Author: mes
Date: 2011-07-05 17:31:21 -0700 (Tue, 05 Jul 2011)
New Revision: 26051

Added:
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
Modified:
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/BoundaryRangeValues.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMapping.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingPoint.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMapping.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMapping.java
   
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
   
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
Log:
refactored in preparation of moving implementation to vizmap-impl

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/BoundaryRangeValues.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/BoundaryRangeValues.java
    2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/BoundaryRangeValues.java
    2011-07-06 00:31:21 UTC (rev 26051)
@@ -59,30 +59,24 @@
  * interpolation above and below the same domain value, plus allow a distinctly
  * different value for exact matches.
  */
-public class BoundaryRangeValues<T> {
+public final class BoundaryRangeValues<T> {
        /**
         *
         */
-       public T lesserValue = null;
+       public final T lesserValue;
 
        /**
         *
         */
-       public T equalValue = null;
+       public final T equalValue;
 
        /**
         *
         */
-       public T greaterValue = null;
+       public final T greaterValue;
 
        /**
         * Creates a new BoundaryRangeValues object.
-        */
-       public BoundaryRangeValues() {
-       }
-
-       /**
-        * Creates a new BoundaryRangeValues object.
         *
         * @param lesser
         *            Object used for values less than this point.

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMapping.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMapping.java
      2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMapping.java
      2011-07-06 00:31:21 UTC (rev 26051)
@@ -1,295 +1,44 @@
-/*
-  File: ContinuousMapping.java
-
-  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
-  This library is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2.1 of the License, or
-  any later version.
-
-  This library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
-  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
-  documentation provided hereunder is on an "as is" basis, and the
-  Institute for Systems Biology and the Whitehead Institute
-  have no obligations to provide maintenance, support,
-  updates, enhancements or modifications.  In no event shall the
-  Institute for Systems Biology and the Whitehead Institute
-  be liable to any party for direct, indirect, special,
-  incidental or consequential damages, including lost profits, arising
-  out of the use of this software and its documentation, even if the
-  Institute for Systems Biology and the Whitehead Institute
-  have been advised of the possibility of such damage.  See
-  the GNU Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with this library; if not, write to the Free Software Foundation,
-  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
 package org.cytoscape.view.vizmap.mappings;
 
-
-import java.awt.Color;
-import java.awt.Paint;
-import java.util.ArrayList;
 import java.util.List;
 
-import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTableEntry;
 import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.mappings.interpolators.FlatInterpolator;
-import org.cytoscape.view.vizmap.mappings.interpolators.Interpolator;
-import 
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToColorInterpolator;
-import 
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToNumberInterpolator;
+import org.cytoscape.view.vizmap.VisualMappingFunction;
 
+public interface ContinuousMapping<K, V> extends VisualMappingFunction<K,V>{
 
-/**
- * Implements an interpolation table mapping data to values of a particular
- * class. The data value is extracted from a bundle of attributes by using a
- * specified data attribute name.
- * 
- * @param <V>
- *            Type of object Visual Property holds
- * 
- *            For refactoring changes in this class, please refer to:
- *            cytoscape.visual.mappings.continuous.README.txt.
- * 
- */
-public class ContinuousMapping<K, V> extends AbstractVisualMappingFunction<K, 
V> {
-       
-       protected static final String CONTINUOUS = "Continuous Mapping";
+       public static final String CONTINUOUS = "Continuous Mapping";
 
-       // used to interpolate between boundaries
-       private Interpolator<K, V> interpolator;
-
-       // Contains List of Data Points
-       private List<ContinuousMappingPoint<K, V>> points;
-
-       ContinuousMapping(final String attrName, final Class<K> attrType, final 
VisualProperty<V> vp) {
-               super(attrName, attrType, vp);
-               
-               // Validate type.  K is always a number.
-               if(Number.class.isAssignableFrom(attrType) == false)
-                       throw new IllegalArgumentException("Attribute type 
should be Number.");
-               
-               this.points = new ArrayList<ContinuousMappingPoint<K, V>>();
-
-               // TODO FIXME use factory here.
-               // Create Interpolator
-               if (vp.getRange().getType() == Color.class || 
vp.getRange().getType() == Paint.class)
-                       interpolator = (Interpolator<K, V>) new 
LinearNumberToColorInterpolator();
-               else if (Number.class.isAssignableFrom(vp.getRange().getType()))
-                       interpolator = (Interpolator<K, V>) new 
LinearNumberToNumberInterpolator();
-               else
-                       interpolator = (Interpolator<K, V>) new 
FlatInterpolator();
-       }
-
-
-       @Override public String toString() {
-               return CONTINUOUS;
-       }
-
        /**
         * Gets all Data Points.
         * 
         * @return List of ContinuousMappingPoint objects.
         */
-       public List<ContinuousMappingPoint<K, V>> getAllPoints() {
-               return points;
-       }
+       public List<ContinuousMappingPoint<K, V>> getAllPoints();
 
        /**
         * Adds a New Data Point.
         */
-       public void addPoint(K value, BoundaryRangeValues<V> brv) {
-               points.add(new ContinuousMappingPoint<K, V>(value, brv));
-       }
+       public void addPoint(K value, BoundaryRangeValues<V> brv);
 
        /**
         * Removes a Point from the List.
         */
-       public void removePoint(int index) {
-               points.remove(index);
-       }
+       public void removePoint(int index);
 
        /**
         * Gets Total Point Count.
         */
-       public int getPointCount() {
-               return points.size();
-       }
+       public int getPointCount();
 
        /**
         * Gets Specified Point.
-        * 
+        *  
         * @param index
         *            Index Value.
         * @return ContinuousMappingPoint.
         */
-       public ContinuousMappingPoint<K, V> getPoint(int index) {
-               return points.get(index);
-       }
+       public ContinuousMappingPoint<K, V> getPoint(int index);
 
-       /**
-        * DOCUMENT ME!
-        * 
-        * @param <V>
-        *            DOCUMENT ME!
-        * @param <V>
-        *            DOCUMENT ME!
-        * @param column
-        *            DOCUMENT ME!
-        * @param views
-        *            DOCUMENT ME!
-        */
-       @Override
-       public void apply(final View<? extends CyTableEntry> view) {
-               if (view == null)
-                       return;
-               
-               if(this.points.size() == 0)
-                       return;
-
-               doMap(view);
-       }
-
-       /**
-        * Read attribute from row, map it and apply it.
-        * 
-        * types are guaranteed to be correct (? FIXME: check this)
-        * 
-        * Putting this in a separate method makes it possible to make it
-        * type-parametric.
-        * 
-        * @param <V>
-        *            the type-parameter of the ViewColumn column
-        * @param <K>
-        *            the type-parameter of the domain of the mapping (the 
object
-        *            read as an attribute value has to be is-a K)
-        * @param <V>
-        *            the type-parameter of the View
-        */
-       private void doMap(final View<? extends CyTableEntry> view) {
-
-               final CyRow row = view.getModel().getCyRow();
-
-               if (row.isSet(attrName)) {
-                       // skip Views where source attribute is not defined;
-                       // ViewColumn will automatically substitute the per-VS 
or global
-                       // default, as appropriate
-
-                       // In all cases, attribute value should be a number for 
continuous
-                       // mapping.
-                       final K attrValue = view.getModel().getCyRow()
-                                       .get(attrName, attrType);
-                       final V value = getRangeValue(attrValue);
-                       view.setVisualProperty(vp, value);
-               } else { // remove value so that default value will be used:
-                       view.setVisualProperty(vp, null);
-               }
-
-       }
-
-       private V getRangeValue(K domainValue) {
-               ContinuousMappingPoint<K, V> firstPoint = points.get(0);
-               K minDomain = firstPoint.getValue();
-
-               // if given domain value is smaller than any in our list,
-               // return the range value for the smallest domain value we have.
-               int firstCmp = compareValues(domainValue, minDomain);
-
-               if (firstCmp <= 0) {
-                       BoundaryRangeValues<V> bv = firstPoint.getRange();
-
-                       if (firstCmp < 0)
-                               return bv.lesserValue;
-                       else
-
-                               return bv.equalValue;
-               }
-
-               // if given domain value is larger than any in our Vector,
-               // return the range value for the largest domain value we have.
-               ContinuousMappingPoint<K, V> lastPoint = 
points.get(points.size() - 1);
-               K maxDomain = lastPoint.getValue();
-
-               if (compareValues(domainValue, maxDomain) > 0) {
-                       BoundaryRangeValues<V> bv = lastPoint.getRange();
-
-                       return bv.greaterValue;
-               }
-
-               // OK, it's somewhere in the middle, so find the boundaries and
-               // pass to our interpolator function. First check for a null
-               // interpolator function
-               if (this.interpolator == null)
-                       return null;
-
-               // Note that the list of Points is sorted.
-               // Also, the case of the inValue equalling the smallest key was
-               // checked above.
-               ContinuousMappingPoint<K, V> currentPoint;
-               int index = 0;
-
-               for (index = 0; index < points.size(); index++) {
-                       currentPoint = points.get(index);
-
-                       K currentValue = currentPoint.getValue();
-                       int cmpValue = compareValues(domainValue, currentValue);
-
-                       if (cmpValue == 0) {
-                               BoundaryRangeValues<V> bv = 
currentPoint.getRange();
-
-                               return bv.equalValue;
-                       } else if (cmpValue < 0)
-                               break;
-               }
-
-               return getRangeValue(index, domainValue);
-       }
-
-       /**
-        * This is tricky. The desired domain value is greater than lowerDomain 
and
-        * less than upperDomain. Therefore, we want the "greater" field of the
-        * lower boundary value (because the desired domain value is greater) 
and
-        * the "lesser" field of the upper boundary value (semantic 
difficulties).
-        */
-       private V getRangeValue(int index, K domainValue) {
-               // Get Lower Domain and Range
-               ContinuousMappingPoint<K, V> lowerBound = points.get(index - 1);
-               K lowerDomain = lowerBound.getValue();
-               BoundaryRangeValues<V> lv = lowerBound.getRange();
-               V lowerRange = lv.greaterValue;
-
-               // Get Upper Domain and Range
-               ContinuousMappingPoint<K, V> upperBound = points.get(index);
-               K upperDomain = upperBound.getValue();
-               BoundaryRangeValues<V> gv = upperBound.getRange();
-               V upperRange = gv.lesserValue;
-               
-               V value = interpolator.getRangeValue(lowerDomain, lowerRange, 
upperDomain, upperRange, domainValue);
-               
-               return value;
-       }
-
-       /**
-        * Helper function to compare Number objects. This is needed because 
Java
-        * doesn't allow comparing, for example, Integer objects to Double 
objects.
-        */
-       private int compareValues(K probe, K target) {
-               
-               final Number n1 = (Number) probe;
-               final Number n2 = (Number) target;
-               double d1 = n1.doubleValue();
-               double d2 = n2.doubleValue();
-
-               if (d1 < d2)
-                       return -1;
-               else if (d1 > d2)
-                       return 1;
-               else
-                       return 0;
-       }
-}
+}
\ No newline at end of file

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
       2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
       2011-07-06 00:31:21 UTC (rev 26051)
@@ -20,7 +20,7 @@
                if(Number.class.isAssignableFrom(attrValueType) == false)
                        throw new IllegalArgumentException("ContinuousMapping 
can be used for numerical attributes only.");
                
-               return new ContinuousMapping<K, V>(attributeName, 
attrValueType,  vp);
+               return new ContinuousMappingImpl<K, V>(attributeName, 
attrValueType,  vp);
        }
        
        @Override public String toString() {

Copied: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
 (from rev 26049, 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMapping.java)
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
                          (rev 0)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
  2011-07-06 00:31:21 UTC (rev 26051)
@@ -0,0 +1,287 @@
+/*
+  File: ContinuousMappingImpl.java
+
+  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.view.vizmap.mappings;
+
+
+import java.awt.Color;
+import java.awt.Paint;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.vizmap.mappings.interpolators.FlatInterpolator;
+import org.cytoscape.view.vizmap.mappings.interpolators.Interpolator;
+import 
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToColorInterpolator;
+import 
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToNumberInterpolator;
+
+
+/**
+ * Implements an interpolation table mapping data to values of a particular
+ * class. The data value is extracted from a bundle of attributes by using a
+ * specified data attribute name.
+ * 
+ * @param <V>
+ *            Type of object Visual Property holds
+ * 
+ *            For refactoring changes in this class, please refer to:
+ *            cytoscape.visual.mappings.continuous.README.txt.
+ * 
+ */
+public class ContinuousMappingImpl<K, V> extends 
AbstractVisualMappingFunction<K, V> implements ContinuousMapping<K, V> {
+       
+       // used to interpolate between boundaries
+       private Interpolator<K, V> interpolator;
+
+       // Contains List of Data Points
+       private List<ContinuousMappingPoint<K, V>> points;
+
+       ContinuousMappingImpl(final String attrName, final Class<K> attrType, 
final VisualProperty<V> vp) {
+               super(attrName, attrType, vp);
+               
+               // Validate type.  K is always a number.
+               if(Number.class.isAssignableFrom(attrType) == false)
+                       throw new IllegalArgumentException("Attribute type 
should be Number.");
+               
+               this.points = new ArrayList<ContinuousMappingPoint<K, V>>();
+
+               // TODO FIXME use factory here.
+               // Create Interpolator
+               if (vp.getRange().getType() == Color.class || 
vp.getRange().getType() == Paint.class)
+                       interpolator = (Interpolator<K, V>) new 
LinearNumberToColorInterpolator();
+               else if (Number.class.isAssignableFrom(vp.getRange().getType()))
+                       interpolator = (Interpolator<K, V>) new 
LinearNumberToNumberInterpolator();
+               else
+                       interpolator = (Interpolator<K, V>) new 
FlatInterpolator();
+       }
+
+
+       /* (non-Javadoc)
+        * @see org.cytoscape.view.vizmap.mappings.ContinuousMapping#toString()
+        */
+       @Override
+       public String toString() {
+               return CONTINUOUS;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getAllPoints()
+        */
+       @Override
+       public List<ContinuousMappingPoint<K, V>> getAllPoints() {
+               return points;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#addPoint(K, 
org.cytoscape.view.vizmap.mappings.BoundaryRangeValues)
+        */
+       @Override
+       public void addPoint(K value, BoundaryRangeValues<V> brv) {
+               points.add(new ContinuousMappingPoint<K, V>(value, brv));
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#removePoint(int)
+        */
+       @Override
+       public void removePoint(int index) {
+               points.remove(index);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getPointCount()
+        */
+       @Override
+       public int getPointCount() {
+               return points.size();
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getPoint(int)
+        */
+       @Override
+       public ContinuousMappingPoint<K, V> getPoint(int index) {
+               return points.get(index);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.ContinuousMapping#apply(org.cytoscape.view.model.View)
+        */
+       @Override
+       public void apply(final View<? extends CyTableEntry> view) {
+               if (view == null)
+                       return;
+               
+               if(this.points.size() == 0)
+                       return;
+
+               doMap(view);
+       }
+
+       /**
+        * Read attribute from row, map it and apply it.
+        * 
+        * types are guaranteed to be correct (? FIXME: check this)
+        * 
+        * Putting this in a separate method makes it possible to make it
+        * type-parametric.
+        * 
+        * @param <V>
+        *            the type-parameter of the ViewColumn column
+        * @param <K>
+        *            the type-parameter of the domain of the mapping (the 
object
+        *            read as an attribute value has to be is-a K)
+        * @param <V>
+        *            the type-parameter of the View
+        */
+       private void doMap(final View<? extends CyTableEntry> view) {
+
+               final CyRow row = view.getModel().getCyRow();
+
+               if (row.isSet(attrName)) {
+                       // skip Views where source attribute is not defined;
+                       // ViewColumn will automatically substitute the per-VS 
or global
+                       // default, as appropriate
+
+                       // In all cases, attribute value should be a number for 
continuous
+                       // mapping.
+                       final K attrValue = view.getModel().getCyRow()
+                                       .get(attrName, attrType);
+                       final V value = getRangeValue(attrValue);
+                       view.setVisualProperty(vp, value);
+               } else { // remove value so that default value will be used:
+                       view.setVisualProperty(vp, null);
+               }
+
+       }
+
+       private V getRangeValue(K domainValue) {
+               ContinuousMappingPoint<K, V> firstPoint = points.get(0);
+               K minDomain = firstPoint.getValue();
+
+               // if given domain value is smaller than any in our list,
+               // return the range value for the smallest domain value we have.
+               int firstCmp = compareValues(domainValue, minDomain);
+
+               if (firstCmp <= 0) {
+                       BoundaryRangeValues<V> bv = firstPoint.getRange();
+
+                       if (firstCmp < 0)
+                               return bv.lesserValue;
+                       else
+
+                               return bv.equalValue;
+               }
+
+               // if given domain value is larger than any in our Vector,
+               // return the range value for the largest domain value we have.
+               ContinuousMappingPoint<K, V> lastPoint = 
points.get(points.size() - 1);
+               K maxDomain = lastPoint.getValue();
+
+               if (compareValues(domainValue, maxDomain) > 0) {
+                       BoundaryRangeValues<V> bv = lastPoint.getRange();
+
+                       return bv.greaterValue;
+               }
+
+               // OK, it's somewhere in the middle, so find the boundaries and
+               // pass to our interpolator function. First check for a null
+               // interpolator function
+               if (this.interpolator == null)
+                       return null;
+
+               // Note that the list of Points is sorted.
+               // Also, the case of the inValue equalling the smallest key was
+               // checked above.
+               ContinuousMappingPoint<K, V> currentPoint;
+               int index = 0;
+
+               for (index = 0; index < points.size(); index++) {
+                       currentPoint = points.get(index);
+
+                       K currentValue = currentPoint.getValue();
+                       int cmpValue = compareValues(domainValue, currentValue);
+
+                       if (cmpValue == 0) {
+                               BoundaryRangeValues<V> bv = 
currentPoint.getRange();
+
+                               return bv.equalValue;
+                       } else if (cmpValue < 0)
+                               break;
+               }
+
+               return getRangeValue(index, domainValue);
+       }
+
+       /**
+        * This is tricky. The desired domain value is greater than lowerDomain 
and
+        * less than upperDomain. Therefore, we want the "greater" field of the
+        * lower boundary value (because the desired domain value is greater) 
and
+        * the "lesser" field of the upper boundary value (semantic 
difficulties).
+        */
+       private V getRangeValue(int index, K domainValue) {
+               // Get Lower Domain and Range
+               ContinuousMappingPoint<K, V> lowerBound = points.get(index - 1);
+               K lowerDomain = lowerBound.getValue();
+               BoundaryRangeValues<V> lv = lowerBound.getRange();
+               V lowerRange = lv.greaterValue;
+
+               // Get Upper Domain and Range
+               ContinuousMappingPoint<K, V> upperBound = points.get(index);
+               K upperDomain = upperBound.getValue();
+               BoundaryRangeValues<V> gv = upperBound.getRange();
+               V upperRange = gv.lesserValue;
+               
+               V value = interpolator.getRangeValue(lowerDomain, lowerRange, 
upperDomain, upperRange, domainValue);
+               
+               return value;
+       }
+
+       /**
+        * Helper function to compare Number objects. This is needed because 
Java
+        * doesn't allow comparing, for example, Integer objects to Double 
objects.
+        */
+       private int compareValues(K probe, K target) {
+               
+               final Number n1 = (Number) probe;
+               final Number n2 = (Number) target;
+               double d1 = n1.doubleValue();
+               double d2 = n2.doubleValue();
+
+               if (d1 < d2)
+                       return -1;
+               else if (d1 > d2)
+                       return 1;
+               else
+                       return 0;
+       }
+}

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingPoint.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingPoint.java
 2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingPoint.java
 2011-07-06 00:31:21 UTC (rev 26051)
@@ -50,7 +50,7 @@
  * and associated BoundaryRangeValues.
  *
  */
-public class ContinuousMappingPoint<K, V> implements Cloneable {
+public final class ContinuousMappingPoint<K, V> {
        private K value;
        private BoundaryRangeValues<V> range;
 
@@ -60,8 +60,8 @@
         * @param range BoundaryRangeValues object.
         */
        public ContinuousMappingPoint(K value, BoundaryRangeValues<V> range) {
-               if(value instanceof Number == false)
-                       throw new IllegalArgumentException("Value should be a 
number.");
+               if( value instanceof Number == false)
+                       throw new IllegalArgumentException("Value must be a 
number.");
                
                this.value = value;
                this.range = range;
@@ -99,17 +99,4 @@
                this.range = range;
        }
 
-       /**
-        * Clones the object. (Deep Copy)
-        * @return Cloned Object.
-        */
-       @Override public Object clone() {
-               
-               final BoundaryRangeValues<V> newRange = new 
BoundaryRangeValues<V>();
-               newRange.lesserValue = range.lesserValue;
-               newRange.equalValue = range.equalValue;
-               newRange.greaterValue = range.greaterValue;
-
-               return new ContinuousMappingPoint<K, V>(value, newRange);
-       }
 }

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMapping.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMapping.java
        2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMapping.java
        2011-07-06 00:31:21 UTC (rev 26051)
@@ -1,146 +1,23 @@
-/*
-  File: DiscreteMapping.java
-
-  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
-  This library is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2.1 of the License, or
-  any later version.
-
-  This library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
-  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
-  documentation provided hereunder is on an "as is" basis, and the
-  Institute for Systems Biology and the Whitehead Institute
-  have no obligations to provide maintenance, support,
-  updates, enhancements or modifications.  In no event shall the
-  Institute for Systems Biology and the Whitehead Institute
-  be liable to any party for direct, indirect, special,
-  incidental or consequential damages, including lost profits, arising
-  out of the use of this software and its documentation, even if the
-  Institute for Systems Biology and the Whitehead Institute
-  have been advised of the possibility of such damage.  See
-  the GNU Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with this library; if not, write to the Free Software Foundation,
-  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
 package org.cytoscape.view.vizmap.mappings;
 
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import org.cytoscape.model.CyColumn;
-import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTableEntry;
 import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.cytoscape.view.vizmap.VisualMappingFunction;
 
-/**
- * Implements a lookup table mapping data to values of a particular class. The
- * data value is extracted from a bundle of attributes by using a specified 
data
- * attribute name.
- */
-public class DiscreteMapping<K, V> extends AbstractVisualMappingFunction<K, V> 
{
+public interface DiscreteMapping<K, V> extends VisualMappingFunction<K,V>{
 
-       private static final Logger logger = 
LoggerFactory.getLogger(DiscreteMapping.class);
+       public static final String DISCRETE = "Discrete Mapping";
 
-       // Name of mapping. This will be used by toString() method.
-       protected static final String DISCRETE = "Discrete Mapping";
-
-       // contains the actual map elements (sorted)
-       private final Map<K, V> attribute2visualMap;
-
        /**
-        * Constructor.
-        * 
-        * @param defObj
-        *            Default Object.
-        */
-       public DiscreteMapping(final String attrName, final Class<K> attrType, 
final VisualProperty<V> vp) {
-               super(attrName, attrType, vp);
-               attribute2visualMap = new HashMap<K, V>();
-       }
-
-       @Override
-       public String toString() {
-               return DISCRETE;
-       }
-
-       @Override
-       public void apply(View<? extends CyTableEntry> view) {
-               if (view == null)
-                       return; // empty view, nothing to do
-
-               applyDiscreteMapping(view);
-       }
-
-       /**
-        * Read attribute from row, map it and apply it.
-        * 
-        * types are guaranteed to be correct (? FIXME: check this)
-        * 
-        * Putting this in a separate method makes it possible to make it
-        * type-parametric.
-        * 
-        * @param <V>
-        *            the type-parameter of the ViewColumn column
-        * @param <K>
-        *            the type-parameter of the key stored in the mapping (the
-        *            object read as an attribute value has to be is-a K)
-        * @param <V>
-        *            the type-parameter of the View
-        */
-       private void applyDiscreteMapping(final View<? extends CyTableEntry> 
view) {
-               final CyRow row = view.getModel().getCyRow();
-               V value = null;
-
-               if (row.isSet(attrName)) {
-                       // skip Views where source attribute is not defined;
-                       // ViewColumn will automatically substitute the per-VS 
or global
-                       // default, as appropriate
-                       final CyColumn column = 
row.getTable().getColumn(attrName);
-                       final Class<?> attrClass = column.getType();
-
-                       if (attrClass.isAssignableFrom(List.class)) {
-                               List<?> list = row.getList(attrName, 
column.getListElementType());
-
-                               if (list != null) {
-                                       for (Object item : list) {
-                                               // TODO: should we convert 
other types to String?
-                                               String key = item.toString();
-                                               value = 
attribute2visualMap.get(key);
-                                               if (value != null)
-                                                       break;
-                                       }
-                               }
-                       } else {
-                               Object key = row.get(attrName, attrType);
-
-                               if (key != null)
-                                       value = attribute2visualMap.get(key);
-                       }
-               }
-
-               // set a new value or null to use the default one:
-               view.setVisualProperty(vp, value);
-       }
-
-       /**
         * Gets Value for Specified Key.
         * 
         * @param key
         *            String Key.
         * @return Object.
         */
-       public V getMapValue(K key) {
-               return attribute2visualMap.get(key);
-       }
+       public V getMapValue(K key);
 
        /**
         * Puts New Key/Value in Map.
@@ -150,9 +27,7 @@
         * @param value
         *            Value Object.
         */
-       public <T extends V> void putMapValue(final K key, final T value) {
-               attribute2visualMap.put(key, value);
-       }
+       public <T extends V> void putMapValue(final K key, final T value);
 
        /**
         * Adds All Members of Specified Map.
@@ -160,15 +35,12 @@
         * @param map
         *            Map.
         */
-       public <T extends V> void putAll(Map<K, T> map) {
-               attribute2visualMap.putAll(map);
-       }
+       public <T extends V> void putAll(Map<K, T> map);
 
        /**
         * gets all map values
         * 
         */
-       public Map<K, V> getAll() {
-               return attribute2visualMap;
-       }
-}
+       public Map<K, V> getAll();
+
+}
\ No newline at end of file

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
 2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
 2011-07-06 00:31:21 UTC (rev 26051)
@@ -11,7 +11,7 @@
        public <K, V> VisualMappingFunction<K, V> 
createVisualMappingFunction(final String attributeName,
                        Class<K> attrValueType, final VisualProperty<V> vp) {
                
-               return new DiscreteMapping<K, V>(attributeName, attrValueType, 
vp);
+               return new DiscreteMappingImpl<K, V>(attributeName, 
attrValueType, vp);
        }
        
        @Override public String toString() {

Copied: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
 (from rev 26049, 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMapping.java)
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
                            (rev 0)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
    2011-07-06 00:31:21 UTC (rev 26051)
@@ -0,0 +1,168 @@
+/*
+  File: DiscreteMappingImpl.java
+
+  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.view.vizmap.mappings;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements a lookup table mapping data to values of a particular class. The
+ * data value is extracted from a bundle of attributes by using a specified 
data
+ * attribute name.
+ */
+public class DiscreteMappingImpl<K, V> extends 
AbstractVisualMappingFunction<K, V> implements DiscreteMapping<K, V> {
+
+       private static final Logger logger = 
LoggerFactory.getLogger(DiscreteMapping.class);
+
+       // contains the actual map elements (sorted)
+       private final Map<K, V> attribute2visualMap;
+
+       /**
+        * Constructor.
+        * 
+        * @param defObj
+        *            Default Object.
+        */
+       public DiscreteMappingImpl(final String attrName, final Class<K> 
attrType, final VisualProperty<V> vp) {
+               super(attrName, attrType, vp);
+               attribute2visualMap = new HashMap<K, V>();
+       }
+
+       /* (non-Javadoc)
+        * @see org.cytoscape.view.vizmap.mappings.DiscreteMapping#toString()
+        */
+       @Override
+       public String toString() {
+               return DISCRETE;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.DiscreteMapping#apply(org.cytoscape.view.model.View)
+        */
+       @Override
+       public void apply(View<? extends CyTableEntry> view) {
+               if (view == null)
+                       return; // empty view, nothing to do
+
+               applyDiscreteMapping(view);
+       }
+
+       /**
+        * Read attribute from row, map it and apply it.
+        * 
+        * types are guaranteed to be correct (? FIXME: check this)
+        * 
+        * Putting this in a separate method makes it possible to make it
+        * type-parametric.
+        * 
+        * @param <V>
+        *            the type-parameter of the ViewColumn column
+        * @param <K>
+        *            the type-parameter of the key stored in the mapping (the
+        *            object read as an attribute value has to be is-a K)
+        * @param <V>
+        *            the type-parameter of the View
+        */
+       private void applyDiscreteMapping(final View<? extends CyTableEntry> 
view) {
+               final CyRow row = view.getModel().getCyRow();
+               V value = null;
+
+               if (row.isSet(attrName)) {
+                       // skip Views where source attribute is not defined;
+                       // ViewColumn will automatically substitute the per-VS 
or global
+                       // default, as appropriate
+                       final CyColumn column = 
row.getTable().getColumn(attrName);
+                       final Class<?> attrClass = column.getType();
+
+                       if (attrClass.isAssignableFrom(List.class)) {
+                               List<?> list = row.getList(attrName, 
column.getListElementType());
+
+                               if (list != null) {
+                                       for (Object item : list) {
+                                               // TODO: should we convert 
other types to String?
+                                               String key = item.toString();
+                                               value = 
attribute2visualMap.get(key);
+                                               if (value != null)
+                                                       break;
+                                       }
+                               }
+                       } else {
+                               Object key = row.get(attrName, attrType);
+
+                               if (key != null)
+                                       value = attribute2visualMap.get(key);
+                       }
+               }
+
+               // set a new value or null to use the default one:
+               view.setVisualProperty(vp, value);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.DiscreteMapping#getMapValue(K)
+        */
+       @Override
+       public V getMapValue(K key) {
+               return attribute2visualMap.get(key);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.DiscreteMapping#putMapValue(K, T)
+        */
+       @Override
+       public <T extends V> void putMapValue(final K key, final T value) {
+               attribute2visualMap.put(key, value);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.DiscreteMapping#putAll(java.util.Map)
+        */
+       @Override
+       public <T extends V> void putAll(Map<K, T> map) {
+               attribute2visualMap.putAll(map);
+       }
+
+       /* (non-Javadoc)
+        * @see org.cytoscape.view.vizmap.mappings.DiscreteMapping#getAll()
+        */
+       @Override
+       public Map<K, V> getAll() {
+               return attribute2visualMap;
+       }
+}

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMapping.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMapping.java
     2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMapping.java
     2011-07-06 00:31:21 UTC (rev 26051)
@@ -1,118 +1,11 @@
-/*
- Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications.  In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage.  See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
 package org.cytoscape.view.vizmap.mappings;
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.cytoscape.model.CyColumn;
-import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTableEntry;
 import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.vizmap.VisualMappingFunction;
 
-/**
- */
-public class PassthroughMapping<K, V> extends
-               AbstractVisualMappingFunction<K, V> {
-       
-       protected static final String PASSTHROUGH = "Passthrough Mapping";
+public interface PassthroughMapping<K, V> extends VisualMappingFunction<K,V> {
 
-       /**
-        * dataType is the type of the _attribute_ !! currently we force that 
to be
-        * the same as the VisualProperty; FIXME: allow different once? but how 
to
-        * coerce?
-        */
-       public PassthroughMapping(final String attrName, final Class<K> 
attrType,
-                       final VisualProperty<V> vp) {
-               super(attrName, attrType, vp);
-       }
+       public static final String PASSTHROUGH = "Passthrough Mapping";
 
-       @Override
-       public String toString() {
-               return PASSTHROUGH;
-       }
-
-       /**
-        * DOCUMENT ME!
-        * 
-        * @param v
-        *            DOCUMENT ME!
-        */
-       @Override
-       public void apply(final View<? extends CyTableEntry> view) {
-               if (view == null)
-                       return; // empty list, nothing to do
-
-               final CyRow row = view.getModel().getCyRow();
-               
-               if (row.isSet(attrName)) {
-                       // skip Views where source attribute is not defined;
-                       // ViewColumn will automatically substitute the per-VS 
or
-                       // global default, as appropriate
-                       final CyColumn column = 
row.getTable().getColumn(attrName);
-                       final Class<?> attrClass = column.getType();
-                       K value = null;
-                       
-                       if (attrClass.isAssignableFrom(List.class)) {
-                               List<?> list = row.getList(attrName, 
column.getListElementType());
-                               StringBuffer sb = new StringBuffer();
-                               
-                               if (list != null && !list.isEmpty()) {
-                                       for (Object item : list)
-                                               sb.append(item.toString() + 
"\n");
-                                       
-                                       sb.deleteCharAt(sb.length() - 1);
-                               }
-                               
-                               value = (K) sb.toString();
-                       } else {
-                               value = row.get(attrName, attrType);
-                       }
-
-                       final V converted = convertToValue(value);
-
-                       view.setVisualProperty(vp, converted);
-               } else {
-                       // remove value, so that default value will be used:
-                       view.setVisualProperty(vp, null);
-               }
-       }
-
-       // TODO: make this converter pluggable
-       private V convertToValue(final K key) {
-               try {
-                       return (V) key;
-               } catch (Exception e) {
-                       return null;
-               }
-
-       }
-}
+}
\ No newline at end of file

Modified: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
      2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
      2011-07-06 00:31:21 UTC (rev 26051)
@@ -9,7 +9,7 @@
        @Override
        public <K, V> VisualMappingFunction<K, V> 
createVisualMappingFunction(final String attributeName,
                        Class<K> attrValueType, VisualProperty<V> vp) {
-               return new PassthroughMapping<K, V>(attributeName, 
attrValueType, vp);
+               return new PassthroughMappingImpl<K, V>(attributeName, 
attrValueType, vp);
        }
        
        @Override public String toString() {

Copied: 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
 (from rev 26049, 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMapping.java)
===================================================================
--- 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
                         (rev 0)
+++ 
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
 2011-07-06 00:31:21 UTC (rev 26051)
@@ -0,0 +1,116 @@
+/*
+ Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.cytoscape.view.vizmap.mappings;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualProperty;
+
+/**
+ */
+public class PassthroughMappingImpl<K, V> extends
+               AbstractVisualMappingFunction<K, V> implements 
PassthroughMapping<K, V> {
+       
+       /**
+        * dataType is the type of the _attribute_ !! currently we force that 
to be
+        * the same as the VisualProperty; FIXME: allow different once? but how 
to
+        * coerce?
+        */
+       public PassthroughMappingImpl(final String attrName, final Class<K> 
attrType,
+                       final VisualProperty<V> vp) {
+               super(attrName, attrType, vp);
+       }
+
+       /* (non-Javadoc)
+        * @see org.cytoscape.view.vizmap.mappings.PassthroughMapping#toString()
+        */
+       @Override
+       public String toString() {
+               return PASSTHROUGH;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.cytoscape.view.vizmap.mappings.PassthroughMapping#apply(org.cytoscape.view.model.View)
+        */
+       @Override
+       public void apply(final View<? extends CyTableEntry> view) {
+               if (view == null)
+                       return; // empty list, nothing to do
+
+               final CyRow row = view.getModel().getCyRow();
+               
+               if (row.isSet(attrName)) {
+                       // skip Views where source attribute is not defined;
+                       // ViewColumn will automatically substitute the per-VS 
or
+                       // global default, as appropriate
+                       final CyColumn column = 
row.getTable().getColumn(attrName);
+                       final Class<?> attrClass = column.getType();
+                       K value = null;
+                       
+                       if (attrClass.isAssignableFrom(List.class)) {
+                               List<?> list = row.getList(attrName, 
column.getListElementType());
+                               StringBuffer sb = new StringBuffer();
+                               
+                               if (list != null && !list.isEmpty()) {
+                                       for (Object item : list)
+                                               sb.append(item.toString() + 
"\n");
+                                       
+                                       sb.deleteCharAt(sb.length() - 1);
+                               }
+                               
+                               value = (K) sb.toString();
+                       } else {
+                               value = row.get(attrName, attrType);
+                       }
+
+                       final V converted = convertToValue(value);
+
+                       view.setVisualProperty(vp, converted);
+               } else {
+                       // remove value, so that default value will be used:
+                       view.setVisualProperty(vp, null);
+               }
+       }
+
+       // TODO: make this converter pluggable
+       private V convertToValue(final K key) {
+               try {
+                       return (V) key;
+               } catch (Exception e) {
+                       return null;
+               }
+
+       }
+}

Modified: 
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
===================================================================
--- 
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
    2011-07-05 23:17:52 UTC (rev 26050)
+++ 
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
    2011-07-06 00:31:21 UTC (rev 26051)
@@ -51,7 +51,7 @@
                
                final Class<String> type = String.class;
 
-               final DiscreteMapping<String, Paint> mapping = new 
DiscreteMapping<String, Paint>(attrName, type,
+               final DiscreteMapping<String, Paint> mapping = new 
DiscreteMappingImpl<String, Paint>(attrName, type,
                                MinimalVisualLexicon.NODE_FILL_COLOR);
                
                return mapping;

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to