List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive
public static boolean[] toPrimitive(final Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null for a null input array.
From source file:com.github.strawberry.guice.config.CharInjectionTest.java
@Test public void test_that_missing_value_causes_default_value_to_be_set_for_char_array() { // Test for case where no value is present in redis database. CharArrayDefaultValueContainer dummy = this.injector.getInstance(CharArrayDefaultValueContainer.class); assertThat(dummy.getInjectedChars(), is(equalTo(new Character[] { 't', 'e', 's', 't' }))); // Test for case where value is present in redis database. // Default value should be overwritten. properties.put("test:chars", "test_value"); dummy = this.injector.getInstance(CharArrayDefaultValueContainer.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_missing_value_causes_default_value_to_be_set_for_byte_array() { // Test for case where no value is present in redis database. ByteArrayDefaultValueContainer dummy = this.injector.getInstance(ByteArrayDefaultValueContainer.class); assertThat(dummy.getInjectedBytes(), is(equalTo(new Byte[] { (byte) 1, (byte) 2, (byte) 3 }))); // Test for case where value is present in redis database. // Default value should be overwritten. properties.put("test:bytes", "test_value"); dummy = this.injector.getInstance(ByteArrayDefaultValueContainer.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_missing_value_causes_default_value_to_be_set_for_char_array() { // Test for case where no value is present in redis database. CharArrayDefaultValueContainer dummy = this.injector.getInstance(CharArrayDefaultValueContainer.class); assertThat(dummy.getInjectedChars(), is(equalTo(new Character[] { 't', 'e', 's', 't' }))); // Test for case where value is present in redis database. // Default value should be overwritten. this.jedis.set("test:chars", "test_value"); dummy = this.injector.getInstance(CharArrayDefaultValueContainer.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_missing_value_causes_default_value_to_be_set_for_byte_array() { // Test for case where no value is present in redis database. ByteArrayDefaultValueContainer dummy = this.injector.getInstance(ByteArrayDefaultValueContainer.class); assertThat(dummy.getInjectedBytes(), is(equalTo(new Byte[] { (byte) 1, (byte) 2, (byte) 3 }))); // Test for case where value is present in redis database. // Default value should be overwritten. this.jedis.set("test:bytes", "test_value"); dummy = this.injector.getInstance(ByteArrayDefaultValueContainer.class); assertThat(ArrayUtils.toPrimitive(dummy.getInjectedBytes()), is(equalTo("test_value".getBytes()))); }
From source file:gr.iti.mklab.reveal.forensics.maps.dq.DQExtractor.java
public void detectDQDiscontinuities() { int imWidth = dcts.length; int imHeight = dcts[0].length; int[] p_h_avg = new int[maxCoeffs]; int[] p_h_fft = new int[maxCoeffs]; int[] p_final = new int[maxCoeffs]; double[][] pTampered = new double[maxCoeffs][]; double[][] pUntampered = new double[maxCoeffs][]; for (int coeffIndex = 0; coeffIndex < maxCoeffs; coeffIndex++) { int coe = coeff[coeffIndex]; int startY = coe % 8 - 1; if (startY == -1) { startY = 8;/*from w ww . j a v a 2s . c o m*/ } int startX = (int) Math.floor((coe - 1) / 8); List<Integer> selectedCoeffs = new ArrayList<Integer>(); for (int ii = startX; ii < imWidth; ii += 8) { for (int jj = startY; jj < imHeight; jj += 8) { selectedCoeffs.add(dcts[ii][jj]); } } int minCoeffValue = Collections.min(selectedCoeffs); int maxCoeffValue = Collections.max(selectedCoeffs); int s_0; Double[] coeffHist = new Double[0]; if (maxCoeffValue - minCoeffValue > 0) { //will be a power of 2 to allow for fft (zero padded) int trueHistRange = maxCoeffValue - minCoeffValue + 1; //int histLength = trueHistRange; int histLength = (int) Math.pow(2, Math.ceil(Math.log(trueHistRange) / Math.log(2))); coeffHist = new Double[histLength]; for (int ii = 0; ii < coeffHist.length; ii++) { coeffHist[ii] = 0.0; } for (Integer selectedCoeff : selectedCoeffs) { coeffHist[selectedCoeff - minCoeffValue] += 1; } List<Double> coeffHistList = Arrays.asList(coeffHist); s_0 = coeffHistList.indexOf(Collections.max(coeffHistList)); List<Double> h = new ArrayList<>(); DescriptiveStatistics vals; for (int coeffInd = 1; coeffInd < coeffHistList.size(); coeffInd++) { vals = new DescriptiveStatistics(); for (int leapInd = s_0; leapInd < coeffHistList.size(); leapInd += coeffInd) { vals.addValue(coeffHistList.get(leapInd)); } for (int leapInd = s_0 - coeffInd; leapInd >= 0; leapInd -= coeffInd) { vals.addValue(coeffHistList.get(leapInd)); } h.add(vals.getMean()); } p_h_avg[coeffIndex] = (h.indexOf(Collections.max(h))); FastFourierTransformer fastFourierTransformer = new FastFourierTransformer( DftNormalization.STANDARD); Complex[] fft = fastFourierTransformer.transform(ArrayUtils.toPrimitive(coeffHist), TransformType.FORWARD); double[] power = new double[fft.length]; for (int ii = 0; ii < power.length; ii++) { power[ii] = fft[ii].abs(); } //Find first local minimum, to bypass DC peak double DC = power[0]; int FreqValley = 1; while (FreqValley < power.length - 1 & power[FreqValley] >= power[FreqValley + 1]) { FreqValley++; } int maxFFTInd = 0; double maxFFTVal = 0; double minFFTVal = Double.MAX_VALUE; for (int ii = FreqValley; ii < power.length / 2; ii++) { if (power[ii] > maxFFTVal) { maxFFTInd = ii; maxFFTVal = power[ii]; } if (power[ii] < minFFTVal) { minFFTVal = power[ii]; } } if (maxFFTInd == 0 | maxFFTVal < (DC / 5) | minFFTVal / maxFFTVal > 0.9) { p_h_fft[coeffIndex] = 1; } else { p_h_fft[coeffIndex] = Math.round(coeffHist.length / maxFFTInd); } } else { p_h_avg[coeffIndex] = 1; p_h_fft[coeffIndex] = 1; s_0 = 0; } if (p_h_avg[coeffIndex] < p_h_fft[coeffIndex]) { p_final[coeffIndex] = p_h_avg[coeffIndex]; } else { p_final[coeffIndex] = p_h_fft[coeffIndex]; } pTampered[coeffIndex] = new double[selectedCoeffs.size()]; pUntampered[coeffIndex] = new double[selectedCoeffs.size()]; int[] adjustedCoeffs = new int[selectedCoeffs.size()]; int[] period_start = new int[selectedCoeffs.size()]; int[] period; int[] num = new int[selectedCoeffs.size()]; int[] denom = new int[selectedCoeffs.size()]; double[] P_u = new double[selectedCoeffs.size()]; double[] P_t = new double[selectedCoeffs.size()]; if (p_final[coeffIndex] != 1) { for (int ii = 0; ii < adjustedCoeffs.length; ii++) { adjustedCoeffs[ii] = selectedCoeffs.get(ii) - minCoeffValue; period_start[ii] = adjustedCoeffs[ii] - rem(adjustedCoeffs[ii] - s_0, p_final[coeffIndex]); } for (int kk = 0; kk < selectedCoeffs.size(); kk++) { if (period_start[kk] > s_0) { period = new int[p_final[coeffIndex]]; for (int ii = 0; ii < p_final[coeffIndex]; ii++) { period[ii] = period_start[kk] + ii; if (period[ii] >= coeffHist.length) { period[ii] = period[ii] - p_final[coeffIndex]; } } num[kk] = (int) coeffHist[adjustedCoeffs[kk]].doubleValue(); denom[kk] = 0; for (int ll = 0; ll < period.length; ll++) { denom[kk] = denom[kk] + (int) coeffHist[period[ll]].doubleValue(); } } else { period = new int[p_final[coeffIndex]]; for (int ii = 0; ii < p_final[coeffIndex]; ii++) { period[ii] = period_start[kk] - ii; if (period_start[kk] - p_final[coeffIndex] + 1 <= 0) { if (period[ii] <= 0) { period[ii] = period[ii] + p_final[coeffIndex]; } } } num[kk] = (int) coeffHist[adjustedCoeffs[kk]].doubleValue(); denom[kk] = 0; for (int ll = 0; ll < period.length; ll++) { denom[kk] = denom[kk] + (int) coeffHist[period[ll]].doubleValue(); } } P_u[kk] = ((double) num[kk] / denom[kk]); P_t[kk] = (1.0 / p_final[coeffIndex]); if (P_u[kk] + P_t[kk] != 0) { pTampered[coeffIndex][kk] = P_t[kk] / (P_u[kk] + P_t[kk]); pUntampered[coeffIndex][kk] = P_u[kk] / (P_u[kk] + P_t[kk]); } else { pTampered[coeffIndex][kk] = 0.5; pUntampered[coeffIndex][kk] = 0.5; } } } else { for (int kk = 0; kk < selectedCoeffs.size(); kk++) { pTampered[coeffIndex][kk] = 0.5; pUntampered[coeffIndex][kk] = 0.5; } } } double[] pTamperedOverall = new double[pTampered[0].length]; double pTamperedProd; double pUntamperedProd; for (int locationIndex = 0; locationIndex < pTampered[0].length; locationIndex++) { pTamperedProd = 1; pUntamperedProd = 1; for (int coeffIndex = 0; coeffIndex < pTampered.length; coeffIndex++) { pTamperedProd = pTamperedProd * pTampered[coeffIndex][locationIndex]; pUntamperedProd = pUntamperedProd * pUntampered[coeffIndex][locationIndex]; } if (pTamperedProd + pUntamperedProd != 0) { pTamperedOverall[locationIndex] = pTamperedProd / (pTamperedProd + pUntamperedProd); } else { pTamperedOverall[locationIndex] = 0; } } int blocksH = imWidth / 8; int blocksV = imHeight / 8; double[][] outputMap = new double[blocksV][blocksH]; for (int kk = 0; kk < pTamperedOverall.length; kk++) { outputMap[kk % blocksV][(int) Math.floor(kk / blocksV)] = pTamperedOverall[kk]; if (pTamperedOverall[kk] > maxProbValue) { maxProbValue = pTamperedOverall[kk]; } if (pTamperedOverall[kk] < minProbValue) { minProbValue = pTamperedOverall[kk]; } } probabilityMap = outputMap; BufferedImage outputIm = visualizeWithJet(outputMap); // output displaySurface = outputIm; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a ship type outside the given list. *///from w ww. ja v a 2 s . co m public Predicate<AisPacket> filterOnTargetShiptype(Integer[] shiptypes) { final int[] list = ArrayUtils.toPrimitive(shiptypes); Arrays.sort(list); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int shiptype = getShiptype(mmsi); // Extract shiptype no. - if we know it return shiptype < 0 ? false : Arrays.binarySearch(list, shiptype) >= 0; } public String toString() { return "shiptype in " + skipBrackets(Arrays.toString(list)); } }; }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Converts a list of BigIntegers to an array of shorts. * @param List<BigInteger> list of BigIntegers * @return array of shorts *//*from w w w . java2 s. c o m*/ public static short[] toShortArray(List<BigInteger> list) { for (BigInteger val : list) { if (!OverFlowUtil.shortOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Short[list.size()])); }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Converts a list of BigDecimals to an array of shorts. * @param List<BigDecimal> list of BigDecimals * @return array of shorts */// w w w. ja va 2 s . c o m public static short[] toShortArray(List<BigDecimal> list) { for (BigDecimal val : list) { if (!OverFlowUtil.shortOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Short[list.size()])); }
From source file:jat.application.DE405Propagator.DE405PropagatorPlot.java
double[][] getXYZforPlot(ArrayList<Double> xsol, ArrayList<Double> ysol, ArrayList<Double> zsol) { int arraySize = xsol.size(); double[] xsolArray = ArrayUtils.toPrimitive(xsol.toArray(new Double[arraySize])); double[] ysolArray = ArrayUtils.toPrimitive(ysol.toArray(new Double[arraySize])); double[] zsolArray = ArrayUtils.toPrimitive(zsol.toArray(new Double[arraySize])); double[][] XYZ = new double[arraySize][3]; plotBounds = 0.;//w w w . j a v a 2s .c o m for (int i = 0; i < arraySize; i++) { XYZ[i][0] = xsolArray[i]; XYZ[i][1] = ysolArray[i]; XYZ[i][2] = zsolArray[i]; plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][0])); plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][1])); plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][2])); } plotBounds /= 1.5; return XYZ; }
From source file:Query6Servlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . ja va 2 s . co m * * @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 patientswithAllSqlStat = null; String patientswithAmlSqlStat = null; ResultSet rsetForALL = null; ResultSet rsetForAML = null; String patientID = null; double expValue = 0; List<Double> exprValuesForPatientID = null; Map<String, List<Double>> patientToExpValueALL = new HashMap<String, List<Double>>(); Map<String, List<Double>> patientToExpValueAML = new HashMap<String, List<Double>>(); //Variables for average correlation int i, j; double correlation = 0; double totalCorrelationALL = 0; double avgCorrelationAll = 0; double numComForAll = 0; Set<String> patientsForALLSet = null; String[] patientsForALL = null; double totalCorrelationAML = 0; double avgCorrelationAllAml = 0; double numComForAml = 0; Set<String> patientsForAMLSet = null; String[] patientsForAML = null; List<Double> patientOneExprValues = null; Double[] patientOneExprValuesArr = null; List<Double> patientTwoExprValues = null; Double[] patientTwoExprValuesArr = null; response.setContentType("application/json"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ Class.forName("oracle.jdbc.driver.OracleDriver"); connection = DriverManager.getConnection("jdbc:oracle:thin:@aos.acsu.buffalo.edu:1521/aos.buffalo.edu", "vvelrath", "cse601"); stmt = connection.createStatement(); patientswithAllSqlStat = "SELECT C.P_ID, EXPRESSION FROM MICROARRAY_FACT M, CLINICAL_FACT C " + "WHERE M.S_ID = C.S_ID AND M.PB_ID IN (SELECT PB_ID FROM PROBE, GENE_FACT " + "WHERE PROBE.USER_ID = GENE_FACT.GENE_UID AND " + "GO_ID = 0007154) AND M.S_ID IN (SELECT S_ID FROM CLINICAL_FACT " + "WHERE P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE " + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME = 'ALL'))"; patientswithAmlSqlStat = "SELECT C.P_ID, EXPRESSION FROM MICROARRAY_FACT M, CLINICAL_FACT C " + "WHERE M.S_ID = C.S_ID AND M.PB_ID IN (SELECT PB_ID FROM PROBE, GENE_FACT " + "WHERE PROBE.USER_ID = GENE_FACT.GENE_UID AND " + "GO_ID = 0007154) AND M.S_ID IN (SELECT S_ID FROM CLINICAL_FACT " + "WHERE P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE " + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME = 'AML'))"; //Executing the query for ALL rsetForALL = stmt.executeQuery(patientswithAllSqlStat); //Converting the result set for "ALL" to the map while (rsetForALL.next()) { patientID = rsetForALL.getString(1); expValue = rsetForALL.getDouble(2); if (patientToExpValueALL.get(patientID) != null) { exprValuesForPatientID = patientToExpValueALL.get(patientID); } else { exprValuesForPatientID = new ArrayList<Double>(); } exprValuesForPatientID.add(expValue); patientToExpValueALL.put(patientID, exprValuesForPatientID); } //Executing the query for AML rsetForAML = stmt.executeQuery(patientswithAmlSqlStat); //Converting the result set for "AML" to the map while (rsetForAML.next()) { patientID = rsetForAML.getString(1); expValue = rsetForAML.getDouble(2); if (patientToExpValueAML.get(patientID) != null) { exprValuesForPatientID = patientToExpValueAML.get(patientID); } else { exprValuesForPatientID = new ArrayList<Double>(); } exprValuesForPatientID.add(expValue); patientToExpValueAML.put(patientID, exprValuesForPatientID); } //Finding average correlation for two patients with ALL and for between ALL and AML patientsForALLSet = patientToExpValueALL.keySet(); patientsForALL = new String[patientsForALLSet.size()]; patientsForALLSet.toArray(patientsForALL); patientsForAMLSet = patientToExpValueAML.keySet(); patientsForAML = new String[patientsForAMLSet.size()]; patientsForAMLSet.toArray(patientsForAML); for (i = 0; i < patientsForALL.length; i++) { patientOneExprValues = patientToExpValueALL.get(patientsForALL[i]); patientOneExprValuesArr = new Double[patientOneExprValues.size()]; patientOneExprValues.toArray(patientOneExprValuesArr); //Calculating the correlation for between ALL for (j = i + 1; j < patientsForALL.length; j++) { patientTwoExprValues = patientToExpValueALL.get(patientsForALL[j]); patientTwoExprValuesArr = new Double[patientTwoExprValues.size()]; ; patientTwoExprValues.toArray(patientTwoExprValuesArr); correlation = new PearsonsCorrelation().correlation( ArrayUtils.toPrimitive(patientOneExprValuesArr), ArrayUtils.toPrimitive(patientTwoExprValuesArr)); totalCorrelationALL += correlation; numComForAll++; } //Calculating the correlation for between ALL and AML for (j = 0; j < patientsForAML.length; j++) { patientTwoExprValues = patientToExpValueAML.get(patientsForAML[j]); patientTwoExprValuesArr = new Double[patientTwoExprValues.size()]; ; patientTwoExprValues.toArray(patientTwoExprValuesArr); correlation = new PearsonsCorrelation().correlation( ArrayUtils.toPrimitive(patientOneExprValuesArr), ArrayUtils.toPrimitive(patientTwoExprValuesArr)); totalCorrelationAML += correlation; numComForAml++; } } avgCorrelationAll = totalCorrelationALL / numComForAll; avgCorrelationAllAml = totalCorrelationAML / numComForAml; //Populating the JSON Object JSONObject avgCorr = new JSONObject(); avgCorr.put("avgcorrall", avgCorrelationAll); avgCorr.put("avgcorrallaml", avgCorrelationAllAml); out.print(avgCorr); //Closing the statement and connection stmt.close(); connection.close(); } catch (SQLException e) { System.out.println("Connection Failed! Check output console"); } catch (ClassNotFoundException e) { System.out.println("Where is your Oracle JDBC Driver?"); } catch (JSONException ex) { Logger.getLogger(Query4Servlet.class.getName()).log(Level.SEVERE, null, ex); } }