]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/MutablePropertyVariable.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / MutablePropertyVariable.java
1 package org.simantics.structural2.variables;
2
3 import java.util.Collections;
4 import java.util.Map;
5 import java.util.Set;
6
7 import org.simantics.databoard.binding.Binding;
8 import org.simantics.databoard.type.Datatype;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.WriteGraph;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.variable.AbstractPropertyVariable;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.db.layer0.variable.Variables;
16 import org.simantics.utils.ObjectUtils;
17
18 /**
19  * TODO: consider removing this, doesn't seem to be used
20  */
21 public class MutablePropertyVariable extends AbstractPropertyVariable {
22
23     final protected Variable parent;
24     final String name;
25
26     public Object value;
27     public Binding binding;
28     
29     public MutablePropertyVariable(Variable parent, String name) {
30         assert parent != null;
31         assert name != null;
32         this.parent = parent;
33         this.name = name;
34     }
35
36     @SuppressWarnings("unchecked")
37     @Override
38     public <T> T getValue(ReadGraph graph) throws DatabaseException {
39         return (T)value;
40     }
41
42     @SuppressWarnings("unchecked")
43     @Override
44     public <T> T getValue(ReadGraph graph, Binding binding)
45             throws DatabaseException {
46         return (T)value;
47     }
48
49     @Override
50     public void setValue(WriteGraph graph, Object value, Binding binding)
51             throws DatabaseException {
52         throw new DatabaseException("Value is constant.");
53     }
54
55     @Override
56     public String getName(ReadGraph graph) throws DatabaseException {
57         return name;
58     }
59
60     @Override
61     public Resource getType(ReadGraph graph) throws DatabaseException {
62         return null;
63     }
64
65     @Override
66     public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
67         return null;
68     }
69
70     @Override
71     public Resource getType(ReadGraph graph, Resource baseType)throws DatabaseException {
72         return null;
73     }
74
75     @Override
76     public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
77         return null;
78     }
79
80 //    @Override
81 //    public Object getSerialized(ReadGraph graph) throws DatabaseException {
82 //        return name;
83 //    }
84
85     @Override
86     public Variable getParent(ReadGraph graph) throws DatabaseException {
87         return parent;
88     }
89
90     @Override
91     public Resource getRepresents(ReadGraph graph) throws DatabaseException {
92         return null;
93     }
94     
95     @Override
96     public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
97         return binding != null ? binding.type() : null;
98     }
99     
100     @Override
101     public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {
102         return null;
103     }
104
105     @Override
106     public Resource getContainerResource(ReadGraph graph) throws DatabaseException {
107         return null;
108     }
109     
110     @Override
111     public Variable getPredicate(ReadGraph graph) throws DatabaseException {
112         return null;
113     }
114     
115     @Override
116     protected Variable getPossibleDomainProperty(ReadGraph graph, String name)
117                 throws DatabaseException {
118         return null;
119     }
120
121     @Override
122     public Map<String, Variable> collectDomainProperties(ReadGraph graph,
123                 Map<String, Variable> properties) throws DatabaseException {
124         return properties;
125     }
126     
127     @Override
128     public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
129         Variable property = getPossibleDomainProperty(graph, Variables.CLASSIFICATIONS);
130         if(property != null) return property.getValue(graph);
131         else return Collections.emptySet();
132     }
133     
134     @Override
135     public int hashCode() {
136         final int prime = 31;
137         int result = 1;
138         result = prime * result + name.hashCode();
139         result = prime * result + parent.hashCode();
140         result = prime * result + ((value == null) ? 0 : value.hashCode());
141         result = prime * result + ((binding == null) ? 0 : binding.hashCode());
142         return result;
143     }
144
145     @Override
146     public boolean equals(Object obj) {
147         if (this == obj)
148             return true;
149         if (obj == null)
150             return false;
151         if (getClass() != obj.getClass())
152             return false;
153         MutablePropertyVariable other = (MutablePropertyVariable) obj;
154         if (!name.equals(other.name))
155             return false;
156         if (!parent.equals(other.parent))
157             return false;
158         if (!ObjectUtils.objectEquals(value, other.value))
159             return false;
160         return ObjectUtils.objectEquals(binding, other.binding);
161     }
162
163 }