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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.layer0.utils.predicates;
\r
14 import java.util.Collection;
\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
21 public class Negation extends UnaryPredicate {
\r
23 IUnaryPredicate predicate;
\r
25 public Negation(IUnaryPredicate predicate) {
\r
26 this.predicate = predicate;
\r
30 public void add(WriteGraph g, Resource r) throws DatabaseException {
\r
31 predicate.remove(g, r);
\r
35 public Collection<Resource> getResources(ReadGraph g) {
\r
36 throw new UnsupportedOperationException();
\r
40 public boolean has(ReadGraph g, Resource resource) throws DatabaseException {
\r
41 return !predicate.has(g, resource);
\r
45 public void remove(WriteGraph g, Resource r) throws DatabaseException {
\r
46 predicate.add(g, r);
\r
50 public boolean supportsAddition() {
\r
51 return predicate.supportsRemoval();
\r
55 public boolean supportsRemoval() {
\r
56 return predicate.supportsAddition();
\r
60 public boolean supportsUnboundedQuery() {
\r
65 public int hashCode() {
\r
66 final int prime = 31;
\r
68 result = prime * result
\r
69 + ((predicate == null) ? 0 : predicate.hashCode());
\r
74 public boolean equals(Object obj) {
\r
79 if (getClass() != obj.getClass())
\r
81 Negation other = (Negation) obj;
\r
82 if (predicate == null) {
\r
83 if (other.predicate != null)
\r
85 } else if (!predicate.equals(other.predicate))
\r