You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RowImpl.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Copyright (c) 2013 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl;
  14. import java.io.IOException;
  15. import java.util.LinkedHashMap;
  16. import java.util.Date;
  17. import java.math.BigDecimal;
  18. import com.healthmarketscience.jackcess.Row;
  19. import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
  20. import com.healthmarketscience.jackcess.util.OleBlob;
  21. /**
  22. * A row of data as column->value pairs.
  23. * </p>
  24. * Note that the {@link #equals} and {@link #hashCode} methods work on the row
  25. * contents <i>only</i> (i.e. they ignore the id).
  26. *
  27. * @author James Ahlborn
  28. */
  29. public class RowImpl extends LinkedHashMap<String,Object> implements Row
  30. {
  31. private static final long serialVersionUID = 20130314L;
  32. private final RowIdImpl _id;
  33. public RowImpl(RowIdImpl id) {
  34. _id = id;
  35. }
  36. public RowImpl(RowIdImpl id, int expectedSize) {
  37. super(expectedSize);
  38. _id = id;
  39. }
  40. public RowImpl(Row row) {
  41. super(row);
  42. _id = (RowIdImpl)row.getId();
  43. }
  44. public RowIdImpl getId() {
  45. return _id;
  46. }
  47. public String getString(String name) {
  48. return (String)get(name);
  49. }
  50. public Boolean getBoolean(String name) {
  51. return (Boolean)get(name);
  52. }
  53. public Byte getByte(String name) {
  54. return (Byte)get(name);
  55. }
  56. public Short getShort(String name) {
  57. return (Short)get(name);
  58. }
  59. public Integer getInt(String name) {
  60. return (Integer)get(name);
  61. }
  62. public BigDecimal getBigDecimal(String name) {
  63. return (BigDecimal)get(name);
  64. }
  65. public Float getFloat(String name) {
  66. return (Float)get(name);
  67. }
  68. public Double getDouble(String name) {
  69. return (Double)get(name);
  70. }
  71. public Date getDate(String name) {
  72. return (Date)get(name);
  73. }
  74. public byte[] getBytes(String name) {
  75. return (byte[])get(name);
  76. }
  77. public ComplexValueForeignKey getForeignKey(String name) {
  78. return (ComplexValueForeignKey)get(name);
  79. }
  80. public OleBlob getBlob(String name) throws IOException {
  81. byte[] bytes = getBytes(name);
  82. return ((bytes != null) ? OleBlob.Builder.fromInternalData(bytes) : null);
  83. }
  84. @Override
  85. public String toString() {
  86. return CustomToStringStyle.valueBuilder("Row[" + _id + "]")
  87. .append(null, this)
  88. .toString();
  89. }
  90. }