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:com.opengamma.analytics.financial.instrument.payment.CouponArithmeticAverageONDefinition.java
/** * Constructor from all the coupon details. * @param currency The payment currency. * @param paymentDate Coupon payment date. * @param accrualStartDate Start date of the accrual period. * @param accrualEndDate End date of the accrual period. * @param paymentAccrualFactor Accrual factor of the accrual period. * @param notional Coupon notional./*from w w w . ja v a2 s. com*/ * @param index The OIS-like index on which the coupon fixes. * @param fixingPeriodStartDate The start date of the fixing period. * @param fixingPeriodEndDate The end date of the fixing period. * @param calendar The holiday calendar for the overnight leg. */ public CouponArithmeticAverageONDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double paymentAccrualFactor, final double notional, final IndexON index, final ZonedDateTime fixingPeriodStartDate, final ZonedDateTime fixingPeriodEndDate, final Calendar calendar) { super(currency, paymentDate, accrualStartDate, accrualEndDate, paymentAccrualFactor, notional); ArgumentChecker.notNull(index, "CouponArithmeticAverageONDefinition: index"); ArgumentChecker.notNull(fixingPeriodStartDate, "CouponArithmeticAverageONDefinition: fixingPeriodStartDate"); ArgumentChecker.notNull(fixingPeriodEndDate, "CouponArithmeticAverageONDefinition: fixingPeriodEndDate"); ArgumentChecker.isTrue(currency.equals(index.getCurrency()), "Coupon and index currencies are not compatible. Expected to be the same"); _index = index; final List<ZonedDateTime> fixingDateList = new ArrayList<>(); final List<Double> fixingAccrualFactorList = new ArrayList<>(); ZonedDateTime currentDate = fixingPeriodStartDate; fixingDateList.add(currentDate); ZonedDateTime nextDate; while (currentDate.isBefore(fixingPeriodEndDate)) { nextDate = ScheduleCalculator.getAdjustedDate(currentDate, 1, calendar); fixingDateList.add(nextDate); fixingAccrualFactorList.add(index.getDayCount().getDayCountFraction(currentDate, nextDate, calendar)); currentDate = nextDate; } _fixingPeriodDates = fixingDateList.toArray(new ZonedDateTime[fixingDateList.size()]); _fixingPeriodAccrualFactors = ArrayUtils .toPrimitive(fixingAccrualFactorList.toArray(new Double[fixingAccrualFactorList.size()])); }
From source file:henu.dao.impl.CaclDaoImpl.java
@Override public long[] getCaclUserList(String cid) { String sql = "select uid from uc where cid = " + cid; System.out.println(sql);//from w w w .j a v a 2 s.c o m ResultSet rs = SqlDB.executeQuery(sql); List<Long> arraylist = new ArrayList(); try { while (rs.next()) { arraylist.add(rs.getLong("uid")); System.out.println("UID: " + rs.getInt("uid")); } } catch (SQLException ex) { } long[] list = ArrayUtils.toPrimitive(arraylist.toArray(new Long[arraylist.size()])); SqlDB.close(); return list; }
From source file:cysbml.SBMLGraphReader.java
@Override public int[] getNodeIndicesArray() { Integer[] ids = nodeIds.toArray(new Integer[nodeIds.size()]); return ArrayUtils.toPrimitive(ids); }
From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java
/** * Gets the checksum from the given byte array with an instance of. * * @param bytes/*from w ww. j a v a 2s.co m*/ * the Byte object array. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object. * @throws NoSuchAlgorithmException * Is thrown if the algorithm is not supported or does not exists. * {@link java.security.MessageDigest} object. */ public static String getChecksum(Byte[] bytes, String algorithm) throws NoSuchAlgorithmException { return getChecksum(ArrayUtils.toPrimitive(bytes), algorithm); }
From source file:com.opengamma.analytics.financial.instrument.payment.CouponArithmeticAverageONSpreadDefinition.java
/** * Constructor from all the coupon details. * @param currency The payment currency. * @param paymentDate Coupon payment date. * @param accrualStartDate Start date of the accrual period. * @param accrualEndDate End date of the accrual period. * @param paymentYearFraction Accrual factor of the accrual period. * @param notional Coupon notional.// w ww . jav a 2s . co m * @param index The OIS-like index on which the coupon fixes. * @param fixingPeriodStartDate The start date of the fixing period. * @param fixingPeriodEndDate The end date of the fixing period. * @param spread The spread rate paid above the arithmetic average. * @param calendar The holiday calendar for the overnight index. */ public CouponArithmeticAverageONSpreadDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double paymentYearFraction, final double notional, final IndexON index, final ZonedDateTime fixingPeriodStartDate, final ZonedDateTime fixingPeriodEndDate, final double spread, final Calendar calendar) { super(currency, paymentDate, accrualStartDate, accrualEndDate, paymentYearFraction, notional); ArgumentChecker.notNull(index, "CouponOISDefinition: index"); ArgumentChecker.notNull(fixingPeriodStartDate, "CouponOISDefinition: fixingPeriodStartDate"); ArgumentChecker.notNull(fixingPeriodEndDate, "CouponOISDefinition: fixingPeriodEndDate"); ArgumentChecker.isTrue(currency.equals(index.getCurrency()), "Coupon and index currencies are not compatible. Expected to be the same"); _index = index; final List<ZonedDateTime> fixingDateList = new ArrayList<>(); final List<Double> fixingAccrualFactorList = new ArrayList<>(); ZonedDateTime currentDate = fixingPeriodStartDate; fixingDateList.add(currentDate); ZonedDateTime nextDate; while (currentDate.isBefore(fixingPeriodEndDate)) { nextDate = ScheduleCalculator.getAdjustedDate(currentDate, 1, calendar); fixingDateList.add(nextDate); final double af = index.getDayCount().getDayCountFraction(currentDate, nextDate, calendar); fixingAccrualFactorList.add(af); currentDate = nextDate; } _fixingPeriodDates = fixingDateList.toArray(new ZonedDateTime[fixingDateList.size()]); _fixingPeriodAccrualFactors = ArrayUtils .toPrimitive(fixingAccrualFactorList.toArray(new Double[fixingAccrualFactorList.size()])); _spread = spread; _spreadAmount = spread * paymentYearFraction * notional; }
From source file:aldenjava.opticalmapping.data.data.DataNode.java
/** * Constructs a new <code>DataNode</code> based on a boolean array, where {@code true} represents existence of a signal * /*from w w w . j a va 2 s .c o m*/ * @param name * the specified name for this Data * @param zeroOneSeq * the specified boolean array to indicate the label positions */ public DataNode(String name, boolean[] zeroOneSeq) { long size = zeroOneSeq.length; List<Long> refp = new ArrayList<Long>(); for (int i = 0; i < zeroOneSeq.length; i++) { if (zeroOneSeq[i]) refp.add((long) i + 1); } this.name = name; this.size = size; this.refp = ArrayUtils.toPrimitive(refp.toArray(new Long[refp.size()])); this.simuInfo = null; }
From source file:co.cask.tigon.sql.ioserver.OutputServerSocketTest.java
@Test public void testStreamHeaderParser() throws InterruptedException, IOException { String outputName = "output"; GDATEncoder encoder = new GDATEncoder(); encoder.writeLong(3L);/*from w w w . j a v a 2 s .co m*/ encoder.writeString("Hello"); ByteArrayOutputStream out = new ByteArrayOutputStream(); encoder.writeTo(out); byte[] dataBytes = out.toByteArray(); OutputServerSocket outputServerSocket = new OutputServerSocket(serverFacotry, outputName, "SELECT foo FROM bar", new GDATRecordQueue()); outputServerSocket.startAndWait(); InetSocketAddress serverAddress = outputServerSocket.getSocketAddressMap().get(Constants.StreamIO.DATASINK); LOG.info("Server is running at {}", serverAddress); setupClientPipeline(); ChannelFuture future = clientBootstrap.connect(serverAddress); future.await(3, TimeUnit.SECONDS); Channel channel = future.getChannel(); String gdatHeader = new StreamInputHeader(outputName, testSchema).getStreamHeader(); List<Byte> gdatByteList = new ArrayList<Byte>(Bytes.asList(gdatHeader.getBytes(Charsets.UTF_8))); gdatByteList.addAll(new ArrayList<Byte>(Bytes.asList(dataBytes))); int partitionSize = 10; List<List<Byte>> byteChunks = Lists.newArrayList(); for (int i = 0; i < gdatByteList.size(); i += partitionSize) { byteChunks.add(gdatByteList.subList(i, i + Math.min(partitionSize, gdatByteList.size() - i))); } ChannelBuffer buffer; for (List<Byte> chunk : byteChunks) { buffer = ChannelBuffers.wrappedBuffer(ArrayUtils.toPrimitive(chunk.toArray(new Byte[chunk.size()]))); channel.write(buffer).await(); TimeUnit.MILLISECONDS.sleep(10); } TimeUnit.SECONDS.sleep(2); Assert.assertEquals(1, outputServerSocket.getDataRecordsReceived()); }
From source file:com.rapidminer.operator.learner.tree.NonParallelBootstrappingTreeBuilder.java
/** * Create a start selection that is a random selection of rows. This has the same effect as doing a bootstrapping on * the column table./* ww w .ja v a 2 s .com*/ */ @Override protected Map<Integer, int[]> createExampleStartSelection() { Map<Integer, int[]> selection = new HashMap<>(); if (columnTable.getNumberOfRegularNumericalAttributes() == 0) { selection.put(0, createFullRandomArray(columnTable.getNumberOfExamples())); } else { Integer[] bigSelectionArray = createFullBigRandomArray(columnTable.getNumberOfExamples()); for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j); Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length); Arrays.sort(startSelection, Comparator.comparingDouble(a -> attributeColumn[a])); selection.put(j, ArrayUtils.toPrimitive(startSelection)); } } return selection; }
From source file:cysbml.SBMLGraphReader.java
@Override public int[] getEdgeIndicesArray() { Integer[] ids = edgeIds.toArray(new Integer[edgeIds.size()]); return ArrayUtils.toPrimitive(ids); }
From source file:aldenjava.opticalmapping.data.data.OptMapDataReader.java
private DataNode parseREF() throws IOException { if (nextline == null) return null; String[] l = nextline.split("\t"); String name = l[0];/*w ww . j a v a2 s . co m*/ long size = Long.parseLong(l[1]); long refplen = Integer.parseInt(l[2]); proceedNextLine(); if (refplen == 0) return new DataNode(name, size); if (nextline != null) { List<Long> refp = new ArrayList<Long>(); String[] line = nextline.trim().split("\t"); for (int i = 0; i < line.length; i++) refp.add(Long.parseLong(line[i])); if (refplen != refp.size()) System.err.println("Warning: " + name + "\nNumber of labels stated (" + refplen + ") does not match true number of labels (" + refp.size() + ")."); proceedNextLine(); return new DataNode(name, size, ArrayUtils.toPrimitive(refp.toArray(new Long[refp.size()]))); } else { System.err.println("Warning: Incomplete record found: " + name); return null; } }