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:CircularQueue.java

@Override
public void clear() {
    if (!isEmpty()) {
        Arrays.fill(this.items, null);
        this.first = 0;
        this.last = 0;
        this.full = false;
        shrinkIfNeeded();// w w w  . j a v a  2 s.co m
    }
}

From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java

@Test
public void testWriteObject2() throws Exception {
    MockTestObject1 object = new MockTestObject1();
    object.coolTest = true;//  www.  j  a va 2  s .co m
    Arrays.fill(object.myArray, (byte) 12);

    byte[] data = this.serializer.writeObject(object);

    assertNotNull("The array should not be null.", data);
    assertTrue("The array shoudl not be empty.", data.length > 0);

    ByteArrayInputStream bytes = new ByteArrayInputStream(data);
    ObjectInputStream stream = new ObjectInputStream(bytes);

    Object input = stream.readObject();

    assertNotNull("The object should not be null.", input);
    assertEquals("The object is not the right kind of object.", MockTestObject1.class, input.getClass());

    MockTestObject1 actual = (MockTestObject1) input;
    assertFalse("The objects should not be the same object.", actual == object);
    assertEquals("The object is not correct.", object, actual);
}

From source file:br.unicamp.ic.recod.gpsi.applications.gpsiTimeSeriesCreator.java

@Override
public void run() throws Exception {
    String datasetsPath = Paths.get(super.datasetPath).getParent().getParent().toString();
    System.out.println(datasetsPath);

    HashMap<Byte, double[][]> indicesMap = new HashMap<>();
    ArrayList<double[]> entities;
    double[][] series;

    int daysCount = 0, i, dayIndex;

    gpsiRawDataset rawDataset;//w  w  w  .  j  av a2 s.c  o m
    gpsiMLDataset dataset;

    VectorialMean vmean;
    Mean mean = new Mean();

    File[] days, years = new File(datasetsPath).listFiles(File::isDirectory);
    Arrays.sort(years);

    for (File year : years)
        daysCount += 365 + (Integer.parseInt(year.getName()) % 4 == 0 ? 1 : 0);

    for (Byte label : classLabels) {
        series = new double[daysCount][descriptors.length];
        for (double[] row : series)
            Arrays.fill(row, Double.NaN);
        indicesMap.put(label, series);
    }

    daysCount = 0;
    for (File year : years) {
        days = new File(year.getAbsolutePath()).listFiles(File::isDirectory);
        Arrays.sort(days);
        for (File day : days) {
            dayIndex = daysCount + Integer.parseInt(day.getName()) - 1;
            rawDataset = datasetReader.readDataset(day.getAbsolutePath() + "/", null, 0.0);
            rawDataset.assignFolds(new byte[] { 0 }, null, null);
            for (i = 0; i < descriptors.length; i++) {
                dataset = new gpsiMLDataset(descriptors[i]);
                dataset.loadTrainingSet(rawDataset.getTrainingEntities(), true);
                for (Byte label : classLabels) {

                    if (!dataset.getTrainingEntities().containsKey(label)) {
                        indicesMap.get(label)[dayIndex][i] = Double.NaN;
                        continue;
                    }
                    vmean = new VectorialMean(dataset.getDimensionality());
                    entities = (ArrayList<double[]>) dataset.getTrainingEntities().get(label);
                    for (double[] v : entities)
                        vmean.increment(v);
                    indicesMap.get(label)[dayIndex][i] = mean.evaluate(vmean.getResult());
                }
            }
        }
        daysCount += 365 + (Integer.parseInt(year.getName()) % 4 == 0 ? 1 : 0);
    }

    for (Byte label : classLabels)
        stream.register(new gpsiDoubleCsvIOElement(indicesMap.get(label), names, "series/" + label + ".csv"));

}

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

/**
 * Writes the supplied array of ints to the record identified by
 * <code>recordNumber</code>. If the number of values is larger than will
 * fit into a single record (>128) the write will continue into the next
 * record./*  ww w .j  a  v a2s. com*/
 * 
 * @param recordNumber
 *            the record number to write to.
 * @param values
 *            the data to write to the record.
 * @return the number of records written.
 */
public int writeToRecord(int recordNumber, int[] values) {
    checkForOverwrite(recordNumber, 0, values.length * SIZE_INT_IN_BYTES);

    // Zero pad the values out to fill a full record.
    if (values.length % RECORD_LENGTH_INTEGERS != 0) {
        int newLength = (values.length / RECORD_LENGTH_INTEGERS + 1) * RECORD_LENGTH_INTEGERS;
        int[] newValues = new int[newLength];
        Arrays.fill(newValues, 0);
        System.arraycopy(values, 0, newValues, 0, values.length);
        values = newValues;
    }

    seekToRecord(recordNumber);
    writeInts(values);

    return values.length / RECORD_LENGTH_INTEGERS;
}

From source file:com.linkedin.pinot.core.index.writer.impl.FixedBitWidthRowColDataFileWriter.java

private void init(File file, int rows, int cols, int[] columnSizesInBits) {
    boolean[] hasNegativeValues = new boolean[cols];
    Arrays.fill(hasNegativeValues, false);
    init(file, rows, cols, columnSizesInBits, hasNegativeValues);
}

From source file:com.joptimizer.util.CholeskyFactorization.java

public double[][] getInverse() {

    //QInv = LTInv * LInv, but for symmetry (QInv=QInvT)
    //QInv = LInvT * LTInvT = LInvT * LInv, so
    //LInvT = LTInv, and we calculate
    //QInv = LInvT * LInv

    double[][] lTData = getLT();
    int dim = lTData.length;

    // LTInv calculation (it will be x)
    double[] diag = new double[dim];
    Arrays.fill(diag, 1.);
    double[][] x = MatrixUtils.createRealDiagonalMatrix(diag).getData();
    for (int j = 0; j < dim; j++) {
        final double[] lTJ = lTData[j];
        final double lTJJ = lTJ[j];
        final double[] xJ = x[j];
        for (int k = 0; k < dim; ++k) {
            xJ[k] /= lTJJ;//from w  ww  . ja  v a2 s  . c  om
        }
        for (int i = j + 1; i < dim; i++) {
            final double[] xI = x[i];
            final double lTJI = lTJ[i];
            for (int k = 0; k < dim; ++k) {
                xI[k] -= xJ[k] * lTJI;
            }
        }
    }

    // transposition (L is upper-triangular)
    double[][] LInvTData = new double[dim][dim];
    for (int i = 0; i < dim; i++) {
        double[] LInvTDatai = LInvTData[i];
        for (int j = i; j < dim; j++) {
            LInvTDatai[j] = x[j][i];
        }
    }

    // QInv
    // NB: LInvT is upper-triangular, so LInvT[i][j]=0 if i>j
    final double[][] QInvData = new double[dim][dim];
    for (int row = 0; row < dim; row++) {
        final double[] LInvTDataRow = LInvTData[row];
        final double[] QInvDataRow = QInvData[row];
        for (int col = row; col < dim; col++) {// symmetry of QInv
            final double[] LInvTDataCol = LInvTData[col];
            double sum = 0;
            for (int i = col; i < dim; i++) {// upper triangular
                sum += LInvTDataRow[i] * LInvTDataCol[i];
            }
            QInvDataRow[col] = sum;
            QInvData[col][row] = sum;// symmetry of QInv
        }
    }

    return QInvData;
}

From source file:CipherSocket.java

public OutputStream getOutputStream() throws IOException {
    OutputStream os = delegate == null ? super.getOutputStream() : delegate.getOutputStream();
    Cipher cipher = null;//ww w .jav a  2s  .com
    try {
        cipher = Cipher.getInstance(algorithm);
        int size = cipher.getBlockSize();
        byte[] tmp = new byte[size];
        Arrays.fill(tmp, (byte) 15);
        IvParameterSpec iv = new IvParameterSpec(tmp);
        cipher.init(Cipher.ENCRYPT_MODE, key, iv);
    } catch (Exception e) {
        throw new IOException("Failed to init cipher: " + e.getMessage());
    }
    CipherOutputStream cos = new CipherOutputStream(os, cipher);
    return cos;
}

From source file:roaded.MainGUI.java

/**
 * Creates new form MainGUI/*from   w ww  . j a  va2 s .  c o  m*/
 */
public MainGUI() {
    initComponents();
    Arrays.fill(wardsSelected, Boolean.FALSE);
    if (firstMapDataVisit) {
        infoBox("Welcome to RoadEd!" + "\nYour helper to visualize Edmonton's311 Report Data."
                + "\nPlease choose JSON DATA or CSV DATA."
                + "\nJSON DATA will load the last 1000 entries submitted."
                + "\nCSV DATA Will load all entries since data inception in the OpenData Portal.", "Message");
        firstDataLoadVisit = false;
    }
    this.jProgressBar2.setForeground(Color.red); // set red initially
}

From source file:org.terracotta.offheapstore.paging.TableStealingFromStorageIT.java

@Test
public void testStealingFromOwnStorage() {
    PageSource source = new UpfrontAllocatingPageSource(new HeapBufferSource(), MEGABYTES.toBytes(1),
            MEGABYTES.toBytes(1));/*  ww  w .  j ava2  s .  c om*/

    OffHeapHashMap<Integer, byte[]> selfStealer = new WriteLockedOffHeapClockCache<>(source, true,
            new SplitStorageEngine<>(new IntegerStorageEngine(), new OffHeapBufferHalfStorageEngine<>(source,
                    KILOBYTES.toBytes(16), ByteArrayPortability.INSTANCE, false, true)));

    long seed = System.nanoTime();
    System.err.println("Random Seed = " + seed);
    Random rndm = new Random(seed);

    int terminalKey = 0;
    for (int key = 0; true; key++) {
        int size = selfStealer.size();
        byte[] payload = new byte[rndm.nextInt(KILOBYTES.toBytes(1))];
        Arrays.fill(payload, (byte) key);
        selfStealer.put(key, payload);
        if (size >= selfStealer.size()) {
            terminalKey = key;
            break;
        }
    }

    System.err.println("Terminal Key = " + terminalKey);

    for (int key = terminalKey + 1; key < 10 * terminalKey; key++) {
        byte[] payload = new byte[rndm.nextInt(KILOBYTES.toBytes(1))];
        Arrays.fill(payload, (byte) key);
        selfStealer.put(key, payload);
        selfStealer.remove(rndm.nextInt(key));
    }

    long measuredSize = 0;
    for (Entry<Integer, byte[]> e : selfStealer.entrySet()) {
        int key = e.getKey();
        byte[] payload = e.getValue();
        for (byte b : payload) {
            assertThat(b, is((byte) key));
        }
        assertThat(selfStealer, hasKey(e.getKey()));
        measuredSize++;
    }
    assertThat(selfStealer.size(), is((int) measuredSize));
    assertThat(selfStealer.getUsedSlotCount(), is(measuredSize));
}

From source file:mase.mason.generic.systematic.SystematicEvaluator.java

@Override
public void setup(EvolutionState state, Parameter base) {
    super.setup(state, base);
    Parameter df = defaultBase();
    this.timeMode = TimeMode.valueOf(state.parameters.getString(base.push(P_TIME_MODE), df.push(P_TIME_MODE)));
    if (timeMode == TimeMode.frames) {
        this.timeFrames = state.parameters.getInt(base.push(P_TIME_FRAMES), df.push(P_TIME_FRAMES));
    }/* ww  w.ja  va 2s  .com*/
    this.numAlive = state.parameters.getBoolean(base.push(P_NUM_ALIVE), df.push(P_NUM_ALIVE), false);
    this.stateMean = state.parameters.getBoolean(base.push(P_STATE_MEAN), df.push(P_STATE_MEAN), false);
    this.stateDeviation = state.parameters.getBoolean(base.push(P_STATE_DEVIATION), df.push(P_STATE_DEVIATION),
            false);
    this.physicalRelations = state.parameters.getBoolean(base.push(P_PHYSICAL_RELATIONS),
            df.push(P_PHYSICAL_RELATIONS), false);

    String s = state.parameters.getStringWithDefault(base.push(P_IGNORE_GROUPS), df.push(P_IGNORE_GROUPS), "");
    this.evaluateGroup = new boolean[100];
    Arrays.fill(evaluateGroup, true);
    for (String sp : s.split(",")) {
        try {
            int index = Integer.parseInt(sp.trim());
            evaluateGroup[index] = false;
            state.output.message("Ignoring group " + index);
        } catch (Exception ex) {
        }
    }
}