Java Code Examples for java.util.UUID.compareTo()

The following are Jave code examples for showing how to use compareTo() of the java.util.UUID class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: directory-ldap-api   File: UuidComparator.java   View Source Code Vote up 6 votes
/**
 * Compare two UUID.
 * 
 * @param uuid1 The first UUID
 * @param uuid2 he second UUID
 * @return -1 if the first UUID is lower than the second UUID, 1 if it's higher, 0
 * if they are equal  
 */
public int compare( UUID uuid1, UUID uuid2 )
{
    if ( IS_DEBUG )
    {
        LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 );
    }

    // -------------------------------------------------------------------
    // Handle some basis cases
    // -------------------------------------------------------------------
    if ( uuid1 == null )
    {
        return ( uuid2 == null ) ? 0 : -1;
    }

    if ( uuid2 == null )
    {
        return 1;
    }

    return uuid1.compareTo( uuid2 );
}
 
Example 2
Project: neoscada   File: EventMatcherImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings ( { "unchecked", "incomplete-switch" } )
private static boolean compareId ( final FilterAssertion assertion, final UUID left )
{
    if ( assertion.getAssertion () == Assertion.PRESENCE )
    {
        return left != null;
    }
    if ( assertion.getValue () == null )
    {
        return false;
    }
    if ( ! ( assertion.getValue () instanceof String || assertion.getValue () instanceof UUID || assertion.getValue () instanceof Collection<?> ) )
    {
        return false;
    }
    if ( assertion.getAssertion () == Assertion.SUBSTRING )
    {
        return left.toString ().matches ( toRegEx ( (Collection<String>)assertion.getValue () ) );
    }
    final UUID right = UUID.fromString ( assertion.getValue ().toString () );
    switch ( assertion.getAssertion () )
    {
        case LESSTHAN:
            return left.compareTo ( right ) == -1;
        case LESSEQ:
            return left.compareTo ( right ) == -1 || left.compareTo ( right ) == 0;
        case EQUALITY:
            return left.compareTo ( right ) == 0;
        case GREATEREQ:
            return left.compareTo ( right ) == 1 || left.compareTo ( right ) == 0;
        case GREATERTHAN:
            return left.compareTo ( right ) == 1;
        case APPROXIMATE:
            throw new IllegalArgumentException ( Messages.getString ( "EventMatcherImpl.Error.ApproximateNotSupported" ) ); //$NON-NLS-1$
    }
    return false;
}
 
Example 3
Project: dhus-core   File: RestrictionMap.java   View Source Code Vote up 5 votes
@Override
public int compare (AccessRestriction o1, AccessRestriction o2)
{
   UUID u1 = UUID.fromString (o1.getUUID ());
   UUID u2 = UUID.fromString (o2.getUUID ());
   
   return u1.compareTo (u2);
}