]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/DataContainer.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / DataContainer.java
index 89b5763eebb6ad9737c741702e88dc9c4b610640..874647cd79df96e594b6578434ea49d33a5d38df 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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
-/*\r
- * Created on 16.12.2005\r
- * \r
- */\r
-package org.simantics.utils;\r
-\r
-import java.lang.reflect.Array;\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-\r
-\r
-/**\r
- * DataContainer is used as return argument\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public final class DataContainer<T> implements Container<T>, Collection<T> {\r
-\r
-    private T data;\r
-\r
-    public static <T> DataContainer<T> make(T t) {\r
-        return new DataContainer<T>(t);\r
-    }\r
-\r
-    public DataContainer() {\r
-    }\r
-\r
-    public DataContainer(T initialData) {\r
-        this.data = initialData;\r
-    }\r
-\r
-    public boolean isEmpty() {\r
-        return data == null;\r
-    }\r
-\r
-    public void set(T value) {\r
-        data = value;\r
-    }\r
-\r
-    public T get() {\r
-        return data;\r
-    }\r
-\r
-    public boolean hasContent() {\r
-        return data != null;\r
-    }\r
-\r
-    @Override\r
-    public boolean add(T arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public boolean addAll(Collection<? extends T> arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public void clear() {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public boolean contains(Object arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public boolean containsAll(Collection<?> arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public Iterator<T> iterator() {\r
-\r
-        return new Iterator<T>() {\r
-\r
-            private T value = data;\r
-\r
-            @Override\r
-            public boolean hasNext() {\r
-                return value != null;\r
-            }\r
-\r
-            @Override\r
-            public T next() {\r
-                T result = value;\r
-                value = null;\r
-                return result;\r
-            }\r
-\r
-            @Override\r
-            public void remove() {\r
-                throw new UnsupportedOperationException();\r
-            }\r
-        };\r
-\r
-    }\r
-\r
-    @Override\r
-    public boolean remove(Object arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public boolean removeAll(Collection<?> arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public boolean retainAll(Collection<?> arg0) {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-\r
-    @Override\r
-    public int size() {\r
-        return data != null ? 1 : 0;\r
-    }\r
-\r
-    @Override\r
-    public Object[] toArray() {\r
-        return new Object[] { data };\r
-    }\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Override\r
-    public <K> K[] toArray(K[] a) {\r
-        int size = size();\r
-        if (a.length < size)\r
-            a = (K[]) Array.newInstance(a.getClass().getComponentType(), 1);\r
-        if (size > 0)\r
-            a[0] = (K) data;\r
-        for (int i = size; i < a.length; ++i)\r
-            a[i] = null;\r
-        return a;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+/*
+ * Created on 16.12.2005
+ * 
+ */
+package org.simantics.utils;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Iterator;
+
+
+/**
+ * DataContainer is used as return argument
+ * 
+ * @author Toni Kalajainen
+ */
+public final class DataContainer<T> implements Container<T>, Collection<T> {
+
+    private T data;
+
+    public static <T> DataContainer<T> make(T t) {
+        return new DataContainer<T>(t);
+    }
+
+    public DataContainer() {
+    }
+
+    public DataContainer(T initialData) {
+        this.data = initialData;
+    }
+
+    public boolean isEmpty() {
+        return data == null;
+    }
+
+    public void set(T value) {
+        data = value;
+    }
+
+    public T get() {
+        return data;
+    }
+
+    public boolean hasContent() {
+        return data != null;
+    }
+
+    @Override
+    public boolean add(T arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends T> arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean contains(Object arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Iterator<T> iterator() {
+
+        return new Iterator<T>() {
+
+            private T value = data;
+
+            @Override
+            public boolean hasNext() {
+                return value != null;
+            }
+
+            @Override
+            public T next() {
+                T result = value;
+                value = null;
+                return result;
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
+
+    }
+
+    @Override
+    public boolean remove(Object arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> arg0) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int size() {
+        return data != null ? 1 : 0;
+    }
+
+    @Override
+    public Object[] toArray() {
+        return new Object[] { data };
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <K> K[] toArray(K[] a) {
+        int size = size();
+        if (a.length < size)
+            a = (K[]) Array.newInstance(a.getClass().getComponentType(), 1);
+        if (size > 0)
+            a[0] = (K) data;
+        for (int i = size; i < a.length; ++i)
+            a[i] = null;
+        return a;
+    }
+
+}