org.norther.tammi.core.rt.util
Class VariableComparator

java.lang.Object
  extended by org.norther.tammi.acorn.util.PropertyComparator
      extended by org.norther.tammi.core.rt.util.VariableComparator
All Implemented Interfaces:
Serializable, Comparator<Object>

public class VariableComparator
extends PropertyComparator

A comparator for named attributes of variables.

Version:
$Id: VariableComparator.java,v 1.2 2009/09/28 15:08:44 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
VariableComparator(String attr)
          Constructs a new comparator.
VariableComparator(String[] attrs)
          Constructs a new comparator for multiple attributes.
VariableComparator(String[] attrs, Comparator<?> comp)
          Constructs a new comparator for multiple attributes with a value comparator.
VariableComparator(String attr, Comparator<?> comp)
          Constructs a new comparator with a value comparator.
 
Method Summary
 int compare(Object var1, Object var2)
          Compares two variables.
protected  Object getProperty(Object obj, String prop)
          Gets the named property value.
 
Methods inherited from class org.norther.tammi.acorn.util.PropertyComparator
compare, getNestedProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

VariableComparator

public VariableComparator(String attr)
Constructs a new comparator.

Parameters:
attr - the attribute to compare.

VariableComparator

public VariableComparator(String attr,
                          Comparator<?> comp)
Constructs a new comparator with a value comparator.

Parameters:
attr - the attribute to compare.
comp - the attribute value comparator.

VariableComparator

public VariableComparator(String[] attrs)
Constructs a new comparator for multiple attributes.

Parameters:
attrs - the attributes to compare.

VariableComparator

public VariableComparator(String[] attrs,
                          Comparator<?> comp)
Constructs a new comparator for multiple attributes with a value comparator.

Parameters:
attrs - the attributes to compare.
comp - the attribute value comparator.
Method Detail

compare

public int compare(Object var1,
                   Object var2)
Compares two variables.

Specified by:
compare in interface Comparator<Object>
Overrides:
compare in class PropertyComparator
Parameters:
var1 - the first variable to be compared.
var2 - the second variable to be compared.
Returns:
-1, 0 or 1 based on comparison.

getProperty

protected Object getProperty(Object obj,
                             String prop)
                      throws Exception
Description copied from class: PropertyComparator
Gets the named property value.

Overrides:
getProperty in class PropertyComparator
Parameters:
obj - the object.
prop - the property.
Returns:
the value or null.
Throws:
Exception - on errors.


Copyright © 2004 The Norther Organization. All rights reserved.