Example usage for org.apache.commons.lang3 ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(final Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

This method returns null for a null input array.

Usage

From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java

/**
 * Converts a list of BigDecimals to an array of doubles.
 * @param    List<BigDecimal>    list of BigDecimals
 * @return                       array of doubles
 */// www  . j a v a2 s. c o m
public static double[] toDoubleArray(List<BigDecimal> list) {
    for (BigDecimal val : list) {
        if (!OverFlowUtil.doubleOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Double[list.size()]));

}

From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java

/**
 * Converts a list of BigIntegers to an array of doubles.
 * @param    List<BigInteger>    list of BigIntegers
 * @return                       array of doubles
 *//*from   w  w w. ja  va2  s  . com*/
public static double[] toDoubleArray(List<BigInteger> list) {

    for (BigInteger val : list) {
        if (!OverFlowUtil.doubleOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Double[list.size()]));

}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Converts a list of integers to an array of doubles.
 * @param    List<Integer>    list of integers
 * @return                    array of doubles
 *//*from   w  ww  .j a v  a2  s . co  m*/
public static double[] toDoubleArray(List<Integer> list) {
    return ArrayUtils.toPrimitive(list.toArray(new Double[list.size()]));

}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Converts a list of doubles to an array of doubles.
 * @param    List<Double>    list of doubles
 * @return                   array of doubles
 *//*from w ww . j a v a 2  s  .c o m*/
public static double[] toDoubleArray(List<Double> list) {
    return ArrayUtils.toPrimitive(list.toArray(new Double[list.size()]));

}

From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java

public void IntegerArrayTest(String fieldName, Field testField) {
    try {//from w  w w.j a  v  a2  s  .  c  o  m
        int[] testFieldValue = ArrayUtils.toPrimitive((Integer[]) testField.get(getConfigBase()));
        Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getIntArray(fieldName), testFieldValue));
    } catch (IllegalAccessException e) {
        assertFailFieldError(fieldName);
    }
}

From source file:com.github.drbookings.ui.controller.MainController.java

private int[] getIndicies(final Predicate<LocalDate> p) {
    final List<Integer> result = new ArrayList<>();
    for (int index = 0; index < tableView.getItems().size(); index++) {
        final LocalDate date = tableView.getItems().get(index).getDate();
        if (p.test(date)) {
            result.add(index);//  w ww . j ava  2  s  .c om
        }
    }
    if (result.isEmpty()) {
        return new int[0];
    }
    return ArrayUtils.toPrimitive(result.toArray(new Integer[] { result.size() }));

}

From source file:ijfx.core.overlay.OverlayStatService.java

public <T extends RealType<T>> OverlayStatistics getStatistics(Overlay overlay, Dataset dataset,
        long[] position) {

    position = DimensionUtils.makeItRight(dataset, position);

    PixelStatistics pixelStats = new PixelStatisticsBase(
            new DescriptiveStatistics(ArrayUtils.toPrimitive(getValueList(dataset, overlay, position))));
    OverlayShapeStatistics shapeState = getShapeStatistics(overlay);

    return new OverlayStatisticsBase(overlay, shapeState, pixelStats);
}

From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java

public void IntegerArrayListTest(String fieldName, Field testField) {
    try {//w  w  w . jav a2 s. co m
        //noinspection unchecked,unchecked
        int[] testFieldValue = ArrayUtils.toPrimitive(((ArrayList<Integer>) testField.get(getConfigBase()))
                .toArray(new Integer[((ArrayList<Integer>) testField.get(getConfigBase())).size()]));
        Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getIntArray(fieldName), testFieldValue));
    } catch (IllegalAccessException e) {
        assertFailFieldError(fieldName);
    }
}

From source file:lockstep.LockstepServer.java

/**
 * Implements the handshake protocol server side, setting up the UDP 
 * connection, queues and threads for a specific client.
 * To be run in parallel threads, one for each client, as they need
 * to synchronize to correctly setup the lockstep protocol.
 * It signals success through a latch or failure through interruption to the
 * server thread./*from  www  .  j  av  a  2s. c om*/
 * 
 * @param tcpSocket Connection with the client, to be used in handshake only
 * @param firstFrameNumber Frame number to initialize the lockstep protocol
 * @param barrier Used for synchronization with concurrent handshake sessions
 * @param latch Used to signal the successful completion of the handshake session.
 * @param server Used to signal failure of the handshake sessions, via interruption.
 */
private void serverHandshakeProtocol(Socket tcpSocket, int firstFrameNumber, CyclicBarrier barrier,
        CountDownLatch latch, LockstepServer server) {
    try (ObjectOutputStream oout = new ObjectOutputStream(tcpSocket.getOutputStream());) {
        oout.flush();
        try (ObjectInputStream oin = new ObjectInputStream(tcpSocket.getInputStream());) {
            //Receive hello message from client and reply
            LOG.info("Waiting an hello from " + tcpSocket.getInetAddress().getHostAddress());
            oout.flush();
            ClientHello hello = (ClientHello) oin.readObject();
            LOG.info("Received an hello from " + tcpSocket.getInetAddress().getHostAddress());
            DatagramSocket udpSocket = new DatagramSocket();
            openSockets.add(udpSocket);
            InetSocketAddress clientUDPAddress = new InetSocketAddress(
                    tcpSocket.getInetAddress().getHostAddress(), hello.clientUDPPort);
            udpSocket.connect(clientUDPAddress);

            int assignedClientID;
            do {
                assignedClientID = (new Random()).nextInt(100000) + 10000;
            } while (!this.clientIDs.add(assignedClientID));

            LOG.info("Assigned hostID " + assignedClientID + " to "
                    + tcpSocket.getInetAddress().getHostAddress() + ", sending helloReply");
            ServerHelloReply helloReply = new ServerHelloReply(udpSocket.getLocalPort(), assignedClientID,
                    clientsNumber, firstFrameNumber);
            oout.writeObject(helloReply);

            ConcurrentHashMap<Integer, TransmissionQueue> clientTransmissionFrameQueues = new ConcurrentHashMap<>();
            this.transmissionFrameQueueTree.put(assignedClientID, clientTransmissionFrameQueues);

            ACKSet clientAckQueue = new ACKSet();
            ackQueues.put(assignedClientID, clientAckQueue);

            clientReceiveSetup(assignedClientID, udpSocket, firstFrameNumber, clientTransmissionFrameQueues);

            barrier.await();

            //Send second reply
            ClientsAnnouncement announcement = new ClientsAnnouncement();
            announcement.clientIDs = ArrayUtils.toPrimitive(this.clientIDs.toArray(new Integer[0]));
            oout.writeObject(announcement);

            clientTransmissionSetup(assignedClientID, firstFrameNumber, udpSocket,
                    clientTransmissionFrameQueues);

            //Wait for other handshakes to reach final step
            barrier.await();
            oout.writeObject(new SimulationStart());

            //Continue with execution
            latch.countDown();
        }
    } catch (IOException | ClassNotFoundException ioEx) {
        LOG.fatal("Exception at handshake with client");
        LOG.fatal(ioEx);
        server.interrupt();
    } catch (InterruptedException | BrokenBarrierException inEx) {
        //Interruptions come from failure in parallel handshake sessions, and signal termination
    }
}

From source file:com.ebay.cloud.cms.service.resources.impl.QueryResource.java

private static int[] extractIntArray(String paramVal, int defaultValue) {
    List<Integer> intLists = null;
    if (paramVal.trim().startsWith("[")) {
        try {//from  ww  w  . ja v  a2s .c o  m
            JsonNode node = ObjectConverter.mapper.readTree(paramVal);
            intLists = new ArrayList<Integer>(10);
            if (node.isInt()) {
                intLists.add(node.getIntValue());
            } else if (node.isArray()) {
                for (JsonNode skipNode : node) {
                    intLists.add(skipNode.isInt() ? skipNode.getIntValue() : defaultValue);
                }
            }
        } catch (Exception e) {
            logger.info("read skip array as json node failed, will try to split by , !", e);
        }
    }
    int[] skips = null;
    if (intLists == null) {
        String[] intStringValues = org.apache.commons.lang3.StringUtils.splitPreserveAllTokens(paramVal, ",");
        skips = new int[intStringValues.length];
        for (int i = 0; i < intStringValues.length; i++) {
            skips[i] = NumberUtils.toInt(intStringValues[i].trim(), defaultValue);
        }
    } else {
        skips = ArrayUtils.toPrimitive(intLists.toArray(new Integer[] { 0 }));
    }
    return skips;
}