X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FResourceProperty.java;h=e875fb736432c4a7240700b367848f026a73cb34;hp=df09d7501842578aa5341cdb8655687cb444a16f;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java index df09d7501..e875fb736 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java @@ -1,117 +1,117 @@ -/******************************************************************************* - * 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.browsing.ui.graph.impl; - -import org.simantics.browsing.ui.common.property.IProperty; -import org.simantics.db.Resource; -import org.simantics.db.common.ResourceArray; - -/** - * @author Tuukka Lehtonen - */ -public class ResourceProperty implements IProperty { - - protected final Type type; - - protected final Resource subject; - protected final Resource predicate; - protected final Resource value; - protected final ResourceArray path; - - public ResourceProperty(Type type, Resource subject, Resource predicate, Resource value, ResourceArray path) { - this.type = type; - this.subject = subject; - this.predicate = predicate; - this.value = value; - this.path = path; - } - - @Override - public Type getType() { - return type; - } - - @SuppressWarnings("unchecked") - @Override - public T getData(Class clazz) { - T t = (T) getAdapter(clazz); - if (t != null) - return t; - throw new ClassCastException("class " + clazz.getCanonicalName() + " not adaptable from " + toString()); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "[subject=" + subject + ", predicate=" + predicate + ", value=" + value - + ", path=" + path + "]"; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public Object getAdapter(Class adapter) { - return adapt(adapter); - } - - @SuppressWarnings("unchecked") - @Override - public T adapt(Class adapter) { - if (adapter == ResourceArray[].class) - return (T) new ResourceArray[] { new ResourceArray(subject, predicate, value), path }; - if (adapter == ResourceArray.class) - return (T) new ResourceArray(subject, predicate, value); - if (adapter == Resource[].class) - return (T) new Resource[] { subject, predicate, value }; - if (adapter == Resource.class) - // Return the object of the specified statement - return (T) value; - return null; - } - - @Override - public int propertyHashCode() { - final int prime = 31; - int result = 1; - result = prime * result + subject.hashCode(); - result = prime * result + predicate.hashCode(); - result = prime * result + path.hashCode(); - return result; - } - - @Override - public boolean propertyEquals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ResourceProperty other = (ResourceProperty) obj; - return subject.equals(other.subject) && predicate.equals(other.predicate) && path.equals(other.path); - } - - @Override - public int hashCode() { - return propertyHashCode() * 31 + value.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!propertyEquals(obj)) - return false; - ResourceProperty other = (ResourceProperty) obj; - return value.equals(other.value) && type.equals(other.type); - - } - -} +/******************************************************************************* + * 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.browsing.ui.graph.impl; + +import org.simantics.browsing.ui.common.property.IProperty; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; + +/** + * @author Tuukka Lehtonen + */ +public class ResourceProperty implements IProperty { + + protected final Type type; + + protected final Resource subject; + protected final Resource predicate; + protected final Resource value; + protected final ResourceArray path; + + public ResourceProperty(Type type, Resource subject, Resource predicate, Resource value, ResourceArray path) { + this.type = type; + this.subject = subject; + this.predicate = predicate; + this.value = value; + this.path = path; + } + + @Override + public Type getType() { + return type; + } + + @SuppressWarnings("unchecked") + @Override + public T getData(Class clazz) { + T t = (T) getAdapter(clazz); + if (t != null) + return t; + throw new ClassCastException("class " + clazz.getCanonicalName() + " not adaptable from " + toString()); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[subject=" + subject + ", predicate=" + predicate + ", value=" + value + + ", path=" + path + "]"; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public Object getAdapter(Class adapter) { + return adapt(adapter); + } + + @SuppressWarnings("unchecked") + @Override + public T adapt(Class adapter) { + if (adapter == ResourceArray[].class) + return (T) new ResourceArray[] { new ResourceArray(subject, predicate, value), path }; + if (adapter == ResourceArray.class) + return (T) new ResourceArray(subject, predicate, value); + if (adapter == Resource[].class) + return (T) new Resource[] { subject, predicate, value }; + if (adapter == Resource.class) + // Return the object of the specified statement + return (T) value; + return null; + } + + @Override + public int propertyHashCode() { + final int prime = 31; + int result = 1; + result = prime * result + subject.hashCode(); + result = prime * result + predicate.hashCode(); + result = prime * result + path.hashCode(); + return result; + } + + @Override + public boolean propertyEquals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceProperty other = (ResourceProperty) obj; + return subject.equals(other.subject) && predicate.equals(other.predicate) && path.equals(other.path); + } + + @Override + public int hashCode() { + return propertyHashCode() * 31 + value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!propertyEquals(obj)) + return false; + ResourceProperty other = (ResourceProperty) obj; + return value.equals(other.value) && type.equals(other.type); + + } + +}