1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 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.browsing.ui.swt.inputs;
\r
14 import org.eclipse.core.runtime.IAdaptable;
\r
17 * An equals-comparable and adaptable container for a single datum. The datum
\r
18 * may be <code>null</code>. Adaptability is provided through {@link IAdaptable}
\r
21 * @author Tuukka Lehtonen
\r
23 * @param <T> the type of the datum
\r
25 public class Datum<T> implements IAdaptable {
\r
27 protected final T datum;
\r
29 public Datum(T datum) {
\r
33 public T getDatum() {
\r
37 @SuppressWarnings({ "unchecked", "rawtypes" })
\r
39 public Object getAdapter(Class adapter) {
\r
40 if (datum != null) {
\r
41 if (adapter.isAssignableFrom(datum.getClass()))
\r
43 if (datum instanceof IAdaptable)
\r
44 return ((IAdaptable) datum).getAdapter(adapter);
\r
50 public int hashCode() {
\r
51 return datum != null ? datum.hashCode() : 0;
\r
55 public boolean equals(Object obj) {
\r
60 if (getClass() != obj.getClass())
\r
62 Datum<?> other = (Datum<?>) obj;
\r
64 return datum == other.datum;
\r
65 return datum.equals(other.datum);
\r