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.harvard.i2b2.crc.dao.setfinder.EncounterSetCollectionSpringDao.java

/**
 * Call this function at the end. i.e. after loading all patient with
 * addPatient function, finally call this function to clear session
 *//*from  w  w w . jav a2s  .co  m*/
public void flush() {
    InsertStatementSetter batchSetter = new InsertStatementSetter(patientEncColl, batchDataIndex);
    jdbcTemplate.batchUpdate(insert_sql, batchSetter);
    Arrays.fill(patientEncColl, null);
    batchDataIndex = 0;
    setIndex = 0;
}

From source file:egat.cli.neresponse.NEResponseCommandHandler.java

protected void findNEResponse(Strategy strategy, SymmetricGame game) {
    Player[] players = game.players().toArray(new Player[0]);
    Strategy[] strategies = new Strategy[players.length];
    Arrays.fill(strategies, strategy);

    System.out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    System.out.print("<ne-response>");
    double basePayoff = 0.0;
    if (gain) {//from w  w w. j ava2  s  .  co  m
        basePayoff = game.payoff(Games.createProfile(players, strategies)).getPayoff(players[0]).getValue();
    }
    for (Action action : game.getActions()) {
        strategies[0] = Games.createStrategy(new Action[] { action }, new Number[] { 1.0 });
        double response = game.payoff(Games.createProfile(players, strategies)).getPayoff(players[0])
                .getValue();

        if (gain) {
            System.out.print(
                    String.format("<action id=\"%s\" gain=\"%f\" />", action.getID(), response - basePayoff));
        } else {
            System.out.print(String.format("<action id=\"%s\" payoff=\"%f\" />", action.getID(), response));
        }
    }

    System.out.print("</ne-response>");
}

From source file:action.GraphAction.java

public Number[] getValues(List<CustomerOrder> orderList) {

    Number[] a = new Integer[12];
    Arrays.fill(a, 0);

    for (int i = 0; i < orderList.size(); i++) {
        Date d = orderList.get(i).getDateCreated();
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);/*from  w ww.ja va2 s . c  om*/
        int month = cal.get(Calendar.MONTH);
        System.out.println("month is" + month + " " + a[month]);
        System.out.println("value  is" + month + " " + a[month].intValue());
        a[month] = a[month].intValue() + 1;
    }

    return a;
}

From source file:com.reactivetechnologies.platform.stream.DistributedPipedOutputStream.java

@Override
public void clear() {
    Arrays.fill(circularBuffer, (byte) -1);
    position = 0;
}

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

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

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

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

From source file:msi.gama.util.matrix.GamaObjectMatrix.java

@Override
public void _clear() {
    Arrays.fill(getMatrix(), null);
}

From source file:com.cloudera.oryx.app.serving.als.model.LocalitySensitiveHashTest.java

@Test
public void testCandidateIndices() {
    int features = 10;
    LocalitySensitiveHash lsh = new LocalitySensitiveHash(0.5, features, 32);
    assertEquals(3, lsh.getMaxBitsDiffering());
    assertEquals(7, lsh.getNumHashes());

    float[] oneVec = new float[features];
    Arrays.fill(oneVec, 1.0f);
    int[] candidates = lsh.getCandidateIndices(oneVec);
    assertEquals(64, candidates.length); // 1 + 7 + 21 + 35
    for (int i = 1; i < 8; i++) {
        assertEquals(1, Integer.bitCount(candidates[0] ^ candidates[i]));
    }/*from   www  .j ava2  s.c  o m*/
    for (int i = 8; i < 29; i++) {
        assertEquals(2, Integer.bitCount(candidates[0] ^ candidates[i]));
    }
    for (int i = 29; i < 64; i++) {
        assertEquals(3, Integer.bitCount(candidates[0] ^ candidates[i]));
    }
}

From source file:com.jaeksoft.searchlib.result.collector.join.JoinDocCollector.java

@Override
final public void doSetForeignDoc(final int pos, final int joinResultPos, final int foreignDocId,
        float foreignScore) {
    int[] foreignDocIds = foreignDocIdsArray[pos];
    if (foreignDocIds == null) {
        foreignDocIds = new int[joinResultSize];
        Arrays.fill(foreignDocIds, -1);
        foreignDocIdsArray[pos] = foreignDocIds;
    }/*  w w  w.  j  ava 2  s.co m*/
    foreignDocIds[joinResultPos] = foreignDocId;
}

From source file:com.meltmedia.cadmium.cli.LoggerCommand.java

@Override
public void execute() throws Exception {
    String logger = null;//from  w w  w  . j  a  v  a  2 s  . c om
    String level = null;
    String site = null;
    if (params != null && params.size() >= 3) {
        logger = params.get(0);
        level = params.get(1);
        site = params.get(2);
    } else if (params != null && params.size() == 2) {
        String value = params.get(0);
        try {
            level = Level.toLevel(value, null).levelStr;
        } catch (Exception e) {
            logger = value;
        }
        site = params.get(1);
    } else if (params != null && params.size() == 1) {
        site = params.get(0);
    } else {
        System.err.println("A site is required!");
        System.exit(1);
    }
    HttpClient client = httpClient();
    HttpMessage method = null;
    site = this.getSecureBaseUrl(site);
    if (level != null) {
        String uri = site + "/system/logger/"
                + (StringUtils.isNotBlank(logger) ? logger + "/"
                        : ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME + "/")
                + (StringUtils.isNotBlank(level) ? level : "DEBUG");
        System.out.println("Updating logger [" + (StringUtils.isNotBlank(logger) ? logger : "ROOT")
                + "] to level [" + level + "] for site " + site);
        method = new HttpPost(uri);
    } else {
        String uri = site + "/system/logger/" + (StringUtils.isNotBlank(logger) ? logger + "/" : "");
        System.out.println("Getting levels for " + (StringUtils.isNotBlank(logger) ? logger : "all")
                + " logger[s] on site " + site);
        method = new HttpGet(uri);
    }
    addAuthHeader(method);
    HttpResponse response = client.execute((HttpUriRequest) method);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        LoggerServiceResponse configs = new Gson().fromJson(EntityUtils.toString(response.getEntity()),
                LoggerServiceResponse.class);
        List<String> nodes = new ArrayList<String>();
        nodes.addAll(configs.getConfigs().keySet());
        Collections.sort(nodes);
        List<String> loggers = new ArrayList<String>();
        Map<String, String[]> loggerLevels = new HashMap<String, String[]>();
        for (String node : nodes) {
            for (LoggerConfig config : configs.getConfigs().get(node)) {
                if (!loggers.contains(config.getName())) {
                    loggers.add(config.getName());
                    loggerLevels.put(config.getName(), new String[nodes.size()]);
                    Arrays.fill(loggerLevels.get(config.getName()), "-");
                }
                loggerLevels.get(config.getName())[nodes.indexOf(node)] = config.getLevel();
            }
        }

        Collections.sort(loggers);
        if (loggers.remove(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME)) {
            loggers.add(0, ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
        }

        System.out.println("Got " + loggers.size() + " logger[s] and " + nodes.size() + " node[s]");

        for (String loggerName : loggers) {
            System.out.println("Logger: " + loggerName);
            String levels[] = loggerLevels.get(loggerName);
            for (String node : nodes) {
                System.out.println("  " + node + ": " + levels[nodes.indexOf(node)]);
            }
        }
    } else {
        System.err.println("Request failed: " + response.getStatusLine());
        System.err.println("Raw response [" + EntityUtils.toString(response.getEntity()) + "]");
    }
}

From source file:com.github.c77.base_driver.kobuki.KobukiPacketReader.java

private final void goodPacket(int length, byte[] packet) { // Without first 2 headers, length, or checksum!
    //header/*from  w  w  w  . j a  v a  2  s  . c o m*/
    //size
    //payload

    int curPlace = 0;
    byte[] toSend = new byte[100];
    System.arraycopy(packet, 0, toSend, 0, (packet[1] + 2));
    curPlace = packet[1] + 2;
    sortParts(toSend);

    for (int i = 0; i < 6; i++) { // seven total packets six left
        Arrays.fill(toSend, (byte) 0);
        //Changed from curPlace + 1 to curPlace. Changed last field from curPlace + 2 to packet[curPlace + 1]
        System.arraycopy(packet, curPlace, toSend, 0, packet[curPlace + 1] + 2); //Curplace is current index that needs to be accessed. packet[curPlace + 1] + 2 accounts for the size of the payload AND the index + payload size bytes
        curPlace = curPlace + packet[curPlace + 1] + 2; //Essentially, the index of the element we just accessed. + the length of the payload + 2 for the index and payload size
        sortParts(toSend); //Sorts packet array into individual packets (see method)
    }
}