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.laxser.blitz.web.impl.mapping.EngineGroupImpl.java

/**
 * @param simpleName ????/*from  w w  w  .  j  av a  2s .c  om*/
 */
public EngineGroupImpl() {
    LinkedEngine[][] engines = new LinkedEngine[ARRAY_SIZE][];
    Arrays.fill(engines, emptyEngines);
    this.engines = engines;
}

From source file:com.joptimizer.optimizers.PrimalDualMethodHeavyTest.java

/**
 * Quadratic objective with linear eq and ineq.
 *///from   w  w  w  .  j  a va2 s .c om
public void testOptimize() throws Exception {
    log.debug("testOptimize");

    // Objective function
    DoubleMatrix2D P = Utils.randomValuesPositiveMatrix(dim, dim, -0.5, 0.5, seed);
    DoubleMatrix1D q = Utils.randomValuesMatrix(1, dim, -0.5, 0.5, seed).viewRow(0);

    PDQuadraticMultivariateRealFunction objectiveFunction = new PDQuadraticMultivariateRealFunction(P.toArray(),
            q.toArray(), 0);

    // equalities
    double[][] AEMatrix = new double[1][dim];
    Arrays.fill(AEMatrix[0], 1.);
    double[] BEVector = new double[] { 1 };

    // inequalities
    double[][] AIMatrix = new double[dim][dim];
    for (int i = 0; i < dim; i++) {
        AIMatrix[i][i] = -1;
    }
    ConvexMultivariateRealFunction[] inequalities = new ConvexMultivariateRealFunction[dim];
    for (int i = 0; i < dim; i++) {
        inequalities[i] = new LinearMultivariateRealFunction(AIMatrix[i], 0);
    }

    OptimizationRequest or = new OptimizationRequest();
    or.setF0(objectiveFunction);
    double[] ip = new double[dim];
    Arrays.fill(ip, 1. / dim);
    or.setInitialPoint(ip);
    or.setA(AEMatrix);
    or.setB(BEVector);
    or.setFi(inequalities);

    // optimization
    PrimalDualMethod opt = new PrimalDualMethod();
    opt.setOptimizationRequest(or);
    int returnCode = opt.optimize();

    if (returnCode == OptimizationResponse.FAILED) {
        fail();
    }

    OptimizationResponse response = opt.getOptimizationResponse();
    double[] sol = response.getSolution();
    double value = objectiveFunction.value(sol);
    log.debug("sol   : " + ArrayUtils.toString(sol));
    log.debug("value : " + value);
}

From source file:Main.java

public static byte[] padLeft(byte[] tgt, int len, byte padding) {
    if (tgt.length >= len) {
        return tgt;
    }/*from   w  ww.j a  va 2 s. c  o  m*/
    ByteBuffer buffer = ByteBuffer.allocate(len);
    byte[] paddings = new byte[len - tgt.length];
    Arrays.fill(paddings, padding);

    buffer.put(paddings);
    buffer.put(tgt);

    return buffer.array();
}

From source file:net.arp7.HdfsPerfTest.WriteFile.java

private static void writeFiles(final Configuration conf, final FileIoStats stats)
        throws InterruptedException, IOException {
    final FileSystem fs = FileSystem.get(conf);
    final AtomicLong filesLeft = new AtomicLong(params.getNumFiles());
    final long runId = abs(rand.nextLong());
    final byte[] data = new byte[params.getIoSize()];
    Arrays.fill(data, (byte) 65);

    // Start the writers.
    final ExecutorService executor = Executors.newFixedThreadPool((int) params.getNumThreads());
    final CompletionService<Object> ecs = new ExecutorCompletionService<>(executor);
    LOG.info("NumFiles=" + params.getNumFiles() + ", FileSize="
            + FileUtils.byteCountToDisplaySize(params.getFileSize()) + ", IoSize="
            + FileUtils.byteCountToDisplaySize(params.getIoSize()) + ", BlockSize="
            + FileUtils.byteCountToDisplaySize(params.getBlockSize()) + ", ReplicationFactor="
            + params.getReplication() + ", isThrottled=" + (params.maxWriteBps() > 0));
    LOG.info("Starting " + params.getNumThreads() + " writer thread" + (params.getNumThreads() > 1 ? "s" : "")
            + ".");
    final long startTime = System.nanoTime();
    for (long t = 0; t < params.getNumThreads(); ++t) {
        final long threadIndex = t;
        Callable<Object> c = new Callable<Object>() {
            @Override//  w  w  w.j  a v  a2 s .  co  m
            public Object call() throws Exception {
                long fileIndex = 0;
                while (filesLeft.addAndGet(-1) >= 0) {
                    final String fileName = "WriteFile-" + runId + "-" + (threadIndex + 1) + "-"
                            + (++fileIndex);
                    writeOneFile(new Path(params.getOutputDir(), fileName), fs, data, stats);
                }
                return null;
            }
        };
        ecs.submit(c);
    }

    // And wait for all writers to complete.
    for (long t = 0; t < params.getNumThreads(); ++t) {
        ecs.take();
    }
    final long endTime = System.nanoTime();
    stats.setElapsedTime(endTime - startTime);
    executor.shutdown();
}

From source file:CipherSocket.java

public InputStream getInputStream() throws IOException {
    InputStream is = delegate == null ? super.getInputStream() : delegate.getInputStream();
    Cipher cipher = null;// w w  w  .  j  a v  a2  s  .  c om
    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.DECRYPT_MODE, key, iv);
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Failed to init cipher: " + e.getMessage());
    }
    CipherInputStream cis = new CipherInputStream(is, cipher);
    return cis;
}

From source file:com.l2jfree.gameserver.instancemanager.ZoneManager.java

public void reload() {
    // Get the world regions
    L2WorldRegion[][] worldRegions = L2World.getInstance().getAllWorldRegions();
    for (L2WorldRegion[] finalWorldRegion : worldRegions) {
        for (L2WorldRegion finalElement : finalWorldRegion) {
            finalElement.clearZones();//from ww w. j  a  v a 2s.  c o  m
        }
    }
    // Remove registered siege danger zones
    for (Castle c : CastleManager.getInstance().getCastles().values())
        c.getSiege().onZoneReload();

    Arrays.fill(_zones, null);

    // Remove registered unique zones
    _uniqueZones.clear();

    // Load the zones
    load();
}

From source file:io.alicorn.server.http.LoginEndpoint.java

public static String hash(char[] chars) {
    //Parse chars into bytes for hashing.
    CharBuffer charBuffer = CharBuffer.wrap(chars);
    ByteBuffer byteBuffer = charset.encode(charBuffer);
    byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit());

    //Clear temporary arrays of any data.
    Arrays.fill(charBuffer.array(), '\u0000');
    Arrays.fill(byteBuffer.array(), (byte) 0);

    //Generate the SHA-256 hash.
    String hash = hash(bytes);/*from   w ww . java2 s  . c  om*/

    //Clear remaining arrays of any data.
    Arrays.fill(bytes, (byte) 0);

    return hash;
}

From source file:com.gc.iotools.stream.writer.TeeWriter.java

/**
 * <p>/*w ww.ja  v a 2  s . c o m*/
 * Creates a <code>TeeWriter</code> and saves its arguments, the
 * <code>destinations</code> for later use.
 * </p>
 * <p>
 * This constructor allow to specify multiple <code>Writer</code> to which
 * the data will be copied.
 * </p>
 *
 * @since 1.2.4
 * @param destinations
 *            Data written to this<code>Writer</code> are copied to all
 *            the <code>destinations</code>.
 */
public TeeWriter(final Writer... destinations) {
    checkDestinations(destinations);
    this.writeTime = new long[destinations.length];
    this.destinations = destinations;
    this.copyEnabled = new boolean[destinations.length];
    Arrays.fill(this.copyEnabled, true);
}

From source file:hivemall.io.DenseModel.java

public DenseModel(int ndims, boolean withCovar) {
    super();/*from  www.j a  v a2  s  .  com*/
    int size = ndims + 1;
    this.size = size;
    this.weights = new float[size];
    if (withCovar) {
        float[] covars = new float[size];
        Arrays.fill(covars, 1f);
        this.covars = covars;
    } else {
        this.covars = null;
    }
    this.sum_of_squared_gradients = null;
    this.sum_of_squared_delta_x = null;
    this.sum_of_gradients = null;
    this.clocks = null;
    this.deltaUpdates = null;
}

From source file:com.chinamobile.bcbsp.ml.math.DenseDoubleVector.java

/**
 * Creates a new vector with the given length and default value.
 *//*  ww w .  j  a  v  a2s.  co  m*/
public DenseDoubleVector(int length, double val) {
    this(length);
    Arrays.fill(vector, val);
}