Example usage for com.google.common.hash Hashing combineUnordered

List of usage examples for com.google.common.hash Hashing combineUnordered

Introduction

In this page you can find the example usage for com.google.common.hash Hashing combineUnordered.

Prototype

public static HashCode combineUnordered(Iterable<HashCode> hashCodes) 

Source Link

Document

Returns a hash code, having the same bit length as each of the input hash codes, that combines the information of these hash codes in an unordered fashion.

Usage

From source file:org.apache.beam.sdk.io.common.HashingFn.java

@Override
public Accum addInput(Accum accum, String input) {
    List<HashCode> elementHashes = Lists.newArrayList();
    if (accum.hashCode != null) {
        elementHashes.add(accum.hashCode);
    }//from ww  w .j  a  va 2  s .  c  o m
    HashCode inputHashCode = Hashing.murmur3_128().hashString(input, StandardCharsets.UTF_8);
    elementHashes.add(inputHashCode);
    accum.hashCode = Hashing.combineUnordered(elementHashes);
    return accum;
}

From source file:org.apache.beam.sdk.io.hadoop.inputformat.hashing.HashingFn.java

@Override
public Accum addInput(Accum accum, String input) {
    List<HashCode> elementHashes = Lists.newArrayList();
    if (accum.hashCode != null) {
        elementHashes.add(accum.hashCode);
    }// w w  w  . jav a 2s  . c o m
    HashCode inputHashCode = Hashing.sha1().hashString(input, StandardCharsets.UTF_8);
    elementHashes.add(inputHashCode);
    accum.hashCode = Hashing.combineUnordered(elementHashes);
    return accum;
}

From source file:org.apache.beam.sdk.io.common.HashingFn.java

@Override
public Accum mergeAccumulators(Iterable<Accum> accums) {
    Accum merged = createAccumulator();/* w w w  . j av a 2 s .c o  m*/
    List<HashCode> elementHashes = Lists.newArrayList();
    for (Accum accum : accums) {
        if (accum.hashCode != null) {
            elementHashes.add(accum.hashCode);
        }
    }
    merged.hashCode = Hashing.combineUnordered(elementHashes);
    return merged;
}

From source file:org.apache.beam.sdk.testing.FileChecksumMatcher.java

private String computeHash(@Nonnull List<String> strs) {
    if (strs.isEmpty()) {
        return Hashing.sha1().hashString("", StandardCharsets.UTF_8).toString();
    }/*w w  w  .  j a  v  a 2 s.  c  o  m*/

    List<HashCode> hashCodes = new ArrayList<>();
    for (String str : strs) {
        hashCodes.add(Hashing.sha1().hashString(str, StandardCharsets.UTF_8));
    }
    return Hashing.combineUnordered(hashCodes).toString();
}

From source file:org.apache.beam.sdk.io.gcp.testing.BigqueryMatcher.java

private String generateHash(@Nonnull List<TableRow> rows) {
    List<HashCode> rowHashes = Lists.newArrayList();
    for (TableRow row : rows) {
        List<String> cellsInOneRow = Lists.newArrayList();
        for (TableCell cell : row.getF()) {
            cellsInOneRow.add(Objects.toString(cell.getV()));
            Collections.sort(cellsInOneRow);
        }/*  w  w w.  j  a  v a2  s. com*/
        rowHashes.add(Hashing.sha1().hashString(cellsInOneRow.toString(), StandardCharsets.UTF_8));
    }
    return Hashing.combineUnordered(rowHashes).toString();
}