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