1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt.inputs;
14 import org.eclipse.core.runtime.IAdaptable;
17 * An equals-comparable and adaptable container for a single datum. The datum
18 * may be <code>null</code>. Adaptability is provided through {@link IAdaptable}
21 * @author Tuukka Lehtonen
23 * @param <T> the type of the datum
25 public class Datum<T> implements IAdaptable {
27 protected final T datum;
29 public Datum(T datum) {
37 @SuppressWarnings({ "unchecked", "rawtypes" })
39 public Object getAdapter(Class adapter) {
41 if (adapter.isAssignableFrom(datum.getClass()))
43 if (datum instanceof IAdaptable)
44 return ((IAdaptable) datum).getAdapter(adapter);
50 public int hashCode() {
51 return datum != null ? datum.hashCode() : 0;
55 public boolean equals(Object obj) {
60 if (getClass() != obj.getClass())
62 Datum<?> other = (Datum<?>) obj;
64 return datum == other.datum;
65 return datum.equals(other.datum);