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.

Identifier.java 2.2KB

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