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

The following examples show how to use java.util.UUID#hashCode() . 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: IPonyManager.java    From MineLittlePony with MIT License 4 votes vote down vote up
/**
 * Returns true if the given uuid is of a player would would use the ALEX skin type.
 */
static boolean isSlimSkin(UUID uuid) {
    return (uuid.hashCode() & 1) == 1;
}
 
Example 2
Source File: AdvancedFakePlayer.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public AdvancedFakePlayer(WorldServer world, UUID uuid) {
    this(world, uuid, "[" + Gadomancy.MODID + ":" + uuid.hashCode() + "]");
}
 
Example 3
Source File: UUIDs.java    From Visage with MIT License 4 votes vote down vote up
public static boolean isAlex(UUID uuid) {
	return (uuid.hashCode() & 1) == 1;
}
 
Example 4
Source File: ClientConsistentHashSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Test hash codes collisions.
 *
 * @throws Exception In case of any exception.
 */
@Test
public void testCollisions() throws Exception {
    Map<Integer, Set<UUID>> map = new HashMap<>();

    // Different nodes, but collide hash codes.
    Collection<UUID> nodes = new LinkedHashSet<>();

    // Generate several nodes with collide hash codes.
    while (nodes.size() < 10) {
        UUID uuid = UUID.randomUUID();
        int hashCode = uuid.hashCode();

        Set<UUID> set = map.get(hashCode);

        if (set == null)
            map.put(hashCode, set = new LinkedHashSet<>());

        set.add(uuid);

        if (set.size() > 1)
            nodes.addAll(set);
    }

    map.clear(); // Clean up.

    GridClientConsistentHash<UUID> hash = new GridClientConsistentHash<>();

    hash.addNodes(nodes, REPLICAS);

    boolean fail = false;

    for (UUID exp : nodes) {
        UUID act = hash.node(0, Arrays.asList(exp));

        if (exp.equals(act))
            info("Validation succeed [exp=" + exp + ", act=" + act + ']');
        else {
            info("Validation failed  [exp=" + exp + ", act=" + act + ']');

            fail = true;
        }
    }

    if (fail)
        fail("Failed to resolve consistent hash node, when node's hash codes collide: " + nodes);
}
 
Example 5
Source File: GridConsistentHashSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Test hash codes collisions.
 *
 * @throws Exception In case of any exception.
 */
@Test
public void testCollisions() throws Exception {
    Map<Integer, Set<UUID>> map = new HashMap<>();

    // Different nodes, but collide hash codes.
    Collection<UUID> nodes = new LinkedHashSet<>();

    // Generate several nodes with collide hash codes.
    while (nodes.size() < 8) {
        UUID uuid = UUID.randomUUID();
        int hashCode = uuid.hashCode();

        Set<UUID> set = map.get(hashCode);

        if (set == null)
            map.put(hashCode, set = new LinkedHashSet<>());

        set.add(uuid);

        if (set.size() > 1)
            nodes.addAll(set);
    }

    map.clear(); // Clean up.

    GridConsistentHash<UUID> hash = new GridConsistentHash<>();

    hash.addNodes(nodes, REPLICAS);

    boolean fail = false;

    for (UUID exp : nodes) {
        UUID act = hash.node(0, Arrays.asList(exp));

        if (exp.equals(act))
            info("Validation succeed [exp=" + exp + ", act=" + act + ']');
        else {
            info("Validation failed  [exp=" + exp + ", act=" + act + ']');

            fail = true;
        }
    }

    if (fail)
        fail("Failed to resolve consistent hash node, when node's hash codes collide: " + nodes);
}
 
Example 6
Source File: DevCommonUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 获取随机唯一数 HashCode
 * @param uuid {@link UUID}
 * @return 随机 UUID hashCode
 */
public static int randomUUIDToHashCode(final UUID uuid) {
    return (uuid != null) ? uuid.hashCode() : 0;
}
 
Example 7
Source File: DevCommonUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 获取随机唯一数 HashCode
 * @param uuid {@link UUID}
 * @return 随机 UUID hashCode
 */
public static int randomUUIDToHashCode(final UUID uuid) {
    return (uuid != null) ? uuid.hashCode() : 0;
}
 
Example 8
Source File: IdProxy.java    From cuba with Apache License 2.0 2 votes vote down vote up
/**
 * Create proxy for the specified ID and UUID values. You might need it for finding {@code HasUuid} entities stored
 * in hashtables by ID.
 *
 * @param value real ID value
 * @param uuid entity's UUID
 */
public static <T extends Number> IdProxy<T> of(T value, UUID uuid) {
    Preconditions.checkNotNullArgument(uuid, "uuid is null");
    return new IdProxy<>(value, uuid.hashCode());
}