View Javadoc
1   /*
2   Copyright (c) 2018 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.expr;
18  
19  import java.util.Objects;
20  
21  
22  /**
23   * identifies a database entity (e.g. the name of a database field).  An
24   * Identify must have an object name, but the collection name and property
25   * name are optional.
26   *
27   * @author James Ahlborn
28   */
29  public class Identifier
30  {
31    private final String _collectionName;
32    private final String _objectName;
33    private final String _propertyName;
34  
35    public Identifier(String objectName)
36    {
37      this(null, objectName, null);
38    }
39  
40    public Identifier(String collectionName, String objectName, String propertyName)
41    {
42      _collectionName = collectionName;
43      _objectName = objectName;
44      _propertyName = propertyName;
45    }
46  
47    public String getCollectionName()
48    {
49      return _collectionName;
50    }
51  
52    public String getObjectName()
53    {
54      return _objectName;
55    }
56  
57    public String getPropertyName()
58    {
59      return _propertyName;
60    }
61  
62    @Override
63    public int hashCode() {
64      return _objectName.hashCode();
65    }
66  
67    @Override
68    public boolean equals(Object o) {
69      if(!(o instanceof Identifier)) {
70        return false;
71      }
72  
73      Identifier../../../../com/healthmarketscience/jackcess/expr/Identifier.html#Identifier">Identifier oi = (Identifier)o;
74  
75      return (Objects.equals(_objectName, oi._objectName) &&
76              Objects.equals(_collectionName, oi._collectionName) &&
77              Objects.equals(_propertyName, oi._propertyName));
78    }
79  
80    @Override
81    public String toString() {
82      StringBuilder sb = new StringBuilder();
83      if(_collectionName != null) {
84        sb.append("[").append(_collectionName).append("].");
85      }
86      sb.append("[").append(_objectName).append("]");
87      if(_propertyName != null) {
88        sb.append(".[").append(_propertyName).append("]");
89      }
90      return sb.toString();
91    }
92  
93  }