List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive
public static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
protected XYChart.Series<Double, Double> getOverlayHistogram(Overlay overlay) { Timer timer = timerService.getTimer(this.getClass()); timer.start();//from w ww. j ava 2 s.c om Double[] valueList = statsService.getValueListFromImageDisplay(currentDisplay(), overlay); timer.elapsed("Getting the stats"); SummaryStatistics sumup = new SummaryStatistics(); for (Double v : valueList) { sumup.addValue(v); } timer.elapsed("Building the sumup"); double min = sumup.getMin(); double max = sumup.getMax(); double range = max - min; int bins = 100;//new Double(max - min).intValue(); EmpiricalDistribution distribution = new EmpiricalDistribution(bins); double[] values = ArrayUtils.toPrimitive(valueList); Arrays.parallelSort(values); distribution.load(values); timer.elapsed("Sort and distrubution repartition up"); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(bins); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<Double, Double>(k, new Double(st.getN()))); k += range / bins; } serie.getData().clear(); serie.getData().addAll(data); timer.elapsed("Creating charts"); return serie; }
From source file:io.pravega.controller.eventProcessor.impl.EventProcessorTest.java
@Test(timeout = 10000) public void testEventProcessorWriter() throws ReinitializationRequiredException, CheckpointStoreException { int initialCount = 1; String systemName = "testSystem"; String readerGroupName = "testReaderGroup"; int[] input = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; EventStreamWriterMock<TestEvent> writer = new EventStreamWriterMock<>(); CheckpointStore checkpointStore = CheckpointStoreFactory.createInMemoryStore(); CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build(); EventProcessorGroupConfig config = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1) .readerGroupName(READER_GROUP).streamName(STREAM_NAME).checkpointConfig(checkpointConfig).build(); createEventProcessorGroupConfig(initialCount); EventProcessorSystemImpl system = createMockSystem(systemName, PROCESS, SCOPE, createEventReaders(1, input), writer, readerGroupName);//from w w w . j a va 2s . c o m EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder() .supplier(() -> new StartWritingEventProcessor(false, input)).serializer(new JavaSerializer<>()) .decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(config).build(); // Create EventProcessorGroup. EventProcessorGroupImpl<TestEvent> group = (EventProcessorGroupImpl<TestEvent>) system .createEventProcessorGroup(eventProcessorConfig, checkpointStore); // Await until it is ready. group.awaitRunning(); // By now, the events have been written to the Mock EventStreamWriter. Integer[] writerList = writer.getEventList().stream().map(TestEvent::getNumber).collect(Collectors.toList()) .toArray(new Integer[input.length]); // Validate that events are correctly written. Assert.assertArrayEquals(input, ArrayUtils.toPrimitive(writerList)); }
From source file:dk.dma.ais.view.rest.AisStoreResource.java
@GET @Path("/history/kml") @Produces(MEDIA_TYPE_KMZ)//from ww w . j av a2s . c o m public Response historyKml(@Context UriInfo info, @QueryParam("mmsi") List<Integer> mmsis) { Iterable<AisPacket> query = getHistory(info, ArrayUtils.toPrimitive(mmsis.toArray(new Integer[mmsis.size()]))); return Response.ok().entity( StreamingUtil.createZippedStreamingOutput(query, AisPacketOutputSinks.newKmlSink(), "history.kml")) .type(MEDIA_TYPE_KMZ).build(); }
From source file:net.maizegenetics.analysis.imputation.FILLINImputationAccuracy.java
private boolean matchChromosomes() { Chromosome[] unimpChr = this.unimp.chromosomes(); Chromosome[] keyChr = this.maskKey.chromosomes(); ArrayList<Integer> keepSites = new ArrayList<>(); for (Chromosome chr : unimpChr) { //if any of the chromosomes in input do not exist in key, return false (which then masks proportion) if (Arrays.binarySearch(keyChr, chr) < 0) return false; }/*from www. j a va 2 s .c om*/ for (Chromosome chr : keyChr) { //keep sites on key that are on matching chromosomes if (Arrays.binarySearch(unimpChr, chr) > -1) { int[] startEnd = this.maskKey.firstLastSiteOfChromosome(chr); for (int site = startEnd[0]; site <= startEnd[1]; site++) { keepSites.add(site); } } } FilterGenotypeTable filter = FilterGenotypeTable.getInstance(this.maskKey, ArrayUtils.toPrimitive(keepSites.toArray(new Integer[keepSites.size()]))); this.maskKey = filter;//GenotypeTableBuilder.getGenotypeCopyInstance(filter);//Change this back when GenotypeCopyInstance fixed if (verboseOutput) System.out.println(this.maskKey.numberOfSites() + " sites retained after chromsome filter"); return true; }
From source file:gov.nih.nci.cabig.caaers.web.ae.AdverseEventReconciliationCommand.java
public void seralizeMapping() { AeMappingsDTO mappings = new AeMappingsDTO(); List<Integer> rejectedExternal = new ArrayList<Integer>(); for (AdverseEventDTO ae : getRejectedExternalAeList()) rejectedExternal.add(ae.getId()); mappings.setRejectedExternalAeIds(ArrayUtils.toPrimitive(rejectedExternal.toArray(new Integer[] {}))); List<Integer> rejectedInternal = new ArrayList<Integer>(); for (AdverseEventDTO ae : getRejectedInternalAeList()) rejectedInternal.add(ae.getId()); mappings.setRejectedInternalAeIds(ArrayUtils.toPrimitive(rejectedInternal.toArray(new Integer[] {}))); List<AeMergeDTO> relations = new ArrayList<AeMergeDTO>(); for (Map.Entry<AdverseEventDTO, AdverseEventDTO> entry : matchedAeMapping.entrySet()) { String key = entry.getKey().getId() + "_" + entry.getValue().getId(); AeMergeDTO merge = new AeMergeDTO(); merge.setInteralAeId(entry.getKey().getId()); merge.setExternalAeId(entry.getValue().getId()); relations.add(merge);/*w w w . ja v a2s . co m*/ AdverseEventDTO ae = mergeMap.get(key); if (ae != null) merge.copyChanges(entry.getKey(), entry.getValue(), ae); } mappings.setRelations(relations.toArray(new AeMergeDTO[] {})); reportingPeriod.setOldAeMapping(AeMappingsDTO.seralize(mappings)); }
From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.sabr.ForexSmileDeltaSurfaceDataBundleTest.java
@Test public void testObject() { assertArrayEquals(FORWARDS, DATA.getForwards(), EPS); assertArrayEquals(EXPIRIES, DATA.getExpiries(), 0); final int n = DELTAS.length; for (int i = 0; i < EXPIRIES.length; i++) { final double[] rr = new double[n]; final double[] s = new double[n]; for (int j = 0; j < n; j++) { rr[j] = RR[j][i];// ww w .j a v a2 s . c o m s[j] = STRANGLE[j][i]; } final SmileDeltaParameters cal = new SmileDeltaParameters(EXPIRIES[i], ATM[i], DELTAS, rr, s); assertArrayEquals(cal.getStrike(FORWARD_CURVE.getForward(EXPIRIES[i])), DATA.getStrikes()[i], EPS); assertArrayEquals(cal.getVolatility(), DATA.getVolatilities()[i], EPS); } assertEquals(FORWARD_CURVE, DATA.getForwardCurve()); // assertEquals(IS_CALL_DATA, DATA.isCallData()); ForexSmileDeltaSurfaceDataBundle other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, DELTAS, ATM, RR, STRANGLE, IS_CALL_DATA); assertEquals(DATA, other); assertEquals(DATA.hashCode(), other.hashCode()); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, STRIKES, VOLS, IS_CALL_DATA); assertEquals(DATA, other); assertEquals(DATA.hashCode(), other.hashCode()); other = new ForexSmileDeltaSurfaceDataBundle(FORWARDS, EXPIRIES, DELTAS, ATM, RR, STRANGLE, IS_CALL_DATA, INTERPOLATOR); assertArrayEquals(DATA.getExpiries(), other.getExpiries(), 0); for (int i = 0; i < EXPIRIES.length; i++) { assertArrayEquals(DATA.getStrikes()[i], other.getStrikes()[i], 0); assertArrayEquals(DATA.getVolatilities()[i], other.getVolatilities()[i], 0); } // assertEquals(DATA.isCallData(), other.isCallData()); assertArrayEquals(ArrayUtils.toPrimitive(DATA.getForwardCurve().getForwardCurve().getXData()), ArrayUtils.toPrimitive(other.getForwardCurve().getForwardCurve().getXData()), 0); assertArrayEquals(ArrayUtils.toPrimitive(DATA.getForwardCurve().getForwardCurve().getYData()), ArrayUtils.toPrimitive(other.getForwardCurve().getForwardCurve().getYData()), 0); assertEquals(((InterpolatedDoublesCurve) DATA.getForwardCurve().getForwardCurve()).getInterpolator(), ((InterpolatedDoublesCurve) other.getForwardCurve().getForwardCurve()).getInterpolator()); final ForwardCurve otherCurve = new ForwardCurve( InterpolatedDoublesCurve.from(EXPIRIES, EXPIRIES, INTERPOLATOR)); other = new ForexSmileDeltaSurfaceDataBundle(otherCurve, EXPIRIES, DELTAS, ATM, RR, STRANGLE, IS_CALL_DATA); assertFalse(DATA.equals(other)); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, new double[] { 7. / 365, 14 / 365., 21 / 365., 1 / 12., 3 / 12., 0.5, 0.75, 1, 5, 9 }, DELTAS, ATM, RR, STRANGLE, IS_CALL_DATA); assertFalse(DATA.equals(other)); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, new double[] { 0.15, 0.35 }, ATM, RR, STRANGLE, IS_CALL_DATA); assertFalse(DATA.equals(other)); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, DELTAS, FORWARDS, RR, STRANGLE, IS_CALL_DATA); assertFalse(DATA.equals(other)); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, DELTAS, ATM, STRANGLE, STRANGLE, IS_CALL_DATA); assertFalse(DATA.equals(other)); other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, DELTAS, ATM, RR, RR, IS_CALL_DATA); assertFalse(DATA.equals(other)); // other = new ForexSmileDeltaSurfaceDataBundle(FORWARD_CURVE, EXPIRIES, DELTAS, ATM, RR, STRANGLE, !IS_CALL_DATA); // assertFalse(DATA.equals(other)); }
From source file:gsn.msr.sensormap.datahub.ServiceSkeleton.java
private ArrayOfSensorData transformToSensorDataArray(String vsName, StringBuilder query, boolean is_binary_linked) { logger.debug("QUERY : " + query); ArrayOfSensorData toReturn = new ArrayOfSensorData(); try {/*w ww . ja v a 2 s . c o m*/ DataEnumerator output = null; output = Main.getStorage(vsName).executeQuery(query, is_binary_linked); SensorData data = new SensorData(); ArrayOfDateTime arrayOfDateTime = new ArrayOfDateTime(); ArrayList<Double> sensor_readings = new ArrayList(); while (output.hasMoreElements()) { StreamElement se = output.nextElement(); Calendar timestamp = Calendar.getInstance(); timestamp.setTimeInMillis(se.getTimeStamp()); arrayOfDateTime.addDateTime(timestamp); sensor_readings.add(Double.parseDouble(se.getData()[0].toString())); } data.setSensorType(5);//Vector data.setDataType(1);// Generic data.setTimestamps(arrayOfDateTime); ArrayOfDouble arrayOfDouble = new ArrayOfDouble(); arrayOfDouble.set_double(ArrayUtils.toPrimitive(sensor_readings.toArray(new Double[] {}))); data.setData(arrayOfDouble); toReturn.addSensorData(data); } catch (SQLException e) { logger.error(e.getMessage(), e); } return toReturn; }
From source file:eionet.web.action.VocabularyFoldersActionBean.java
/** * Returns the expanded folder IDs and sets the correct expanded[] value. * * @return/*from www . j a v a2 s . c o m*/ */ private int[] parseExpandedIds() { List<Integer> result = new ArrayList<Integer>(); if (StringUtils.isNotEmpty(expanded)) { String[] expandedStrArr = StringUtils.split(expanded, ","); for (String s : expandedStrArr) { result.add(Integer.parseInt(s)); } } if (expand) { result.add(folderId); } else { result.remove(Integer.valueOf(folderId)); } expanded = StringUtils.join(result, ","); return ArrayUtils.toPrimitive(result.toArray(new Integer[result.size()])); }
From source file:com.twineworks.kettle.ruby.step.RubyStepSyntaxHighlighter.java
void highlight(String title, StyledTextComp wText) { // set up lexer process script = wText.getText();/* w w w .j av a 2 s . c o m*/ StyledText canvas = wText.getStyledText(); initBytes(); initLexer(title); // remember bounds of current token int leftTokenBorder = 0; int rightTokenBorder = 0; int token = 0; int previousToken = 0; int lastCommentEnd = 0; ArrayList<StyleRange> ranges = new ArrayList<>(200); ArrayList<Integer> intRanges = new ArrayList<>(400); try { boolean keepParsing = true; while (keepParsing) { /* take care of comments, which are stripped out by the lexer */ int[] upcomingComment = null; while ((rightTokenBorder >= lastCommentEnd || rightTokenBorder == 0) && (upcomingComment = getUpcomingCommentPos(rightTokenBorder)) != null) { leftTokenBorder = upcomingComment[0]; rightTokenBorder = leftTokenBorder + upcomingComment[1]; lastCommentEnd = rightTokenBorder; // System.out.println("Found comment -> [" + leftTokenBorder + "," + rightTokenBorder + "]"); ranges.add(tokenToStyleRange(TOKEN_COMMENT, null, previousToken)); int start = charOffset(leftTokenBorder); int count = charOffset(rightTokenBorder) - start; intRanges.add(start); intRanges.add(count); } /* read language syntax */ int oldOffset = lexerOffset(); previousToken = token; token = lexer.nextToken(); keepParsing = !lexer.eofp; if (token > 0 && token != 10) { Object v = lexer.value(); leftTokenBorder = oldOffset; if (leftTokenBorder < lastCommentEnd && lexerOffset() > lastCommentEnd) { leftTokenBorder = lastCommentEnd; } rightTokenBorder = lexerOffset(); // System.out.println("Found token " + token + " -> " + lexer.value() + " [" + leftTokenBorder + "," + rightTokenBorder + "]"); ranges.add(tokenToStyleRange(token, v, previousToken)); int start = charOffset(leftTokenBorder); int count = charOffset(rightTokenBorder) - start; intRanges.add(start); intRanges.add(count); } } // don't mind anything that might go wrong during parsing } catch (SyntaxException e) { // apply the latest style to the rest of the file in case there is a syntax error if (ranges.size() > 0) { ranges.remove(ranges.size() - 1); intRanges.remove(intRanges.size() - 1); intRanges.remove(intRanges.size() - 1); } ranges.add(tokenToStyleRange(token, null, previousToken)); int start = charOffset(leftTokenBorder); intRanges.add(start); intRanges.add(script.length() - start); } catch (Exception ignored) { // the lexer will sometimes throw a non-syntax exception when confronted with malformed input // ignored.printStackTrace(); } // don't mind swt errors in case some unforeseen input brought the style ranges out of order try { canvas.setStyleRanges(ArrayUtils.toPrimitive(intRanges.toArray(new Integer[0])), ranges.toArray(new StyleRange[0])); } catch (Exception e) { // e.printStackTrace(); } }
From source file:com.ec.android.module.bluetooth40.base.BaseBluetoothControlWithProtocolActivity.java
protected void writeContent(Byte[] bytes) { writeContent(new String(ArrayUtils.toPrimitive(bytes))); }