]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/predicates/Type.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / predicates / Type.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.layer0.utils.predicates;
13
14 import java.util.Collection;
15
16 import org.simantics.db.Resource;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.layer0.Layer0;
21
22 public class Type extends UnaryPredicate {
23
24         Resource type;
25
26         public Type(Resource type) {
27                 this.type = type;
28         }
29         
30         public Resource getType() {
31         return type;
32     }
33
34         @Override
35         public Collection<Resource> getResources(ReadGraph g) {
36                 throw new UnsupportedOperationException();
37         }
38
39         @Override
40         public boolean has(ReadGraph g, Resource resource) throws DatabaseException {
41                 return g.isInstanceOf(resource, type);
42         }
43
44         @Override
45         public boolean supportsUnboundedQuery() {
46                 return false;
47         }
48
49         @Override
50         public void add(WriteGraph g, Resource r) throws DatabaseException {
51         Layer0 b = Layer0.getInstance(g);
52                 if(!g.isInstanceOf(r, type))
53                         g.claim(r, b.InstanceOf, null, type);
54         }
55
56         @Override
57         public void remove(WriteGraph g, Resource r) throws DatabaseException {
58                 // FIXME not implemented correctly
59         Layer0 b = Layer0.getInstance(g);
60                 if(g.isInstanceOf(r, type))
61                         g.denyStatement(r, b.InstanceOf, type);
62         }
63
64         @Override
65         public boolean supportsAddition() {
66                 return true;
67         }
68
69         @Override
70         public boolean supportsRemoval() {
71                 return false;
72         }
73
74         @Override
75         public int hashCode() {
76                 final int prime = 31;
77                 int result = 1;
78                 result = prime * result + ((type == null) ? 0 : type.hashCode());
79                 return result;
80         }
81
82         @Override
83         public boolean equals(Object obj) {
84                 if (this == obj)
85                         return true;
86                 if (obj == null)
87                         return false;
88                 if (getClass() != obj.getClass())
89                         return false;
90                 Type other = (Type) obj;
91                 if (type == null) {
92                         if (other.type != null)
93                                 return false;
94                 } else if (!type.equals(other.type))
95                         return false;
96                 return true;
97         }
98         
99 }