1 | /** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
3 | * or more contributor license agreements. See the NOTICE file |
---|
4 | * distributed with this work for additional information |
---|
5 | * regarding copyright ownership. The ASF licenses this file |
---|
6 | * to you under the Apache License, Version 2.0 (the |
---|
7 | * "License"); you may not use this file except in compliance |
---|
8 | * with the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | |
---|
19 | package org.apache.hadoop.record.meta; |
---|
20 | |
---|
21 | import java.io.IOException; |
---|
22 | |
---|
23 | import org.apache.hadoop.record.RecordOutput; |
---|
24 | |
---|
25 | /** |
---|
26 | * Represents a type information for a field, which is made up of its |
---|
27 | * ID (name) and its type (a TypeID object). |
---|
28 | */ |
---|
29 | public class FieldTypeInfo |
---|
30 | { |
---|
31 | |
---|
32 | private String fieldID; |
---|
33 | private TypeID typeID; |
---|
34 | |
---|
35 | /** |
---|
36 | * Construct a FiledTypeInfo with the given field name and the type |
---|
37 | */ |
---|
38 | FieldTypeInfo(String fieldID, TypeID typeID) { |
---|
39 | this.fieldID = fieldID; |
---|
40 | this.typeID = typeID; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * get the field's TypeID object |
---|
45 | */ |
---|
46 | public TypeID getTypeID() { |
---|
47 | return typeID; |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * get the field's id (name) |
---|
52 | */ |
---|
53 | public String getFieldID() { |
---|
54 | return fieldID; |
---|
55 | } |
---|
56 | |
---|
57 | void write(RecordOutput rout, String tag) throws IOException { |
---|
58 | rout.writeString(fieldID, tag); |
---|
59 | typeID.write(rout, tag); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Two FieldTypeInfos are equal if ach of their fields matches |
---|
64 | */ |
---|
65 | public boolean equals(Object o) { |
---|
66 | if (this == o) |
---|
67 | return true; |
---|
68 | if (!(o instanceof FieldTypeInfo)) |
---|
69 | return false; |
---|
70 | FieldTypeInfo fti = (FieldTypeInfo) o; |
---|
71 | // first check if fieldID matches |
---|
72 | if (!this.fieldID.equals(fti.fieldID)) { |
---|
73 | return false; |
---|
74 | } |
---|
75 | // now see if typeID matches |
---|
76 | return (this.typeID.equals(fti.typeID)); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * We use a basic hashcode implementation, since this class will likely not |
---|
81 | * be used as a hashmap key |
---|
82 | */ |
---|
83 | public int hashCode() { |
---|
84 | return 37*17+typeID.hashCode() + 37*17+fieldID.hashCode(); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | public boolean equals(FieldTypeInfo ti) { |
---|
89 | // first check if fieldID matches |
---|
90 | if (!this.fieldID.equals(ti.fieldID)) { |
---|
91 | return false; |
---|
92 | } |
---|
93 | // now see if typeID matches |
---|
94 | return (this.typeID.equals(ti.typeID)); |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | |
---|