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:com.opensource.dbhelp.dbutils.CamelBeanProcessor.java

/**
 * /* w w w .j  a  v a 2s .c  o m*/
 *
 * @param rsmd
 *            
 * @param props
 *            
 * @return ??
 */
@Override
protected int[] mapColumnsToProperties(ResultSetMetaData rsmd, PropertyDescriptor[] props) throws SQLException {

    int cols = rsmd.getColumnCount();
    int columnToProperty[] = new int[cols + 1];
    Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

    for (int col = 1; col <= cols; col++) {
        String columnName = rsmd.getColumnLabel(col);
        if (null == columnName || 0 == columnName.length()) {
            columnName = rsmd.getColumnName(col);
        }

        for (int i = 0; i < props.length; i++) {
            if (formatColName(columnName).equalsIgnoreCase(props[i].getName())) {
                columnToProperty[col] = i;
                break;
            }
            if (columnName.equalsIgnoreCase(props[i].getName())) {
                columnToProperty[col] = i;
                break;
            }
        }
    }

    return columnToProperty;
}

From source file:com.intel.cosbench.exporter.CSVStageExporter.java

protected void writeHeader(Writer writer) throws IOException {
    StringBuilder buffer = new StringBuilder();
    buffer.append("Timestamp").append(',');
    char[] cs = new char[numOpTypes];
    Arrays.fill(cs, ',');
    String suffix = new String(cs);
    buffer.append("Op-Count").append(suffix);
    buffer.append("Byte-Count").append(suffix);
    buffer.append("Avg-ResTime").append(suffix);
    buffer.append("Avg-ProcTime").append(suffix);
    buffer.append("Throughput").append(suffix);
    buffer.append("Bandwidth").append(suffix);
    buffer.append("Succ-Ratio").append(suffix);
    buffer.append("Version-Info");
    buffer.append(',').append(',').append('\n').append(',');
    for (int i = 0; i < 7; i++)
        // 7 metrics
        for (Metrics metrics : snapshots[0].getReport())
            buffer.append(StringUtils.join(new Object[] {
                    (metrics.getOpName().equals(metrics.getSampleType()) ? null : metrics.getOpName() + "-"),
                    metrics.getSampleType() })).append(',');
    buffer.append("Min-Version").append(',');
    buffer.append("Version").append(',');
    buffer.append("Max-Version").append('\n');
    writer.write(buffer.toString());//  w w w . j a v a2s .  c  o m
}

From source file:Main.java

private static SecretKeySpec getKey(String password) throws UnsupportedEncodingException {

    // You can change it to 128 if you wish
    int keyLength = 256;
    byte[] keyBytes = new byte[keyLength / 8];
    // explicitly fill with zeros
    Arrays.fill(keyBytes, (byte) 0x0);

    // if password is shorter then key length, it will be zero-padded
    // to key length
    byte[] passwordBytes = password.getBytes("UTF-8");
    int length = passwordBytes.length < keyBytes.length ? passwordBytes.length : keyBytes.length;
    System.arraycopy(passwordBytes, 0, keyBytes, 0, length);
    SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
    return key;/*from  www .j  a va  2  s  . c om*/
}

From source file:ArrayHelper.java

public static int[] fillArray(int value, int length) {
    int[] result = new int[length];
    Arrays.fill(result, value);
    return result;
}

From source file:net.sf.dsp4j.octave_3_2_4.m.polynomial.Poly.java

public static Complex[] poly(Complex[] x) {

    Complex[] y;/*ww  w.  jav a2 s .c  o m*/

    if (x.length == 0) {
        return new Complex[] { Complex.ONE };
    }

    y = new Complex[x.length + 1];
    Arrays.fill(y, Complex.ZERO);
    y[0] = Complex.ONE;
    for (int j = 1; j < y.length; j++) {
        for (int i = j; i >= 1; i--) {
            y[i] = y[i].subtract(x[j - 1].multiply(y[i - 1]));
        }
    }

    return y;
}

From source file:com.milaboratory.core.io.sequence.fasta.FastaWriterTest.java

private static SingleRead randomRead(long id) {
    Well1024a random = new Well1024a(id);
    Bit2Array seq = new Bit2Array(50 + random.nextInt(150));
    for (int i = 0; i < seq.size(); ++i)
        seq.set(i, (byte) random.nextInt(NucleotideSequence.ALPHABET.size()));
    byte[] quality = new byte[seq.size()];
    Arrays.fill(quality, SequenceQuality.GOOD_QUALITY_VALUE);
    return new SingleReadImpl(id,
            new NSequenceWithQuality(new NucleotideSequence(seq), new SequenceQuality(quality)), "id" + id);
}

From source file:com.opengamma.analytics.math.matrix.DoubleMatrix1D.java

/**
 * Create an vector of length n with all entries equal to value
 * @param n number of elements//from   w  ww .j a  va2s .  co m
 * @param value value of elements
 */
public DoubleMatrix1D(final int n, double value) {
    _elements = n;
    _data = new double[_elements];
    Arrays.fill(_data, value);
}

From source file:io.milton.common.RangeUtilsTest.java

public void xtestSendBytes_Under1k() throws Exception {
    long length = 500;
    byte[] buf = new byte[1000];
    Arrays.fill(buf, (byte) 3);
    ByteArrayInputStream in = new ByteArrayInputStream(buf);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    RangeUtils.sendBytes(in, out, length);

    assertEquals(500, out.toByteArray().length);

}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiClusterSilhouetteScore.java

@Override
public double score(double[][][] samples) {

    ManhattanDistance distance = new ManhattanDistance();
    double score = 0.0;
    int m = 0, i, j, k;

    for (i = 0; i < samples.length; i++)
        m += samples[i].length;//from w  w  w. j  av a2s.  co  m

    byte[] clusterAssignment = new byte[m];
    double[][] values = new double[m][];

    double[][] distances = new double[m - 1][];
    for (i = 0; i < m - 1; i++)
        distances[i] = new double[m - i - 1];

    int mIndex = 0;

    for (byte label = 0; label < samples.length; label++)
        for (i = 0; i < samples[label].length; i++) {
            values[mIndex] = samples[label][i];
            clusterAssignment[mIndex] = label;
            for (j = 0; j < mIndex; j++)
                distances[mIndex - j - 1][j] = distance.compute(values[mIndex], values[mIndex - j - 1]);
            mIndex++;
        }

    double dissimilarity[] = new double[samples.length];
    double a, b;
    for (i = 0; i < m; i++) {
        Arrays.fill(dissimilarity, 0.0);
        for (j = 0; j < m; j++)
            if (i != j) {
                k = Math.min(i, j);
                dissimilarity[clusterAssignment[j]] += distances[k][Math.max(i, j) - 1 - k];
            }

        a = dissimilarity[clusterAssignment[i]] / (samples[clusterAssignment[i]].length - 1);
        b = Double.MAX_VALUE;
        for (j = 0; j < dissimilarity.length; j++)
            if (clusterAssignment[i] != j)
                b = Math.min(b, dissimilarity[j] / samples[j].length);

        score += Math.max(a, b) == 0.0 ? -1.0 : (b - a) / Math.max(a, b);

    }

    return score / m;

}

From source file:net.jetrix.filter.TetrisFilter.java

public void onMessage(StartGameMessage m, List<Message> out) {
    Arrays.fill(tetrisCount, 0);

    GmsgMessage message = new GmsgMessage();
    message.setKey("filter.tetris.start_message", tetrisLimit);

    out.add(m);/*from  w w w .  j  a  v a2  s  .co  m*/
    out.add(message);
}