git-svn-id: https://svn.coded.pt/svn/SIPRP@1215 bb69d46d-e84e-40c8-a05a-06db0d633741
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 753 B After Width: | Height: | Size: 753 B |
|
Before Width: | Height: | Size: 914 B After Width: | Height: | Size: 914 B |
|
Before Width: | Height: | Size: 765 B After Width: | Height: | Size: 765 B |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 936 B After Width: | Height: | Size: 936 B |
|
Before Width: | Height: | Size: 876 B After Width: | Height: | Size: 876 B |
@ -1,4 +1,4 @@
|
||||
package leaf.data;
|
||||
package com.evolute.adt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -1,100 +1,48 @@
|
||||
package com.evolute.adt;
|
||||
|
||||
public class Pair<CARCLASS extends Object, CDRCLASS extends Object> implements Comparable<Pair<? extends CARCLASS,? extends CDRCLASS>>
|
||||
public class Pair<CarClass extends Comparable<CarClass>, CdrClass> implements Comparable<Pair<CarClass, CdrClass>>
|
||||
{
|
||||
|
||||
private final CARCLASS left;
|
||||
|
||||
private final CDRCLASS right;
|
||||
|
||||
public Pair( CARCLASS leftValue, CDRCLASS rightValue )
|
||||
{
|
||||
this.left = leftValue;
|
||||
this.right = rightValue;
|
||||
}
|
||||
|
||||
public CARCLASS getLeft()
|
||||
private final CarClass car;
|
||||
private final CdrClass cdr;
|
||||
|
||||
public Pair(CarClass car, CdrClass cdr)
|
||||
{
|
||||
return left;
|
||||
this.car = car;
|
||||
this.cdr = cdr;
|
||||
}
|
||||
|
||||
public CDRCLASS getRight()
|
||||
public CarClass getCar()
|
||||
{
|
||||
return right;
|
||||
return car;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
|
||||
public CdrClass getCdr()
|
||||
{
|
||||
boolean result = obj != null;
|
||||
if( result )
|
||||
{
|
||||
if( obj instanceof Pair )
|
||||
{
|
||||
result = ( left == null ? (((Pair) obj).left == null ) : (left.equals(((Pair) obj).left)) );
|
||||
result &= ( right == null ? (((Pair) obj).right == null ) : (right.equals(((Pair) obj).right)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return cdr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Pair<? extends CARCLASS, ? extends CDRCLASS> pair)
|
||||
public int compareTo( Pair<CarClass, CdrClass> toPair )
|
||||
{
|
||||
int result = compare( left, pair == null ? null : pair.left );
|
||||
if( result == 0 )
|
||||
if(toPair == null)
|
||||
{
|
||||
result = compare( right, pair == null ? null : pair.right );
|
||||
return 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private int compare( Object a, Object b )
|
||||
{
|
||||
int result = a == null ? (b == null ? 0 : -1 ) : ( b == null ? 1 : 0 );
|
||||
if( a != null && b != null )
|
||||
else if(car == null && toPair.getCar() == null)
|
||||
{
|
||||
if( a.getClass().equals( b.getClass() ) && (a instanceof Comparable) )
|
||||
{
|
||||
((Comparable)a).compareTo(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = compare(a.toString(),b.toString());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = super.hashCode();
|
||||
if( left != null )
|
||||
{
|
||||
result = left.hashCode();
|
||||
if( right != null )
|
||||
{
|
||||
result ^= right.hashCode();
|
||||
}
|
||||
}
|
||||
else if( right != null )
|
||||
else
|
||||
{
|
||||
result = right.hashCode();
|
||||
return getCar().compareTo( toPair.getCar() );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "<"+left+","+right+">";
|
||||
return "(" + (car == null ? "" : car.toString()) + ", "+ (cdr == null ? "" : cdr.toString()) + ")";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package leaf.data;
|
||||
package com.evolute.adt;
|
||||
|
||||
public interface Validator<OBJECT_CLASS extends Object>
|
||||
{
|
||||
@ -1,48 +0,0 @@
|
||||
package leaf.data;
|
||||
|
||||
public class Pair<CarClass extends Comparable<CarClass>, CdrClass> implements Comparable<Pair<CarClass, CdrClass>>
|
||||
{
|
||||
|
||||
private final CarClass car;
|
||||
private final CdrClass cdr;
|
||||
|
||||
public Pair(CarClass car, CdrClass cdr)
|
||||
{
|
||||
this.car = car;
|
||||
this.cdr = cdr;
|
||||
}
|
||||
|
||||
public CarClass getCar()
|
||||
{
|
||||
return car;
|
||||
}
|
||||
|
||||
public CdrClass getCdr()
|
||||
{
|
||||
return cdr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( Pair<CarClass, CdrClass> toPair )
|
||||
{
|
||||
if(toPair == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(car == null && toPair.getCar() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getCar().compareTo( toPair.getCar() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "(" + (car == null ? "" : car.toString()) + ", "+ (cdr == null ? "" : cdr.toString()) + ")";
|
||||
}
|
||||
|
||||
}
|
||||