X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Finputs%2FDatum.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Finputs%2FDatum.java;h=6a554f4ac0f328f6f0d707236449fd0011eb377d;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/inputs/Datum.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/inputs/Datum.java new file mode 100644 index 000000000..6a554f4ac --- /dev/null +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/inputs/Datum.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 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.swt.inputs; + +import org.eclipse.core.runtime.IAdaptable; + +/** + * An equals-comparable and adaptable container for a single datum. The datum + * may be null. Adaptability is provided through {@link IAdaptable} + * . + * + * @author Tuukka Lehtonen + * + * @param the type of the datum + */ +public class Datum implements IAdaptable { + + protected final T datum; + + public Datum(T datum) { + this.datum = datum; + } + + public T getDatum() { + return datum; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Object getAdapter(Class adapter) { + if (datum != null) { + if (adapter.isAssignableFrom(datum.getClass())) + return datum; + if (datum instanceof IAdaptable) + return ((IAdaptable) datum).getAdapter(adapter); + } + return null; + } + + @Override + public int hashCode() { + return datum != null ? datum.hashCode() : 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Datum other = (Datum) obj; + if (datum == null) + return datum == other.datum; + return datum.equals(other.datum); + } + +} \ No newline at end of file