]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/ListAccessor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / rules / range / ListAccessor.java
index a384235be4021a49be6e3ccec5e66c3155308791..18479880417c3659978a1c3637fb1b46dccee2c1 100644 (file)
@@ -1,94 +1,94 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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
-package org.simantics.objmap.graph.rules.range;\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.objmap.exceptions.MappingException;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-\r
-/**\r
- * Accessor for mapped collections. \r
- * Uses three methods:\r
- * - Getter: returns the collection.\r
- * - Adder: adds one item into the collection.\r
- * - Remover: removes one item from the collection. \r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- * @param <T>\r
- */\r
-public class ListAccessor<Range,T>  implements IRangeAccessor<Range,Collection<T>> {\r
-       \r
-       private Method getter;\r
-       private Method adder;\r
-       private Method remover;\r
-       \r
-       public ListAccessor(Method getter, Method adder, Method remover) {\r
-               this.getter = getter;\r
-               this.adder = adder;\r
-               this.remover = remover;\r
-       }\r
-       \r
-       @SuppressWarnings("unchecked")\r
-       public java.util.Collection<T> get(Object element) throws MappingException {\r
-               try {\r
-                       return (Collection<T>) getter.invoke(element);\r
-               } catch (IllegalArgumentException e) {\r
-                       throw new MappingException(e);\r
-               } catch (IllegalAccessException e) {\r
-                       throw new MappingException(e);\r
-               } catch (InvocationTargetException e) {\r
-                       throw new MappingException(e.getCause());\r
-               }\r
-       };\r
-\r
-       @Override\r
-       public boolean set(Range element, Collection<T> value)\r
-                       throws MappingException {\r
-               java.util.Collection<T> current = get(element);\r
-               Collection<Pair<Integer, T>> adding = new ArrayList<Pair<Integer, T>>();\r
-               Collection<T> removing = new ArrayList<T>();\r
-               for (T e : current) {\r
-                       if (!value.contains(e))\r
-                               removing.add(e);\r
-               }\r
-               int i = 0;\r
-               for (T e : value) {\r
-                       if (!current.contains(e))\r
-                               adding.add(new Pair<Integer, T>(i, e));\r
-                       i++;\r
-               }\r
-               \r
-               try {\r
-                       for (T e : removing) {\r
-                               remover.invoke(element, e);\r
-                       }\r
-                       \r
-                       for (Pair<Integer,T> e : adding) {\r
-                               adder.invoke(element, e.first,e.second);\r
-                       }\r
-               } catch (IllegalArgumentException e) {\r
-                       throw new MappingException(e);\r
-               } catch (IllegalAccessException e) {\r
-                       throw new MappingException(e);\r
-               } catch (InvocationTargetException e) {\r
-                       throw new MappingException(e.getCause());\r
-               }\r
-               return removing.size() > 0 || adding.size() > 0;\r
-               \r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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
+ *******************************************************************************/
+package org.simantics.objmap.graph.rules.range;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.objmap.exceptions.MappingException;
+import org.simantics.utils.datastructures.Pair;
+
+
+/**
+ * Accessor for mapped collections. 
+ * Uses three methods:
+ * - Getter: returns the collection.
+ * - Adder: adds one item into the collection.
+ * - Remover: removes one item from the collection. 
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ * @param <T>
+ */
+public class ListAccessor<Range,T>  implements IRangeAccessor<Range,Collection<T>> {
+       
+       private Method getter;
+       private Method adder;
+       private Method remover;
+       
+       public ListAccessor(Method getter, Method adder, Method remover) {
+               this.getter = getter;
+               this.adder = adder;
+               this.remover = remover;
+       }
+       
+       @SuppressWarnings("unchecked")
+       public java.util.Collection<T> get(Object element) throws MappingException {
+               try {
+                       return (Collection<T>) getter.invoke(element);
+               } catch (IllegalArgumentException e) {
+                       throw new MappingException(e);
+               } catch (IllegalAccessException e) {
+                       throw new MappingException(e);
+               } catch (InvocationTargetException e) {
+                       throw new MappingException(e.getCause());
+               }
+       };
+
+       @Override
+       public boolean set(Range element, Collection<T> value)
+                       throws MappingException {
+               java.util.Collection<T> current = get(element);
+               Collection<Pair<Integer, T>> adding = new ArrayList<Pair<Integer, T>>();
+               Collection<T> removing = new ArrayList<T>();
+               for (T e : current) {
+                       if (!value.contains(e))
+                               removing.add(e);
+               }
+               int i = 0;
+               for (T e : value) {
+                       if (!current.contains(e))
+                               adding.add(new Pair<Integer, T>(i, e));
+                       i++;
+               }
+               
+               try {
+                       for (T e : removing) {
+                               remover.invoke(element, e);
+                       }
+                       
+                       for (Pair<Integer,T> e : adding) {
+                               adder.invoke(element, e.first,e.second);
+                       }
+               } catch (IllegalArgumentException e) {
+                       throw new MappingException(e);
+               } catch (IllegalAccessException e) {
+                       throw new MappingException(e);
+               } catch (InvocationTargetException e) {
+                       throw new MappingException(e.getCause());
+               }
+               return removing.size() > 0 || adding.size() > 0;
+               
+       }
+}