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