--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.swt.inputs;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+\r
+/**\r
+ * An equals-comparable and adaptable container for a single datum. The datum\r
+ * may be <code>null</code>. Adaptability is provided through {@link IAdaptable}\r
+ * .\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * \r
+ * @param <T> the type of the datum\r
+ */\r
+public class Datum<T> implements IAdaptable {\r
+\r
+ protected final T datum;\r
+\r
+ public Datum(T datum) {\r
+ this.datum = datum;\r
+ }\r
+\r
+ public T getDatum() {\r
+ return datum;\r
+ }\r
+\r
+ @SuppressWarnings({ "unchecked", "rawtypes" })\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if (datum != null) {\r
+ if (adapter.isAssignableFrom(datum.getClass()))\r
+ return datum;\r
+ if (datum instanceof IAdaptable)\r
+ return ((IAdaptable) datum).getAdapter(adapter);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return datum != null ? datum.hashCode() : 0;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ Datum<?> other = (Datum<?>) obj;\r
+ if (datum == null)\r
+ return datum == other.datum;\r
+ return datum.equals(other.datum);\r
+ }\r
+\r
+}
\ No newline at end of file