-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.concepts.transform;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Map;\r
-import java.util.concurrent.ConcurrentHashMap;\r
-\r
-\r
-/**\r
- * Transformer which aggregates multiple implementations of\r
- * {@link InputClassBasedTransformer}.\r
- *\r
- * The transformation process is driven by {@link Class} of input. The selection\r
- * of used {@link InputClassBasedTransformer} is done by using the {@link Class}\r
- * of input as a key to select the transformer.\r
- *\r
- * This approach provides quick resolution of transformer, but does not support\r
- * registering a super type of input to provide transformation support for all\r
- * subclasses, one must register a new instance of transformer for each valid\r
- * input class.\r
- *\r
- * If you need more flexible selection of transformation consider using\r
- * {@link CompositeConditionalTransformer} which is slower but most flexible or\r
- * {@link RuleBasedTransformer} which provides declarative approach for\r
- * transformation.\r
- *\r
- * See {@link #transform(Object)} for more information about tranformation\r
- * process.\r
- *\r
- * @author Tony Tkacik <ttkacik@cisco.com>\r
- *\r
- * @param <I>\r
- * Input super-type\r
- * @param <P>\r
- * Product\r
- */\r
-public abstract class CompositeClassBasedTransformer<I, P> implements\r
- InputClassBasedTransformer<I, I, P>,\r
- AggregateTransformer<I, P> {\r
-\r
- private Map<Class<? extends I>, InputClassBasedTransformer<I, ? extends I, P>> transformers = new ConcurrentHashMap<Class<? extends I>, InputClassBasedTransformer<I, ? extends I, P>>();\r
-\r
- /**\r
- * Transforms an input into instance of Product class.\r
- *\r
- * The final registered transformer is the one which match following\r
- * condition:\r
- *\r
- * <code>input.getClass() == transformer.getInputClass()</code>\r
- *\r
- * This means that transformers are not resolved by class hierarchy, only\r
- * selected based on final class of the input. If you need more flexible\r
- * selection of transformation consider using\r
- * {@link CompositeConditionalTransformer} which is slower but more\r
- * flexible.\r
- *\r
- */\r
- @Override\r
- public P transform(I input) {\r
- @SuppressWarnings("unchecked")\r
- InputClassBasedTransformer<I, I, P> transformer = (InputClassBasedTransformer<I, I, P>) transformers\r
- .get(input.getClass());\r
- if (transformer == null)\r
- throw new IllegalArgumentException("Transformation of: " + input\r
- + " is not supported");\r
- return transformer.transform(input);\r
- }\r
-\r
- /**\r
- * Registers a new transformer.\r
- *\r
- * The transformer is registered for class returned by\r
- * {@link InputClassBasedTransformer#getInputClass()}. Only one transformer\r
- * can be registered for particular input class.\r
- *\r
- */\r
- public void addTransformer(\r
- InputClassBasedTransformer<I, ? extends I, P> transformer)\r
- throws IllegalStateException {\r
- if (transformer == null)\r
- throw new IllegalArgumentException("Transformer should not be null");\r
- if (transformer.getInputClass() == null)\r
- throw new IllegalArgumentException(\r
- "Transformer should specify input class.");\r
- transformers.put(transformer.getInputClass(), transformer);\r
- }\r
-\r
- /**\r
- * Removes an registered transformer.\r
- *\r
- * Note: Removal is currently unsupported.\r
- *\r
- * @param transformer\r
- * Tranformer to be removed.\r
- * @throws IllegalArgumentException\r
- * If the provided transformer is null or is not registered.\r
- */\r
- public void removeTransformer(\r
- InputClassBasedTransformer<I, ? extends I, P> transformer)\r
- throws IllegalArgumentException {\r
- throw new UnsupportedOperationException("Not implemented yet");\r
- }\r
-\r
- @Override\r
- public Collection<P> transformAll(Collection<? extends I> inputs) {\r
- Collection<P> ret = new ArrayList<P>();\r
- for (I i : inputs) {\r
- ret.add(transform(i));\r
- }\r
- return ret;\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. 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
+ */
+
+package org.opendaylight.controller.concepts.transform;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * Transformer which aggregates multiple implementations of
+ * {@link InputClassBasedTransformer}.
+ *
+ * The transformation process is driven by {@link Class} of input. The selection
+ * of used {@link InputClassBasedTransformer} is done by using the {@link Class}
+ * of input as a key to select the transformer.
+ *
+ * This approach provides quick resolution of transformer, but does not support
+ * registering a super type of input to provide transformation support for all
+ * subclasses, one must register a new instance of transformer for each valid
+ * input class.
+ *
+ * If you need more flexible selection of transformation consider using
+ * {@link CompositeConditionalTransformer} which is slower but most flexible or
+ * {@link RuleBasedTransformer} which provides declarative approach for
+ * transformation.
+ *
+ * See {@link #transform(Object)} for more information about tranformation
+ * process.
+ *
+ * @author Tony Tkacik <ttkacik@cisco.com>
+ *
+ * @param <I>
+ * Input super-type
+ * @param <P>
+ * Product
+ */
+public abstract class CompositeClassBasedTransformer<I, P> implements
+ InputClassBasedTransformer<I, I, P>,
+ AggregateTransformer<I, P> {
+
+ private Map<Class<? extends I>, InputClassBasedTransformer<I, ? extends I, P>> transformers = new ConcurrentHashMap<Class<? extends I>, InputClassBasedTransformer<I, ? extends I, P>>();
+
+ /**
+ * Transforms an input into instance of Product class.
+ *
+ * The final registered transformer is the one which match following
+ * condition:
+ *
+ * <code>input.getClass() == transformer.getInputClass()</code>
+ *
+ * This means that transformers are not resolved by class hierarchy, only
+ * selected based on final class of the input. If you need more flexible
+ * selection of transformation consider using
+ * {@link CompositeConditionalTransformer} which is slower but more
+ * flexible.
+ *
+ */
+ @Override
+ public P transform(I input) {
+ @SuppressWarnings("unchecked")
+ InputClassBasedTransformer<I, I, P> transformer = (InputClassBasedTransformer<I, I, P>) transformers
+ .get(input.getClass());
+ if (transformer == null)
+ throw new IllegalArgumentException("Transformation of: " + input
+ + " is not supported");
+ return transformer.transform(input);
+ }
+
+ /**
+ * Registers a new transformer.
+ *
+ * The transformer is registered for class returned by
+ * {@link InputClassBasedTransformer#getInputClass()}. Only one transformer
+ * can be registered for particular input class.
+ *
+ */
+ public void addTransformer(
+ InputClassBasedTransformer<I, ? extends I, P> transformer)
+ throws IllegalStateException {
+ if (transformer == null)
+ throw new IllegalArgumentException("Transformer should not be null");
+ if (transformer.getInputClass() == null)
+ throw new IllegalArgumentException(
+ "Transformer should specify input class.");
+ transformers.put(transformer.getInputClass(), transformer);
+ }
+
+ /**
+ * Removes an registered transformer.
+ *
+ * Note: Removal is currently unsupported.
+ *
+ * @param transformer
+ * Tranformer to be removed.
+ * @throws IllegalArgumentException
+ * If the provided transformer is null or is not registered.
+ */
+ public void removeTransformer(
+ InputClassBasedTransformer<I, ? extends I, P> transformer)
+ throws IllegalArgumentException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public Collection<P> transformAll(Collection<? extends I> inputs) {
+ Collection<P> ret = new ArrayList<P>();
+ for (I i : inputs) {
+ ret.add(transform(i));
+ }
+ return ret;
+ }
+
+}