]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/predicates/Negation.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / predicates / Negation.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.layer0.utils.predicates;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.WriteGraph;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 \r
21 public class Negation extends UnaryPredicate {\r
22 \r
23         IUnaryPredicate predicate;\r
24         \r
25         public Negation(IUnaryPredicate predicate) {\r
26                 this.predicate = predicate;\r
27         }\r
28 \r
29         @Override\r
30         public void add(WriteGraph g, Resource r) throws DatabaseException {\r
31                 predicate.remove(g, r);\r
32         }\r
33 \r
34         @Override\r
35         public Collection<Resource> getResources(ReadGraph g) {\r
36                 throw new UnsupportedOperationException();\r
37         }\r
38 \r
39         @Override\r
40         public boolean has(ReadGraph g, Resource resource) throws DatabaseException {\r
41                 return !predicate.has(g, resource);\r
42         }\r
43 \r
44         @Override\r
45         public void remove(WriteGraph g, Resource r) throws DatabaseException {\r
46                 predicate.add(g, r);\r
47         }\r
48 \r
49         @Override\r
50         public boolean supportsAddition() {\r
51                 return predicate.supportsRemoval();\r
52         }\r
53 \r
54         @Override\r
55         public boolean supportsRemoval() {\r
56                 return predicate.supportsAddition();\r
57         }\r
58 \r
59         @Override\r
60         public boolean supportsUnboundedQuery() {\r
61                 return false;\r
62         }\r
63 \r
64         @Override\r
65         public int hashCode() {\r
66                 final int prime = 31;\r
67                 int result = 1;\r
68                 result = prime * result\r
69                                 + ((predicate == null) ? 0 : predicate.hashCode());\r
70                 return result;\r
71         }\r
72 \r
73         @Override\r
74         public boolean equals(Object obj) {\r
75                 if (this == obj)\r
76                         return true;\r
77                 if (obj == null)\r
78                         return false;\r
79                 if (getClass() != obj.getClass())\r
80                         return false;\r
81                 Negation other = (Negation) obj;\r
82                 if (predicate == null) {\r
83                         if (other.predicate != null)\r
84                                 return false;\r
85                 } else if (!predicate.equals(other.predicate))\r
86                         return false;\r
87                 return true;\r
88         }\r
89         \r
90 }\r