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:de.mylifesucks.oss.ncsimulator.protocol.SerialComm.java

/**
 *
 * @param event// w w w.j  a va2  s.  co  m
 * @see http://www.mikrokopter.de/ucwiki/en/SerialProtocol
 */
public void serialEvent(SerialPortEvent event) {

    //"0x1B,0x1B,0x55,0xAA,0x00"
    byte[] pattern = new byte[] { 27, 27, 85, (byte) 170, 0 };

    switch (event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
        break;
    case SerialPortEvent.DATA_AVAILABLE:
        try {
            while (inputStream.available() > 0) {

                Arrays.fill(readBuffer, (byte) 0);
                int numBytes = inputStream.read(readBuffer);
                byte[] data = Arrays.copyOfRange(readBuffer, 0, numBytes);
                //        System.out.println(Hex.encodeHexString(readBuffer));
                //        System.out.println(Hex.encodeHexString(data));

                HandleInputData(data);
            }
        } catch (IOException ex) {
        }
        break;
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.cosmic.policy.HystereticLoadShedding.java

@Override
public final void reset() {
    Arrays.fill(fault, false);
    Arrays.fill(time, 0);
    Arrays.fill(tref, 0);
    tripped.clear();
}

From source file:com.whirlycott.cache.CacheDecorator.java

/**
 * Clears the cache.//from   ww w .j  a v  a2 s. c o m
 */
public void clear() {
    log.info(Messages.getString("CacheDecorator.clearing_cache")); //$NON-NLS-1$
    managedCache.clear();
    Arrays.fill(adaptiveResults, 0);
}

From source file:com.unister.semweb.drums.bucket.hashfunction.RangeHashFunction.java

/**
 * This method instantiates a new {@link RangeHashFunction} by the given rangeValues. The given array should contain
 * only the maximal allowed value per bucket. The minimal value will be the direct successor of the previous maximal
 * value. Remember: the array will be handled circular.
 * //w w w.  j  av  a 2 s  . co m
 * @param rangeValues
 *            the maximum keys for all buckets
 * @param filenames
 *            the filenames for all buckets
 * @param hashFunctionFilename
 *            the file name of the range hash function
 */
public RangeHashFunction(byte[][] rangeValues, String[] filenames, String hashFunctionFilename) {
    this.hashFunctionFile = hashFunctionFilename;
    this.buckets = rangeValues.length;
    this.maxRangeValues = rangeValues;
    this.filenames = filenames;
    this.keyComposition = new int[rangeValues[0].length];
    Arrays.fill(keyComposition, 1);
    sort();
}

From source file:com.google.enterprise.connector.encryptpassword.EncryptPassword.java

/**
 * Returns the password to encrypt.  If a password was not supplied on the
 * command line, prompt for it./*  ww w  . j  a va2s.  co m*/
 *
 * @param password password option supplied on command line.
 * @return String password
 */
private char[] getPassword(String password) {
    if (password != null) {
        // If password was supplied on command line, return it.
        return password.toCharArray();
    }

    // Since we will be prompting, might as well display the version.
    printVersion();

    Console console = System.console();
    if (console == null) {
        System.err.println("Error: No Console");
        return null;
    }

    while (true) {
        char[] pw1 = console.readPassword("  Type Password: ");
        if ((pw1 == null) || (pw1.length == 0)) {
            System.exit(0);
        }
        char[] pw2 = console.readPassword("Retype Password: ");
        if (Arrays.equals(pw1, pw2)) {
            System.out.println("\nThe encrypted password is:");
            Arrays.fill(pw2, '\0');
            return pw1;
        }
        System.out.println("\007\nPasswords do not match.  Please try again.\n");
    }
}

From source file:com.gc.iotools.stream.is.TeeInputStreamOutputStream.java

/**
 * <p>/*from   w w  w .j ava 2  s.c  om*/
 * Creates a <code>TeeInputStreamOutputStream</code> and saves its
 * argument, the input stream <code>source</code> and the output stream
 * <code>destination</code> for later use.
 * </p>
 * <p>
 * This constructor allow to specify multiple <code>OutputStream</code> to
 * which the data will be copied.
 * </p>
 *
 * @since 1.2.3
 * @param source
 *            The underlying <code>InputStream</code>
 * @param closeStreams
 *            if <code>true</code> the <code>destination</code> will be
 *            closed when the {@link #close()} method is invoked. If
 *            <code>false</code> the close method on the underlying
 *            streams will not be called (it must be invoked externally).
 * @param destinations
 *            Data read from <code>source</code> are also written to this
 *            <code>OutputStream</code>.
 */
public TeeInputStreamOutputStream(final InputStream source, final boolean closeStreams,
        final OutputStream... destinations) {
    super(source);
    if (destinations == null) {
        throw new IllegalArgumentException("Destinations OutputStream can't be null");
    }
    if (destinations.length == 0) {
        throw new IllegalArgumentException("At least one destination OutputStream must be specified");
    }
    for (final OutputStream destination : destinations) {
        if (destination == null) {
            throw new IllegalArgumentException("One of the outputstreams in the array is null");
        }
    }
    this.writeTime = new long[destinations.length];
    this.destinations = destinations;
    this.closeStreams = closeStreams;
    this.copyEnabled = new boolean[destinations.length];
    Arrays.fill(this.copyEnabled, true);
}

From source file:gedi.lfc.LfcAlignedReadsProcessor.java

@Override
public void beginRegion(MutableReferenceGenomicRegion<?> region, ProcessorContext context) {
    Arrays.fill(total, 0);
    Arrays.fill(buff, 0);
}

From source file:clus.statistic.ClassificationStat.java

/** Resets the SumWeight and majority class count to weight and all other
 *  class counts to zero./* ww w.ja v  a  2 s  . co  m*/
 */
public void resetToSimple(double weight) {
    m_NbExamples = 0;
    m_SumWeight = weight;
    Arrays.fill(m_SumWeights, weight);
    for (int i = 0; i < m_NbTarget; i++) {
        double[] clcts = m_ClassCounts[i];
        for (int j = 0; j < clcts.length; j++) {
            if (j == m_MajorityClasses[i]) {
                clcts[j] = weight;
            } else {
                clcts[j] = 0.0;
            }
        }
    }
}

From source file:kishida.cnn.layers.FullyConnect.java

@Override
public float[] backward(float[] in, float[] delta) {
    Arrays.fill(newDelta, 0);
    Arrays.fill(diffed, 0);//from ww  w  .ja v  a  2 s. co m
    for (int i = 0; i < result.length; ++i) {
        diffed[i] = activation.diff(result[i]);
    }
    IntStream.range(0, in.length).parallel().forEach((i) -> {
        for (int j = 0; j < outputSize; ++j) {
            if (dropout[j] != 1) {
                continue;
            }
            float d = diffed[j] * delta[j];
            newDelta[i] += d * weight[i * outputSize + j];//in[i] *;
            weightDelta[i * outputSize + j] += d * in[i] * parent.getLearningRate();
        }
    });
    IntStream.range(0, outputSize).parallel().filter(j -> dropout[j] == 1).forEach(j -> {
        biasDelta[j] += diffed[j] * delta[j] * parent.getLearningRate();
    });
    return newDelta;
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Bilinear.java

public Bilinear(Complex[] sZero, Complex[] sPole, double sGain, double T) {

    Complex _2 = new Complex(2);

    if (sZero.length > sPole.length || sPole.length == 0) {
        //    error("bilinear: must have at least as many poles as zeros in s-plane");
    }//from   w  ww.ja v  a  2  s . co m

    Complex[] bz = new Complex[sZero.length];
    for (int i = 0; i < sZero.length; i++) {
        bz[i] = _2.subtract(sZero[i].multiply(T)).divide(T);
    }
    Complex[] bp = new Complex[sPole.length];
    for (int i = 0; i < sPole.length; i++) {
        bp[i] = _2.subtract(sPole[i].multiply(T)).divide(T);
    }

    zGain = new Complex(sGain, 0).multiply(prod(bz).divide(prod(bp))).getReal();
    zPole = new Complex[sPole.length];
    for (int i = 0; i < sPole.length; i++) {
        zPole[i] = _2.add(sPole[i].multiply(T)).divide(_2.subtract(sPole[i].multiply(T)));
    }
    zZero = new Complex[sPole.length];
    if (sZero.length == 0) {
        Arrays.fill(zZero, Complex.ONE.negate());
    } else {
    }
    for (int i = 0; i < sZero.length; i++) {
        zZero[i] = _2.add(sZero[i].multiply(T)).divide(_2.subtract(sZero[i].multiply(T)));
    }
    if (sZero.length < zZero.length) {
        Arrays.fill(zZero, sZero.length, zZero.length, Complex.ONE.negate());
    }
}