Example usage for com.google.common.primitives Bytes contains

List of usage examples for com.google.common.primitives Bytes contains

Introduction

In this page you can find the example usage for com.google.common.primitives Bytes contains.

Prototype

public static boolean contains(byte[] array, byte target) 

Source Link

Document

Returns true if target is present as an element anywhere in array .

Usage

From source file:com.jeffreybosboom.strata.Solution.java

/**
 * Returns a complete solution for the given puzzle; that is, a solution
 * containing all rows and columns in the given puzzle, even those not
 * required to meet constraints.// w  w w . ja v  a2s.co m
 * @param p a puzzle
 * @return a complete solution to the given puzzle
 */
public Solution complete(Puzzle p) {
    byte[] newOrder = new byte[p.rows() + p.cols()];
    byte[] newColors = new byte[p.rows() + p.cols()];
    int idx = 0;
    //add anything missing
    for (byte row = 0; row < p.rows(); ++row)
        if (!Bytes.contains(order, row)) {
            newOrder[idx] = row;
            newColors[idx++] = 0;
        }
    for (byte col = 0; col < p.cols(); ++col)
        if (!Bytes.contains(order, (byte) (col | 128))) {
            newOrder[idx] = (byte) (col | 128);
            newColors[idx++] = 0;
        }
    //replay our contents in order
    System.arraycopy(order, 0, newOrder, idx, order.length);
    System.arraycopy(colors, 0, newColors, idx, colors.length);
    return new Solution(newOrder, newColors);
}