]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceArrayProperty.java
7e8435e8e8b1095d84bfaeb838274e28fac5a96b
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / ResourceArrayProperty.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.graph.impl;\r
13 \r
14 import org.simantics.browsing.ui.common.property.IArrayProperty;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.ResourceArray;\r
17 import org.simantics.utils.datastructures.slice.ValueRange;\r
18 \r
19 /**\r
20  * @author Tuukka Lehtonen\r
21  */\r
22 public class ResourceArrayProperty extends ResourceProperty implements IArrayProperty {\r
23 \r
24     protected final ValueRange range;\r
25 \r
26     public ResourceArrayProperty(Type type, ValueRange range, Resource subject, Resource predicate, Resource value,\r
27             ResourceArray path) {\r
28         super(type, subject, predicate, value, path);\r
29         if (range == null)\r
30             throw new IllegalArgumentException("null value range");\r
31         this.range = range;\r
32     }\r
33 \r
34     @Override\r
35     public ValueRange getRange() {\r
36         return range;\r
37     }\r
38 \r
39     @Override\r
40     public String toString() {\r
41         return super.toString() + "[range=" + range + "]";\r
42     }\r
43 \r
44     @Override\r
45     public int propertyHashCode() {\r
46         return super.propertyHashCode() * 31 + range.hashCode();\r
47     }\r
48 \r
49     @Override\r
50     public boolean propertyEquals(Object obj) {\r
51         if (this == obj)\r
52             return true;\r
53         if (!super.propertyEquals(obj))\r
54             return false;\r
55         ResourceArrayProperty other = (ResourceArrayProperty) obj;\r
56         return range.equals(other.range);\r
57     }\r
58 \r
59     @Override\r
60     public int hashCode() {\r
61         return range.hashCode() + 31 * super.hashCode();\r
62     }\r
63 \r
64     @Override\r
65     public boolean equals(Object obj) {\r
66         if (this == obj)\r
67             return true;\r
68         if (!super.equals(obj))\r
69             return false;\r
70         ResourceArrayProperty other = (ResourceArrayProperty) obj;\r
71         return range.equals(other.range);\r
72     }\r
73 \r
74     @Override\r
75     public IArrayProperty slice(ValueRange range) {\r
76         return new SlicedResourceArrayProperty(type, range, subject, predicate, value, path);\r
77     }\r
78 \r
79     @Override\r
80     public boolean isSlice() {\r
81         return false;\r
82     }\r
83 \r
84     private static class SlicedResourceArrayProperty extends ResourceArrayProperty {\r
85         public SlicedResourceArrayProperty(Type type, ValueRange range, Resource subject, Resource predicate,\r
86                 Resource value, ResourceArray path) {\r
87             super(type, range, subject, predicate, value, path);\r
88         }\r
89         @Override\r
90         public boolean isSlice() {\r
91             return true;\r
92         }\r
93     }\r
94 \r
95 }\r