Java Code Examples for com.google.common.hash.Hasher#putShort()

The following examples show how to use com.google.common.hash.Hasher#putShort() . 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: TimeZoneKeyTest.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
@Test
public void testZoneKeyData()
{
    Hasher hasher = Hashing.murmur3_128().newHasher();

    SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>()
    {
        @Override
        public int compare(TimeZoneKey left, TimeZoneKey right)
        {
            return Short.compare(left.getKey(), right.getKey());
        }
    }, TimeZoneKey.getTimeZoneKeys());

    for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) {
        hasher.putShort(timeZoneKey.getKey());
        hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8);
    }
    // Zone file should not (normally) be changed, so let's make this more difficult
    assertEquals("zone-index.properties file contents changed!", hasher.hash().asLong(), -4582158485614614451L);
}
 
Example 2
Source File: TestTimeZoneKey.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testZoneKeyData()
{
    Hasher hasher = Hashing.murmur3_128().newHasher();

    SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>()
    {
        @Override
        public int compare(TimeZoneKey left, TimeZoneKey right)
        {
            return Short.compare(left.getKey(), right.getKey());
        }
    }, TimeZoneKey.getTimeZoneKeys());

    for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) {
        hasher.putShort(timeZoneKey.getKey());
        hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8);
    }
    // Zone file should not (normally) be changed, so let's make this more difficult
    assertEquals(hasher.hash().asLong(), -972834036790299986L, "zone-index.properties file contents changed!");
}
 
Example 3
Source File: NullHasherTest.java    From elastic-load-balancing-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() {
    Hasher hasher = NullHasher.INSTANCE;
    assertEquals(0, hasher.hash().asInt());
    hasher.putBoolean(false);
    hasher.putByte((byte) 3);
    hasher.putBytes(new byte[0]);
    hasher.putBytes(null, 3, 3);
    hasher.putChar('c');
    hasher.putDouble(3.3);
    hasher.putFloat(3.4f);
    hasher.putInt(7);
    hasher.putLong(3);
    hasher.putObject(null, null);
    hasher.putShort((short) 7);
    hasher.putString(null, null);
    hasher.putUnencodedChars(null);
}