X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fcontent%2FEdgeResource.java;h=45805e556b6ea31944ddc383c0860e3f9d0eceb3;hb=refs%2Fchanges%2F38%2F238%2F2;hp=4ff53a7c44bdb2325eee4ebe52a75622bb508668;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/EdgeResource.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/EdgeResource.java index 4ff53a7c4..45805e556 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/EdgeResource.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/EdgeResource.java @@ -1,116 +1,116 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.content; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; - -/** - * @author Tuukka Lehtonen - */ -public final class EdgeResource /*extends OrderedPair*/ implements Iterable, Comparable { - - private final Resource first; - private final Resource second; - - public EdgeResource(Resource first, Resource second) { - this.first = first; - this.second = second; - } - - public String toString(ReadGraph g) throws DatabaseException { - return "(" + NameUtils.getSafeName(g, first()) + ", " + NameUtils.getSafeName(g, second()) + ")"; - } - - public Resource first() { - return first; - } - - public Resource second() { - return second; - } - - @Override - public int hashCode() { - return first.hashCode() + second.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!(obj instanceof EdgeResource)) - return false; - EdgeResource other = (EdgeResource) obj; - return (first.equals(other.first) && second.equals(other.second)) || (first.equals(other.second) && second.equals(other.first)); - } - - - @Override - public String toString() { - //return "(" + first() + ", " + second() + ")"; - StringBuilder sb = new StringBuilder(32); - sb.append('('); - sb.append(first.getResourceId()); - sb.append(','); - sb.append(second.getResourceId()); - sb.append(')'); - return sb.toString(); - } - - @Override - public Iterator iterator() { - return new Iterator() { - int i = 0; - - @Override - public boolean hasNext() { - return i == 0; - } - - @Override - public Resource next() { - ++i; - switch (i) { - case 1: return first(); - case 2: return second(); - default: - throw new NoSuchElementException("element " + i + "is out of bounds, only two elements exist."); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - final private long id() { - return first.getResourceId() + second.getResourceId(); - } - - @Override - public int compareTo(EdgeResource arg0) { - long i = id(); - long i2 = arg0.id(); - if(i == i2) return 0; - if(i < i2) return -1; - else return 1; - } - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.content; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; + +/** + * @author Tuukka Lehtonen + */ +public final class EdgeResource /*extends OrderedPair*/ implements Iterable, Comparable { + + private final Resource first; + private final Resource second; + + public EdgeResource(Resource first, Resource second) { + this.first = first; + this.second = second; + } + + public String toString(ReadGraph g) throws DatabaseException { + return "(" + NameUtils.getSafeName(g, first()) + ", " + NameUtils.getSafeName(g, second()) + ")"; + } + + public Resource first() { + return first; + } + + public Resource second() { + return second; + } + + @Override + public int hashCode() { + return first.hashCode() + second.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof EdgeResource)) + return false; + EdgeResource other = (EdgeResource) obj; + return (first.equals(other.first) && second.equals(other.second)) || (first.equals(other.second) && second.equals(other.first)); + } + + + @Override + public String toString() { + //return "(" + first() + ", " + second() + ")"; + StringBuilder sb = new StringBuilder(32); + sb.append('('); + sb.append(first.getResourceId()); + sb.append(','); + sb.append(second.getResourceId()); + sb.append(')'); + return sb.toString(); + } + + @Override + public Iterator iterator() { + return new Iterator() { + int i = 0; + + @Override + public boolean hasNext() { + return i == 0; + } + + @Override + public Resource next() { + ++i; + switch (i) { + case 1: return first(); + case 2: return second(); + default: + throw new NoSuchElementException("element " + i + "is out of bounds, only two elements exist."); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + final private long id() { + return first.getResourceId() + second.getResourceId(); + } + + @Override + public int compareTo(EdgeResource arg0) { + long i = id(); + long i2 = arg0.id(); + if(i == i2) return 0; + if(i < i2) return -1; + else return 1; + } + } \ No newline at end of file