1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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
13 * Created on 16.12.2005
\r
16 package org.simantics.utils;
\r
18 import java.lang.reflect.Array;
\r
19 import java.util.Collection;
\r
20 import java.util.Iterator;
\r
24 * DataContainer is used as return argument
\r
26 * @author Toni Kalajainen
\r
28 public final class DataContainer<T> implements Container<T>, Collection<T> {
\r
32 public static <T> DataContainer<T> make(T t) {
\r
33 return new DataContainer<T>(t);
\r
36 public DataContainer() {
\r
39 public DataContainer(T initialData) {
\r
40 this.data = initialData;
\r
43 public boolean isEmpty() {
\r
44 return data == null;
\r
47 public void set(T value) {
\r
55 public boolean hasContent() {
\r
56 return data != null;
\r
60 public boolean add(T arg0) {
\r
61 throw new UnsupportedOperationException();
\r
65 public boolean addAll(Collection<? extends T> arg0) {
\r
66 throw new UnsupportedOperationException();
\r
70 public void clear() {
\r
71 throw new UnsupportedOperationException();
\r
75 public boolean contains(Object arg0) {
\r
76 throw new UnsupportedOperationException();
\r
80 public boolean containsAll(Collection<?> arg0) {
\r
81 throw new UnsupportedOperationException();
\r
85 public Iterator<T> iterator() {
\r
87 return new Iterator<T>() {
\r
89 private T value = data;
\r
92 public boolean hasNext() {
\r
93 return value != null;
\r
104 public void remove() {
\r
105 throw new UnsupportedOperationException();
\r
112 public boolean remove(Object arg0) {
\r
113 throw new UnsupportedOperationException();
\r
117 public boolean removeAll(Collection<?> arg0) {
\r
118 throw new UnsupportedOperationException();
\r
122 public boolean retainAll(Collection<?> arg0) {
\r
123 throw new UnsupportedOperationException();
\r
127 public int size() {
\r
128 return data != null ? 1 : 0;
\r
132 public Object[] toArray() {
\r
133 return new Object[] { data };
\r
136 @SuppressWarnings("unchecked")
\r
138 public <K> K[] toArray(K[] a) {
\r
140 if (a.length < size)
\r
141 a = (K[]) Array.newInstance(a.getClass().getComponentType(), 1);
\r
144 for (int i = size; i < a.length; ++i)
\r