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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 java.time.LocalDateTime;
  19. import com.healthmarketscience.jackcess.Row;
  20. import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
  21. import com.healthmarketscience.jackcess.util.OleBlob;
  22. /**
  23. * A row of data as column->value pairs.
  24. * <p>
  25. * Note that the {@link #equals} and {@link #hashCode} methods work on the row
  26. * contents <i>only</i> (i.e. they ignore the id).
  27. *
  28. * @author James Ahlborn
  29. */
  30. public class RowImpl extends LinkedHashMap<String,Object> implements Row
  31. {
  32. private static final long serialVersionUID = 20130314L;
  33. private final RowIdImpl _id;
  34. public RowImpl(RowIdImpl id) {
  35. _id = id;
  36. }
  37. public RowImpl(RowIdImpl id, int expectedSize) {
  38. super(expectedSize);
  39. _id = id;
  40. }
  41. public RowImpl(Row row) {
  42. super(row);
  43. _id = (RowIdImpl)row.getId();
  44. }
  45. @Override
  46. public RowIdImpl getId() {
  47. return _id;
  48. }
  49. @Override
  50. public String getString(String name) {
  51. return (String)get(name);
  52. }
  53. @Override
  54. public Boolean getBoolean(String name) {
  55. return (Boolean)get(name);
  56. }
  57. @Override
  58. public Byte getByte(String name) {
  59. return (Byte)get(name);
  60. }
  61. @Override
  62. public Short getShort(String name) {
  63. return (Short)get(name);
  64. }
  65. @Override
  66. public Integer getInt(String name) {
  67. return (Integer)get(name);
  68. }
  69. @Override
  70. public BigDecimal getBigDecimal(String name) {
  71. return (BigDecimal)get(name);
  72. }
  73. @Override
  74. public Float getFloat(String name) {
  75. return (Float)get(name);
  76. }
  77. @Override
  78. public Double getDouble(String name) {
  79. return (Double)get(name);
  80. }
  81. @Override
  82. @SuppressWarnings("deprecation")
  83. public Date getDate(String name) {
  84. return (Date)get(name);
  85. }
  86. @Override
  87. public LocalDateTime getLocalDateTime(String name) {
  88. return (LocalDateTime)get(name);
  89. }
  90. @Override
  91. public byte[] getBytes(String name) {
  92. return (byte[])get(name);
  93. }
  94. @Override
  95. public ComplexValueForeignKey getForeignKey(String name) {
  96. return (ComplexValueForeignKey)get(name);
  97. }
  98. @Override
  99. public OleBlob getBlob(String name) throws IOException {
  100. byte[] bytes = getBytes(name);
  101. return ((bytes != null) ? OleBlob.Builder.fromInternalData(bytes) : null);
  102. }
  103. @Override
  104. public String toString() {
  105. return CustomToStringStyle.valueBuilder("Row[" + _id + "]")
  106. .append(null, this)
  107. .toString();
  108. }
  109. }