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:de.biomedical_imaging.traJ.features.ConfinedDiffusionParametersFeature.java

@Override
/**/*from  www  . jav a 2s.  com*/
 * @return Returns an double array with the elements [0] = squared radius (A), [1] = Diffusion coefficent (D) [2] = shape parameter 1 (B), 
 * [3] shape parameter 2 (C) and  [4] Fit goodness. If reduced model was selected then it return [0] = squared radius, [1] = diffusion coefficient, [3] = goodness
 */
public double[] evaluate() {
    MeanSquaredDisplacmentFeature msd = new MeanSquaredDisplacmentFeature(t, 1);
    msd.setOverlap(false);

    ArrayList<Double> xDataList = new ArrayList<Double>();
    ArrayList<Double> yDataList = new ArrayList<Double>();

    for (int i = 1; i < t.size() / 3; i++) {
        msd.setTimelag(i);
        double[] res = msd.evaluate();
        double msdvalue = res[0];
        int N = (int) res[2];
        for (int j = 0; j < N; j++) {
            xDataList.add((double) i * timelag);
            yDataList.add(msdvalue);
        }
    }
    double[] xData = ArrayUtils.toPrimitive(xDataList.toArray(new Double[0]));
    double[] yData = ArrayUtils.toPrimitive(yDataList.toArray(new Double[0]));

    /*
     * Estimate inital values
     */
    MaxDistanceBetweenTwoPositionsFeature maxdist = new MaxDistanceBetweenTwoPositionsFeature(t);
    double estdia = maxdist.evaluate()[0];
    double estDC = dcEst.getDiffusionCoefficient(t, 1 / timelag)[0];

    double[] initialParams = new double[] { estdia * estdia, 0, 0, estDC };

    /*
     * Do the fit and report the results
     */

    ConfinedDiffusionMSDCurveFit cmsdfit = new ConfinedDiffusionMSDCurveFit();
    cmsdfit.setInitParameters(initialParams);
    cmsdfit.doFit(xData, yData, useReducedModel);
    if (useReducedModel) {
        result = new double[] { cmsdfit.getA(), cmsdfit.getD(), cmsdfit.getGoodness() };
    } else {
        result = new double[] { cmsdfit.getA(), cmsdfit.getD(), cmsdfit.getB(), cmsdfit.getC(),
                cmsdfit.getGoodness() };
    }

    return result;
}

From source file:com.l2jfree.network.mmocore.packethandlers.PacketDefinition.java

public PacketDefinition(Class<? extends RP> clazz, S... defaultStates) throws Exception {
    _clazz = clazz;//from www . ja v  a  2 s .c  o m
    _constructor = findConstructor(clazz);

    final List<Integer> opcodes = new ArrayList<Integer>();

    opcodes.add(findOpcode(clazz, "OPCODE", true));

    for (int i = 2;; i++) {
        final Integer opcode = findOpcode(clazz, "OPCODE_" + i, false);
        if (opcode != null)
            opcodes.add(opcode);
        else
            break; // break as it was expected
    }

    _opcodes = ArrayUtils.toPrimitive(opcodes.toArray(new Integer[opcodes.size()]));
    _states = findStates(clazz, defaultStates);

    System.out.println(toString());
}

From source file:com.github.strawberry.guice.config.CharInjectionTest.java

@Test
public void test_that_string_is_injected_into_char_array() {
    properties.put("test:chars", "test_value");
    CharArrayContainer dummy = this.injector.getInstance(CharArrayContainer.class);
    assertThat(ArrayUtils.toPrimitive(dummy.getInjectedChars()), is(equalTo("test_value".toCharArray())));
}

From source file:com.github.strawberry.guice.config.ByteInjectionTest.java

@Test
public void test_that_string_is_injected_into_byte_array() {
    properties.put("test:bytes", "test_value");
    ByteArrayContainer dummy = this.injector.getInstance(ByteArrayContainer.class);
    assertThat(ArrayUtils.toPrimitive(dummy.getInjectedBytes()), is(equalTo("test_value".getBytes())));
}

From source file:com.github.strawberry.guice.CharInjectionTest.java

@Test
public void test_that_string_is_injected_into_char_array() {
    this.jedis.set("test:chars", "test_value");
    CharArrayContainer dummy = this.injector.getInstance(CharArrayContainer.class);
    assertThat(ArrayUtils.toPrimitive(dummy.getInjectedChars()), is(equalTo("test_value".toCharArray())));
}

From source file:com.github.strawberry.guice.ByteInjectionTest.java

@Test
public void test_that_string_is_injected_into_byte_array() {
    this.jedis.set("test:bytes", "test_value");
    ByteArrayContainer dummy = this.injector.getInstance(ByteArrayContainer.class);
    assertThat(ArrayUtils.toPrimitive(dummy.getInjectedBytes()), is(equalTo("test_value".getBytes())));
}

From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java

/**
 * Get the PDU encoding for the given message
 * @param message/*from   w ww .  j a v a  2  s  .c  om*/
 * @param rightshift of the content for concatination
 * @return 
 */
public SMSPDUConversionResult getContent(String message, int rightshift) {
    List<Byte> finalized = new LinkedList<>();
    BitSet currentWorkingBS = new BitSet(16);

    int currentShiftpos = 0;
    boolean currentlyExtended = false;
    int len = 0;

    //repeat while there are characters left
    while (message.length() > 0) {
        String c = message.substring(0, 1);
        message = message.substring(1);
        byte value;

        //loook up current character
        if (this.GSM_3GPP_TS_23_038.containsKey(c)) {
            value = this.GSM_3GPP_TS_23_038.get(c);
        } else {
            if (this.GSM_3GPP_TS_23_038_EXTENSION.containsKey(c)) {
                if (!currentlyExtended) {
                    //extension -> now do the escape character!
                    //do the "new" character the other round
                    message = c + message;
                    currentlyExtended = true;
                    value = this.GSM_3GPP_TS_23_038.get("\u001B");
                } else {
                    //we just did the ecsape character, now do the char from
                    //the extended alphabet
                    value = this.GSM_3GPP_TS_23_038_EXTENSION.get(c);
                    currentlyExtended = false;
                }
            } else {
                throw new RuntimeException("Not found: " + c);

            }

        }

        //start at 0x0
        if (currentShiftpos == 0) {
            //add current char beginning at pos 0
            addByteToBitset(value, currentWorkingBS, 0, 1, 7);
        } else {
            //else start at second byte and do flipping

            //make place for the right bits of the current char in the front
            currentWorkingBS = rightShiftBitset(currentWorkingBS, currentShiftpos);

            //add last X bits in front of the bitset
            addByteToBitset(value, currentWorkingBS, 0, 8 - currentShiftpos, currentShiftpos);

            //add the first X bits at the end of the bitset if any
            if (currentShiftpos < 7) {
                addByteToBitset(value, currentWorkingBS, 8, 1, 7 - currentShiftpos);
            }

            //the first byte of the bitset is now complete! :)
            byte finalByte = currentWorkingBS.toByteArray()[0];
            finalByte = swapEndianFormat(finalByte);
            finalized.add(finalByte);

            //shift bitset left by 8 bits since we just finished and exported a byte
            currentWorkingBS = leftShiftBitset(currentWorkingBS, 8);
        }

        currentShiftpos = (currentShiftpos + 1) % 8;
        len++;
        //for first character -> just add to the bitset
        //addByteToBitset(value, bitset, i*7);

        /*//exchange characters
        for (int j=0;j<((i%8)*8-(i%8)*7);j++) {
        boolean cBit = content.get()
        }*/

    }

    //add last byte (swap back our eagerly shifted byte)
    if (currentShiftpos == 7) {
        byte finalByte = 0x00;
        finalized.add(finalByte);
    } else if (currentShiftpos != 0) {
        byte finalByte = (currentWorkingBS.isEmpty()) ? 0x0 : currentWorkingBS.toByteArray()[0];
        finalByte = swapEndianFormat(finalByte);

        //I don't really know why,  
        //but java fills right shifts with 1s
        //so we have to manually set all new (left) bits to zero
        for (int i = 0; i < currentShiftpos; i++) {
            finalByte = (byte) (finalByte >> 1);
            finalByte = (byte) (finalByte & 0x7F); //unset first bit
        }

        //finalByte = (byte) (finalByte & 0x3F);
        finalized.add(finalByte);
    }

    byte[] finalM = ArrayUtils.toPrimitive(finalized.toArray(new Byte[finalized.size()]));
    Logger.getGlobal().info("1: " + DatatypeConverter.printHexBinary(finalM));

    //in case of rightshift for concatenation -> right shift the whole array
    if (rightshift > 0) {
        BitSet bs = BitSet.valueOf(finalM);
        bs = rightShiftBitset(bs, rightshift);
        finalM = bs.toByteArray();
        Logger.getGlobal().info("2: " + DatatypeConverter.printHexBinary(finalM));
    }

    SMSPDUConversionResult res = new SMSPDUConversionResult(finalM, len);

    return res;
}

From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java

/**
 * Creates a new array by selecting those elements marked as true in the predicate array.
 *
 * @param values The array where the elements are going to be selected from.
 * @param predicate The selection mapper.
 * @return The new array with selected items.
 *///from   ww  w .j a v  a  2 s .  c om
public static double[] selectByPredicate(double[] values, boolean[] predicate) {
    // Define the filtered list:
    List<Double> filtered = new ArrayList<>();

    // Iterate and populate:
    for (int i = 0; i < predicate.length; i++) {
        if (predicate[i]) {
            filtered.add(values[i]);
        }
    }

    // Save the value:
    return ArrayUtils.toPrimitive(filtered.toArray(new Double[filtered.size()]));
}

From source file:Query7Servlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  ww. jav a  2s  .  c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Connection connection = null;
    Statement stmt = null;

    String patientsWithAllSqlQuery = null;
    String patientsWithoutAllSqlQuery = null;

    ResultSet expWithAllResultSet = null;
    ResultSet expWithoutAllResultSet = null;

    String geneID = null;
    double expValue = 0;
    List<Double> exprValuesForGeneID = null;

    Map<String, List<Double>> geneToExpValueALL = new HashMap<String, List<Double>>();
    Map<String, List<Double>> geneToExpValueNOTALL = new HashMap<String, List<Double>>();

    Set<String> geneIDSet = null;
    String[] geneIDs = null;
    List<Double> listOneForGeneId = null;
    List<Double> listTwoForGeneId = null;
    Double[] listOneForGeneIdArr = null;
    Double[] listTwoForGeneIdArr = null;

    double p_value = 0;
    JSONArray informativeGenes = new JSONArray();
    JSONObject informativeGene = null;

    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        Class.forName("oracle.jdbc.driver.OracleDriver");

        connection = DriverManager.getConnection("jdbc:oracle:thin:@VIVEK:1521/ORCL", "system", "vivek");

        stmt = connection.createStatement();

        patientsWithAllSqlQuery = "SELECT P.USER_ID, M.EXPRESSION FROM MICROARRAY_FACT M, PROBE P, CLINICAL_FACT C "
                + "WHERE M.PB_ID = P.PB_ID " + "AND M.S_ID = C.S_ID "
                + "AND C.P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE "
                + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME = 'ALL')";

        patientsWithoutAllSqlQuery = "SELECT P.USER_ID, M.EXPRESSION FROM MICROARRAY_FACT M, PROBE P, CLINICAL_FACT C "
                + "WHERE M.PB_ID = P.PB_ID " + "AND M.S_ID = C.S_ID "
                + "AND C.P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE "
                + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME <> 'ALL')";

        //Expression Values for patients with "ALL"
        expWithAllResultSet = stmt.executeQuery(patientsWithAllSqlQuery);

        //Converting the result set for "ALL" to the map
        while (expWithAllResultSet.next()) {
            geneID = expWithAllResultSet.getString(1);
            expValue = expWithAllResultSet.getDouble(2);

            if (geneToExpValueALL.get(geneID) != null) {
                exprValuesForGeneID = geneToExpValueALL.get(geneID);
            } else {
                exprValuesForGeneID = new ArrayList<Double>();
            }

            exprValuesForGeneID.add(expValue);
            geneToExpValueALL.put(geneID, exprValuesForGeneID);
        }

        //Expression Values for patients without "ALL"
        expWithoutAllResultSet = stmt.executeQuery(patientsWithoutAllSqlQuery);

        while (expWithoutAllResultSet.next()) {
            geneID = expWithoutAllResultSet.getString(1);
            expValue = expWithoutAllResultSet.getDouble(2);

            if (geneToExpValueNOTALL.get(geneID) != null) {
                exprValuesForGeneID = geneToExpValueNOTALL.get(geneID);
            } else {
                exprValuesForGeneID = new ArrayList<Double>();
            }

            exprValuesForGeneID.add(expValue);
            geneToExpValueNOTALL.put(geneID, exprValuesForGeneID);
        }

        //Calculating the p value for genes between two groups
        geneIDSet = geneToExpValueALL.keySet();
        geneIDs = new String[geneIDSet.size()];
        geneIDSet.toArray(geneIDs);

        for (int i = 0; i < geneIDs.length; i++) {
            listOneForGeneId = geneToExpValueALL.get(geneIDs[i]);
            listTwoForGeneId = geneToExpValueNOTALL.get(geneIDs[i]);

            listOneForGeneIdArr = new Double[listOneForGeneId.size()];
            listTwoForGeneIdArr = new Double[listTwoForGeneId.size()];

            listOneForGeneId.toArray(listOneForGeneIdArr);
            listTwoForGeneId.toArray(listTwoForGeneIdArr);

            p_value = new TTest().tTest(ArrayUtils.toPrimitive(listOneForGeneIdArr),
                    ArrayUtils.toPrimitive(listTwoForGeneIdArr));

            if (p_value < 0.01) {
                informativeGene = new JSONObject();
                informativeGene.put("infogene", geneIDs[i]);
                informativeGenes.put(informativeGene);
            }
        }

        out.print(informativeGenes);
        //Closing the statement and connection
        stmt.close();
        connection.close();
    } catch (SQLException e) {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return;
    } catch (ClassNotFoundException e) {
        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return;
    } catch (JSONException e) {
        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return;
    }
}

From source file:at.tuwien.mnsa.smssender.SMS.java

/**
 * Get the list of single SMS for a possible concatenated SMS
 * @return /* w  w  w.  j  a  v  a 2  s.  co  m*/
 */
public List<SMSRepresentation> getMultiMessage() {
    List<SMSRepresentation> messages = new LinkedList<>();

    //try to get all in a single message
    SMSRepresentation single = this.getMessage();
    if (single.len <= 160) {
        messages.add(single);
        return messages;
    }

    //else, one message is not sufficient :-(
    //we have to split the messages
    String remainingText = this.text;
    int len = 153;
    int remaining = this.text.length();

    List<SMSPDUConverter.SMSPDUConversionResult> messageResults = new ArrayList<>();
    while (remaining > 0) {
        String text = remainingText.substring(0, Math.min(remainingText.length(), len));

        SMSPDUConverter.SMSPDUConversionResult conversionResult = SMSPDUConverter.getInstance().getContent(text,
                1);
        if (conversionResult.len > 153) {
            //we got too much :-(
            //try shorten it
            len--;
            continue;
        }
        //add the message
        messageResults.add(conversionResult);

        remaining = remaining - len;

        //continue in the text
        if (remaining > 0) {
            remainingText = remainingText.substring(len);
        }

    }

    for (int i = 0; i < messageResults.size(); i++) {
        List<Byte> bytes = new ArrayList<>();

        bytes.add((byte) 0x00); //SMSC Information
        bytes.add((byte) 0x41); //First octed of the SMS-Submit message

        bytes.add((byte) i); //TP-Message-Reference (0: phone default)
        //The message reference should be different with each SMS-SUBMIT PDU sent. (mobiletidings.com)

        int lenRec = this.recipient.length();
        bytes.add((byte) lenRec);
        bytes.add((byte) 0x91);

        bytes.addAll(Arrays.asList(ArrayUtils.toObject(getSemiOctet(this.recipient))));

        bytes.add((byte) 0x00); //TP-PID Protocol Identifier
        bytes.add((byte) 0x00); //7 bit encoding
        //bytes.add((byte) 0xAA); //validity (4 days) - @TODO: optional?

        int lenContent = Math.min(160, messageResults.get(i).len + 7); //count of septets
        bytes.add((byte) lenContent);

        bytes.add((byte) 0x05); //User data header length (UDHL)

        bytes.addAll(getMultiMessagePayloadHeader(i + 1, messageResults.size()));

        byte[] message = messageResults.get(i).message;
        bytes.addAll(Arrays.asList(ArrayUtils.toObject(message)));

        String sMessage = DatatypeConverter
                .printHexBinary(ArrayUtils.toPrimitive(bytes.toArray(new Byte[bytes.size()])));
        int smsLen = (sMessage.length() / 2) - 1;

        messages.add(new SMSRepresentation(sMessage, smsLen));
        //System.out.println("length: " + (((messages.get(i).length()/2)-1)));
    }

    //return DatatypeConverter.printHexBinary(ArrayUtils.toPrimitive(bytes.toArray(new Byte[bytes.size()])));

    return messages;
}