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

The following examples show how to use java.util.UUID#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UuidComparator.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * 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 ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_13751_COMPARING_UUID, 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
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 3
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 4
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 5
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 6
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 7
Source File: KeyHasher.java    From pravega with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a new Key Hash that is immediately after the given one. We define Key Hash H2 to be immediately after
 * Key Hash h1 if there doesn't exist Key Hash H3 such that H1&lt;H3&lt;H2. The ordering is performed using {@link UUID#compareTo}.
 *
 * @return The successor Key Hash, or null if no more successors are available (if {@link IteratorState#isEnd} returns true).
 */
static UUID getNextHash(UUID hash) {
    if (hash == null) {
        // No hash given. By definition, the first hash is the "next" one".
        hash = MIN_HASH;
    } else if (hash.compareTo(MAX_HASH) >= 0) {
        // Given hash already equals or exceeds the max value. There is no successor.
        return null;
    }

    long msb = hash.getMostSignificantBits();
    long lsb = hash.getLeastSignificantBits();
    if (lsb == Long.MAX_VALUE) {
        msb++; // This won't overflow since we've checked that state is not end (i.e., id != MAX).
        lsb = Long.MIN_VALUE;
    } else {
        lsb++;
    }

    return new UUID(msb, lsb);
}
 
Example 8
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.w(TAG, "Characteristic changed");
    UUID charUuid = characteristic.getUuid();
    Log.w(TAG, "Characteristic Update Received: " + charUuid);
    if(charUuid.compareTo(mResponseCharacteristic.getUuid()) == 0) {
        Log.w(TAG, "mResponseCharacteristic Update");
    }
    if(charUuid.compareTo(mCommandCharacteristic.getUuid()) == 0) {
        Log.w(TAG, "mCommandCharacteristic Update");
    }
    if(charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        Log.w(TAG, "mHeartBeatCharacteristic Update");
    }
    if(charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.w(TAG, "mReceiveDataCharacteristic Update");
        byte[] value = characteristic.getValue();
        if(value != null) {
            Log.w(TAG, "Characteristic: " + value);
            Log.w(TAG, "Characteristic: " + value.toString());
            Log.w(TAG, "Characteristic getstring: " + characteristic.getStringValue(0));
            Log.w(TAG, "SUBSCRIBED TO RESPONSE LISTENER");
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        } else {
            Log.w(TAG, "Characteristic was null");
        }
    }
    Log.w(TAG, "NEW VALUE: " + characteristic.getValue().toString());
}
 
Example 9
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    }
}
 
Example 10
Source File: UUIDTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void logJdkUUIDCompareToVariance(UUID u1, UUID u2, int expC)
{
    if ((u1 == null) || (u2 == null))
        return;
    if (u1.version() != u2.version())
        return;
    if (u1.version() == 1)
        return;
    if (u1.compareTo(u2) != expC)
        logger.info("*** Note: java.util.UUID.compareTo() would have compared this differently");
}
 
Example 11
Source File: RestrictionMap.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int compare (AccessRestriction o1, AccessRestriction o2)
{
   UUID u1 = UUID.fromString (o1.getUUID ());
   UUID u2 = UUID.fromString (o2.getUUID ());
   
   return u1.compareTo (u2);
}
 
Example 12
Source File: ShareTest.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.i(TAG, "Characteristic changed");
    UUID charUuid = characteristic.getUuid();
    Log.i(TAG, "Characteristic Update Received: " + charUuid);
    if(charUuid.compareTo(mResponseCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mResponseCharacteristic Update");
    }
    if(charUuid.compareTo(mCommandCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mCommandCharacteristic Update");
    }
    if(charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mHeartBeatCharacteristic Update");
    }
    if(charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mReceiveDataCharacteristic Update");
        byte[] value = characteristic.getValue();
        if(value != null) {
            Log.i(TAG, "Characteristic: " + value);
            Log.i(TAG, "Characteristic: " + value.toString());
            Log.i(TAG, "Characteristic getstring: " + characteristic.getStringValue(0));
            Log.i(TAG, "SUBSCRIBED TO RESPONSE LISTENER");
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        } else {
            Log.w(TAG, "Characteristic was null");
        }
    }
    Log.i(TAG, "NEW VALUE: " + characteristic.getValue().toString());
}
 
Example 13
Source File: TimeUUIDs.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Compare two time UUIDs deterministically, first by their embedded timestamp,
 * next by their node-specific sequence number, finally breaking ties using
 * their embedded node identifier.\
 * @throws UnsupportedOperationException if either uuid is not a timestamp UUID
 */
public static int compare(UUID uuid1, UUID uuid2) {
    int timeResult = Longs.compare(uuid1.timestamp(), uuid2.timestamp());
    if (timeResult != 0) {
        return timeResult;
    }
    // if the time component is identical, break ties using the clockSeqAndNode
    // component (the 64 least significant bits).  the top 16 bits of the lsb are
    // the "clockSeq" number which, theoretically, is an incrementing counter.  in
    // practice, however, (and in com.eaio.uuid) clockSeq is a random number and
    // shouldn't be interpreted as meaning anything.  just use it for breaking ties.
    return uuid1.compareTo(uuid2);
}
 
Example 14
Source File: ShareTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.i(TAG, "Characteristic changed");
    UUID charUuid = characteristic.getUuid();
    Log.i(TAG, "Characteristic Update Received: " + charUuid);
    if(charUuid.compareTo(mResponseCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mResponseCharacteristic Update");
    }
    if(charUuid.compareTo(mCommandCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mCommandCharacteristic Update");
    }
    if(charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mHeartBeatCharacteristic Update");
    }
    if(charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mReceiveDataCharacteristic Update");
        byte[] value = characteristic.getValue();
        if(value != null) {
            Log.i(TAG, "Characteristic: " + value);
            Log.i(TAG, "Characteristic: " + value.toString());
            Log.i(TAG, "Characteristic getstring: " + characteristic.getStringValue(0));
            Log.i(TAG, "SUBSCRIBED TO RESPONSE LISTENER");
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        } else {
            Log.w(TAG, "Characteristic was null");
        }
    }
    Log.i(TAG, "NEW VALUE: " + characteristic.getValue().toString());
}
 
Example 15
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.i(TAG, "Characteristic changed");
    UUID charUuid = characteristic.getUuid();
    Log.i(TAG, "Characteristic Update Received: " + charUuid);
    if(charUuid.compareTo(mResponseCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mResponseCharacteristic Update");
    }
    if(charUuid.compareTo(mCommandCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mCommandCharacteristic Update");
    }
    if(charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mHeartBeatCharacteristic Update");
    }
    if(charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.i(TAG, "mReceiveDataCharacteristic Update");
        byte[] value = characteristic.getValue();
        if(value != null) {
            Log.i(TAG, "Characteristic: " + value);
            Log.i(TAG, "Characteristic: " + value.toString());
            Log.i(TAG, "Characteristic getstring: " + characteristic.getStringValue(0));
            Log.i(TAG, "SUBSCRIBED TO RESPONSE LISTENER");
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        } else {
            Log.w(TAG, "Characteristic was null");
        }
    }
    Log.i(TAG, "NEW VALUE: " + characteristic.getValue().toString());
}
 
Example 16
Source File: EventMatcherImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@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 17
Source File: SegmentAttributeIteratorTests.java    From pravega with Apache License 2.0 4 votes vote down vote up
private static boolean isBetween(UUID toCheck, UUID fromId, UUID toId) {
    return fromId.compareTo(toCheck) <= 0 && toId.compareTo(toCheck) >= 0;
}
 
Example 18
Source File: ItemService.java    From Transport-Pipes with MIT License 4 votes vote down vote up
public DuctType readDuctNBTTags(ItemStack item, DuctRegister ductRegister) {
    String basicDuctTypeSerialized = (String) NMSUtils.readItemStackNBT(item, "basicDuctType", "String");
    if (basicDuctTypeSerialized != null && !basicDuctTypeSerialized.isEmpty()) {
        BaseDuctType bdt = ductRegister.baseDuctTypeOf(basicDuctTypeSerialized);
        String ductTypeSerialized = (String) NMSUtils.readItemStackNBT(item, "ductType", "String");
        if (ductTypeSerialized != null && !ductTypeSerialized.isEmpty()) {
            return bdt.ductTypeOf(ductTypeSerialized);
        }
    } else {
        //legacy ductType loading (with the gameprofile uuids of the skulls)
        if (item.getItemMeta() instanceof SkullMeta) {

            SkullMeta sm = (SkullMeta) item.getItemMeta();
            try {

                Field profileField = sm.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                Object profile = profileField.get(sm);
                if (profile == null)
                    return null;

                Field idField = Class.forName("com.mojang.authlib.GameProfile").getDeclaredField("id");
                idField.setAccessible(true);
                UUID id = (UUID) idField.get(profile);
                if (id == null)
                    return null;

                for (DuctType dt : ductRegister.baseDuctTypeOf("pipe").ductTypes()) {
                    Object dtProfile = profileField.get(dt.getBaseDuctType().getItemManager().getItem(dt).getItemMeta());
                    UUID dtId = (UUID) idField.get(dtProfile);

                    if (id.compareTo(dtId) == 0) {
                        return dt;
                    }
                }
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException e) {
                e.printStackTrace();
            }

        }
    }
    return null;
}
 
Example 19
Source File: Common.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
public static boolean equalsUUID(UUID uuida, UUID uuidb) {
    return (uuida.compareTo(uuidb) == 0);
}