All Packages Class Hierarchy This Package Previous Next Index
Collate1 - Comparison by CollationKeys.
Collate2 - Comparison of CollationKeys.
Collate3 - Comparison using Collator objects.
Collate1 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.predicates.*;
import java.text.Collator;
import java.util.Enumeration;
/**
* Comparison by CollationKeys.
*
* @see com.objectspace.jgl.predicates.LessCollationKey
* @see com.objectspace.jgl.predicates.LessEqualCollationKey
* @see com.objectspace.jgl.predicates.GreaterCollationKey
* @see com.objectspace.jgl.predicates.GreaterEqualCollationKey
* @see java.text.Collator
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Collate1
{
public static void show( String tag, Collator collator )
{
// allow duplicates in set
OrderedSet set = new OrderedSet( new LessCollationKey( collator ), true );
// add a few entries
set.add( "Texas" );
set.add( "texas" );
set.add( "Texas Fight" );
// print the resulting container
System.out.println( tag );
Enumeration iterator = set.begin();
while ( iterator.hasMoreElements() )
System.out.println( "\t" + iterator.nextElement() );
}
public static void main( String args[] )
{
Collator collator = Collator.getInstance();
show( "default collating", collator );
collator.setStrength( Collator.PRIMARY );
show( "case insensitive", collator );
}
}
default collating
texas
Texas
Texas Fight
case insensitive
Texas
texas
Texas Fight
Collate2 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.predicates.*;
import java.text.Collator;
import java.text.CollationKey;
import java.util.Enumeration;
/**
* Comparison of CollationKeys.
*
* @see com.objectspace.jgl.predicates.LessCollationKey
* @see com.objectspace.jgl.predicates.LessEqualCollationKey
* @see com.objectspace.jgl.predicates.GreaterCollationKey
* @see com.objectspace.jgl.predicates.GreaterEqualCollationKey
* @see java.text.Collator
* @see java.text.CollationKey
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Collate2
{
public static void show( String tag, Collator collator )
{
// allow duplicates in set
OrderedSet set = new OrderedSet( new LessCollationKey(), true );
// add a few entries
set.add( collator.getCollationKey( "Texas" ) );
set.add( collator.getCollationKey( "texas" ) );
set.add( collator.getCollationKey( "Texas Fight" ) );
// print the resulting container
System.out.println( tag );
Enumeration iterator = set.begin();
while ( iterator.hasMoreElements() )
System.out.println( "\t" + ( (CollationKey)iterator.nextElement() ).getSourceString() );
}
public static void main( String args[] )
{
Collator collator = Collator.getInstance();
show( "default collating", collator );
collator.setStrength( Collator.PRIMARY );
show( "case insensitive", collator );
}
}
default collating
texas
Texas
Texas Fight
case insensitive
Texas
texas
Texas Fight
Collate3 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.predicates.*;
import java.text.Collator;
/**
* Comparison using Collator objects.
*
* @see com.objectspace.jgl.predicates.LessCollator
* @see com.objectspace.jgl.predicates.LessEqualCollator
* @see com.objectspace.jgl.predicates.GreaterCollator
* @see com.objectspace.jgl.predicates.GreaterEqualCollator
* @see java.text.Collator
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Collate3
{
public static void show( String tag, BinaryPredicate predicate )
{
// create a set with given comparitor that allows duplicates
OrderedSet set = new OrderedSet( predicate, true );
// add a few entries
set.add( "Texas" );
set.add( "texas" );
set.add( "Texas Fight" );
// print the resulting container
System.out.println( tag + "\n\t" + set );
}
public static void main( String args[] )
{
show( "old style", new LessString() );
show( "default collating", new LessCollator() );
Collator collator = Collator.getInstance();
collator.setStrength( Collator.PRIMARY );
show( "case insensitive", new LessCollator( collator ) );
}
}
old style
OrderedSet( Texas, Texas Fight, texas )
default collating
OrderedSet( texas, Texas, Texas Fight )
case insensitive
OrderedSet( Texas, texas, Texas Fight )
All Packages Class Hierarchy This Package Previous Next Index