Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:edu.oregonstate.eecs.mcplan.domains.sailing.SailingWorlds.java

public static SailingState randomObstacles(final RandomGenerator rng, final double p, final int V, final int T,
        final int dim) {
    final String[] spec = new String[dim];
    for (int y = 0; y < dim; ++y) {
        final char[] noisy = new char[dim];
        Arrays.fill(noisy, 'w');
        for (int x = 0; x < dim; ++x) {
            // Note that the y-axis is inverted at this point since the
            // parse() function is designed to accept a literal array.
            if (x == 0 && y == dim - 1) {
                // No obstacles in start
                continue;
            }/*from  ww  w . jav a  2s.  c o  m*/
            if (x == dim - 1 && y == 0) {
                // No obstacles in goal
                continue;
            }
            if (rng.nextDouble() < p) {
                noisy[x] = 'l';
            }
        }
        spec[y] = new String(noisy);
    }

    final SailingTerrain[][] terrain = parse(spec, 1);
    return new SailingState(terrain, V, T);
}

From source file:org.cryptomator.crypto.engine.impl.CryptorImpl.java

@Override
public void randomizeMasterkey() {
    final byte[] randomBytes = new byte[KEYLENGTH_IN_BYTES];
    try {/*from  w w  w . j  a  v  a  2 s.com*/
        randomSource.nextBytes(randomBytes);
        encryptionKey = new SecretKeySpec(randomBytes, ENCRYPTION_ALG);
        randomSource.nextBytes(randomBytes);
        macKey = new SecretKeySpec(randomBytes, MAC_ALG);
    } finally {
        Arrays.fill(randomBytes, (byte) 0x00);
    }
}

From source file:com.linkedin.r2.filter.compression.stream.TestStreamingCompression.java

@Test
public void testGzipCompressor()
        throws IOException, InterruptedException, CompressionException, ExecutionException {
    StreamingCompressor compressor = new GzipCompressor(_executor);
    final byte[] origin = new byte[BUF_SIZE];
    Arrays.fill(origin, (byte) 'b');

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    IOUtils.write(origin, gzip);/*  w w w .j a v  a  2 s .c o m*/
    gzip.close();
    byte[] compressed = out.toByteArray();

    testCompress(compressor, origin, compressed);
    testDecompress(compressor, origin, compressed);
    testCompressThenDecompress(compressor, origin);
}

From source file:com.espertech.esper.pattern.EvalOrStateNode.java

public final void quit() {
    for (EvalStateNode child : childNodes) {
        if (child != null) {
            child.quit();/*from w  w w. j a  v  a  2 s.  c  om*/
        }
    }
    Arrays.fill(childNodes, null);
}

From source file:com.analog.lyric.dimple.solvers.gibbs.customFactors.MultinomialBlockProposal.java

@Override
public BlockProposal next(Value[] currentValue, Domain[] variableDomain) {
    final DimpleRandom rand = activeRandom();

    double proposalForwardEnergy = 0;
    double proposalReverseEnergy = 0;
    int argumentIndex = 0;
    int argumentLength = currentValue.length;
    Value[] newValue = new Value[argumentLength];
    for (int i = 0; i < argumentLength; i++)
        newValue[i] = Value.create(variableDomain[i]);

    // Get the current alpha values
    double[] alpha;
    double[] alphaEnergy;
    double alphaSum = 0;
    if (_customFactor.isAlphaEnergyRepresentation()) {
        alphaEnergy = _customFactor.getCurrentAlpha();
        alpha = new double[alphaEnergy.length];
        for (int i = 0; i < alphaEnergy.length; i++) {
            alpha[i] = Math.exp(-alphaEnergy[i]);
            alphaSum += alpha[i];//  w  w w.  j a  va2  s .  com
        }
    } else {
        alpha = _customFactor.getCurrentAlpha();
        alphaEnergy = new double[alpha.length];
        for (int i = 0; i < alpha.length; i++) {
            alphaEnergy[i] = -Math.log(alpha[i]);
            alphaSum += alpha[i];
        }
    }
    if (alphaSum == 0) // Shouldn't happen, but can during initialization
    {
        Arrays.fill(alpha, 1);
        Arrays.fill(alphaEnergy, 0);
        alphaSum = alpha.length;
    }

    int nextN = _constantN;
    if (!_hasConstantN) {
        // If N is variable, sample N uniformly
        int previousN = currentValue[argumentIndex].getIndex();
        int NDomainSize = requireNonNull(variableDomain[0].asDiscrete()).size();
        nextN = rand.nextInt(NDomainSize);
        newValue[argumentIndex].setIndex(nextN);
        argumentIndex++;

        // Add this portion of -log p(x_proposed -> x_previous)
        proposalReverseEnergy += -org.apache.commons.math3.special.Gamma.logGamma(previousN + 1)
                + previousN * Math.log(alphaSum);

        // Add this portion of -log p(x_previous -> x_proposed)
        proposalForwardEnergy += -org.apache.commons.math3.special.Gamma.logGamma(nextN + 1)
                + nextN * Math.log(alphaSum);
    }

    // Given N and alpha, resample the outputs
    // Multinomial formed by successively sampling from a binomial and subtracting each count from the total
    // FIXME: Assumes all outputs are variable (no constant outputs)
    int remainingN = nextN;
    int alphaIndex = 0;
    for (; argumentIndex < argumentLength; argumentIndex++, alphaIndex++) {
        double alphai = alpha[alphaIndex];
        double alphaEnergyi = alphaEnergy[alphaIndex];
        int previousX = currentValue[argumentIndex].getIndex();
        int nextX;
        if (argumentIndex < argumentLength - 1)
            nextX = rand.nextBinomial(remainingN, alphai / alphaSum);
        else // Last value
            nextX = remainingN;
        newValue[argumentIndex].setIndex(nextX);
        remainingN -= nextX; // Subtract the sample value from the remaining total count
        alphaSum -= alphai; // Subtract this alpha value from the sum used for normalization

        double previousXNegativeLogAlphai;
        double nextXNegativeLogAlphai;
        if (alphai == 0 && previousX == 0)
            previousXNegativeLogAlphai = 0;
        else
            previousXNegativeLogAlphai = previousX * alphaEnergyi;
        if (alphai == 0 && nextX == 0)
            nextXNegativeLogAlphai = 0;
        else
            nextXNegativeLogAlphai = nextX * alphaEnergyi;

        // Add this portion of -log p(x_proposed -> x_previous)
        proposalReverseEnergy += previousXNegativeLogAlphai
                + org.apache.commons.math3.special.Gamma.logGamma(previousX + 1);

        // Add this portion of -log p(x_previous -> x_proposed)
        proposalForwardEnergy += nextXNegativeLogAlphai
                + org.apache.commons.math3.special.Gamma.logGamma(nextX + 1);
    }

    return new BlockProposal(newValue, proposalForwardEnergy, proposalReverseEnergy);
}

From source file:clus.statistic.RegressionStatBinaryNomiss.java

public void reset() {
    m_SumWeight = 0.0;
    m_NbExamples = 0;
    Arrays.fill(m_SumValues, 0.0);
}

From source file:imageviewer.util.PasswordGenerator.java

private final char[] getPassword(InputStream in, String prompt) throws IOException {

    MaskingThread mt = new MaskingThread(prompt);
    Thread thread = new Thread(mt);
    thread.start();//from  w  ww  . j a v a  2s  . co  m

    char[] lineBuffer;
    char[] buf = lineBuffer = new char[128];

    int room = buf.length;
    int offset = 0;
    int c;

    loop: while (true) {
        switch (c = in.read()) {
        case -1:
        case '\n':
            break loop;
        case '\r':
            int c2 = in.read();
            if ((c2 != '\n') && (c2 != -1)) {
                if (!(in instanceof PushbackInputStream))
                    in = new PushbackInputStream(in);
                ((PushbackInputStream) in).unread(c2);
            } else {
                break loop;
            }
        default:
            if (--room < 0) {
                buf = new char[offset + 128];
                room = buf.length - offset - 1;
                System.arraycopy(lineBuffer, 0, buf, 0, offset);
                Arrays.fill(lineBuffer, ' ');
                lineBuffer = buf;
            }
            buf[offset++] = (char) c;
            break;
        }
    }

    mt.stopMasking();
    if (offset == 0)
        return null;
    char[] ret = new char[offset];
    System.arraycopy(buf, 0, ret, 0, offset);
    Arrays.fill(buf, ' ');
    return ret;
}

From source file:net.navasoft.madcoin.backend.services.rest.impl.Provider.java

/**
 * Sets the policies.//from  w w w.  j a  v  a 2  s  .c  om
 * 
 * @param policies
 *            the new policies
 * @since 8/09/2014, 01:45:38 AM
 */
@Override
public void setPolicies(Object... policies) {
    if (policies.length > 2) {
        inicioVentanas = (Calendar[]) Array.newInstance(Calendar.class, (policies.length - 2) / 2);
        finVentanas = (Calendar[]) Array.newInstance(Calendar.class, (policies.length - 2) / 2);
        Arrays.fill(inicioVentanas, Calendar.getInstance());
        Arrays.fill(finVentanas, Calendar.getInstance());
    }
    providerPreferrence = (ScopeProvider) policies[policies.length - 2];
    providerContact = (String) policies[policies.length - 1];
    policies = ArrayUtils.remove(policies, policies.length - 2);
    policies = ArrayUtils.remove(policies, policies.length - 1);
    int ini = 0;
    int fini = 0;
    for (int contadorMultiplos = 0; contadorMultiplos < policies.length; contadorMultiplos++) {
        if (contadorMultiplos % 2 == 0) {
            java.util.Date horario = (Date) policies[contadorMultiplos];
            inicioVentanas[ini].setTime(horario);
            ini++;
        } else {
            java.util.Date horario = (Date) policies[contadorMultiplos];
            finVentanas[fini].setTime(horario);
            fini++;
        }
    }
}

From source file:ffx.potential.bonded.Rotamer.java

/**
 * Constructs a Rotamer from a Residue, an array of torsions, and optionally
 * an array of torsion bin widths. Intended to be agnostic to AA vs. NA vs.
 * other, and not require explicitly passed-in sigmas.
 * //from  w w  w .  j a  v a 2s.  c om
 * @param res Residue to construct rotamer for
 * @param chis Torsion angles
 * @param sigmas Torsion angle bin widths (optional)
 */
public Rotamer(Residue res, double[] chis, double[] sigmas) {
    int nChi = chis.length;
    angles = new double[nChi];
    Arrays.fill(angles, 0);
    System.arraycopy(chis, 0, angles, 0, nChi);

    // Hooray, 
    double[] tempVals = new double[7];
    Arrays.fill(tempVals, 0);
    System.arraycopy(chis, 0, tempVals, 0, nChi);

    chi1 = tempVals[0];
    chi2 = tempVals[1];
    chi3 = tempVals[2];
    chi4 = tempVals[3];
    chi5 = tempVals[4];
    chi6 = tempVals[5];
    chi7 = tempVals[6];

    this.sigmas = new double[nChi];
    if (sigmas != null) {
        System.arraycopy(sigmas, 0, this.sigmas, 0, nChi);
    } else {
        Arrays.fill(sigmas, 0);
    }

    switch (res.getResidueType()) {
    case AA:
        this.name = res.getAminoAcid3();
        this.nucleicName = null;
        break;
    case NA:
        this.name = null;
        this.nucleicName = res.getNucleicAcid3();
        break;
    case UNK:
    default:
        this.name = null;
        this.nucleicName = null;
        break;
    }

    length = nChi;
    originalState = null;
    isState = false;
}

From source file:au.org.ala.delta.io.BinaryKeyFile.java

public int writeToRecord(int recordNumber, int offset, byte[] values) {
    int numRecords = checkForOverwrite(recordNumber, offset, values.length);

    if (values.length % RECORD_LENGTH_BYTES != 0) {
        int newLength = (values.length / RECORD_LENGTH_BYTES + 1) * RECORD_LENGTH_BYTES;
        byte[] newValues = new byte[newLength];
        Arrays.fill(newValues, (byte) 0);
        System.arraycopy(values, 0, newValues, 0, values.length);
        values = newValues;//from  w  ww . j  a va  2 s  .c om
    }

    seekToRecord(recordNumber, offset);
    write(values);

    return numRecords;
}