01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.outerj.daisy.repository;
17:
18: import java.util.Arrays;
19:
20: /**
21: * A HierarchyPath is the value assigned to a hierarchical field.
22: * In case of a multivalue hierarchical field, the value of the
23: * field is an array of HierarchyPath objects.
24: *
25: * <p>A HierarchyPath object is immutable.
26: */
27: public final class HierarchyPath {
28: private final Object[] elements;
29:
30: /**
31: *
32: * @param elements the elements of the hierarchy path. The object types in the list
33: * should correspond to the datatype of the field.
34: */
35: public HierarchyPath(Object[] elements) {
36: this .elements = elements.clone();
37: }
38:
39: public Object[] getElements() {
40: return elements.clone();
41: }
42:
43: public int length() {
44: return elements.length;
45: }
46:
47: public boolean equals(Object obj) {
48: if (!(obj instanceof HierarchyPath))
49: return false;
50:
51: HierarchyPath other = (HierarchyPath) obj;
52: return Arrays.equals(elements, other.elements);
53: }
54:
55: public String toString() {
56: StringBuilder builder = new StringBuilder();
57: for (Object element : elements) {
58: builder.append("/");
59: builder.append(element.toString());
60: }
61: return builder.toString();
62: }
63: }
|