List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:com.itemanalysis.psychometrics.irt.model.IrmPCM.java
private double numer(double theta, double[] iparam, int category, double D) { double Zk = 0; double b = iparam[0]; double[] s = Arrays.copyOfRange(iparam, 1, iparam.length); //first category Zk = D * (theta - b);/*w w w. j a v a 2s.c om*/ for (int k = 0; k < category; k++) { Zk += D * (theta - b - s[k]); } return Math.exp(Zk); }
From source file:nu.yona.server.messaging.entities.MessageSource.java
private PrivateKey loadPrivateKey() { if (privateKey == null) { privateKey = PublicKeyUtil/*www .jav a2s . co m*/ .privateKeyFromBytes(Arrays.copyOfRange(privateKeyBytes, 1, privateKeyBytes.length)); } return privateKey; }
From source file:com.blockwithme.longdb.leveldb.Util.java
/** Split column ids. * /*from w w w .java 2s . c o m*/ * @param theColumns * the all columns * @return the long array list */ @CheckForNull public static LongArrayList splitColumnIds(final byte[] theColumns) { if (theColumns == null || theColumns.length == 0) return null; long offset = 0; final LongArrayList colIds = new LongArrayList(); while (offset + LONG_BYTES <= theColumns.length) { final long colId = Util .toLong(Arrays.copyOfRange(theColumns, (int) offset, (int) (offset + LONG_BYTES))); colIds.add(colId); offset += LONG_BYTES; } return colIds; }
From source file:com.netflix.bdp.s3mper.cli.S3mper.java
private String[] popArg(String[] args) { if (args.length == 1) { return new String[0]; }//from ww w . j a va 2 s . c om return Arrays.copyOfRange(args, 1, args.length); }
From source file:com.milaboratory.core.io.sequence.fasta.FastaReaderTest.java
private static TestItem createTestData(long seed, int readsCount, boolean withWildcards) throws IOException { Well1024a rnd = new Well1024a(seed); File tempFile = File.createTempFile("temp" + seed, ".fasta"); tempFile.deleteOnExit();//from w w w . j a va 2 s . c om FileOutputStream output = new FileOutputStream(tempFile); SingleRead[] reads = new SingleRead[readsCount]; WildcardSymbol[] wildcards = NucleotideSequence.ALPHABET.getAllWildcards().toArray(new WildcardSymbol[0]); long id = 0; for (int i = 0; i < readsCount; ++i) { char[] seq = new char[50 + rnd.nextInt(100)]; char[] seqExp = new char[seq.length]; int qPointer = 0; byte[] qualityData = new byte[seq.length]; Arrays.fill(qualityData, SequenceQuality.GOOD_QUALITY_VALUE); for (int j = 0; j < seq.length; ++j) { seq[j] = seqExp[j] = NucleotideSequence.ALPHABET.symbolFromCode((byte) rnd.nextInt(4)); if (j != 0 && j != seq.length - 1 && ((4 * j) % seq.length == 0) && rnd.nextBoolean()) { //next line for sequence seq[j] = seqExp[j] = '\n'; --qPointer; } else if (withWildcards && j % 5 == 0) {//wildcard WildcardSymbol wildcard = wildcards[rnd.nextInt(wildcards.length)]; if (NucleotideSequence.ALPHABET.codeFromSymbol(wildcard.getSymbol()) == -1) { seq[j] = wildcard.getSymbol(); seqExp[j] = NucleotideSequence.ALPHABET .symbolFromCode(wildcard.getUniformlyDistributedSymbol(id ^ (j + qPointer)));//as used in FastaReader#getSequenceWithQuality(..) qualityData[j + qPointer] = SequenceQuality.BAD_QUALITY_VALUE; } } } String description = ">seq" + i; String sequenceString = new String(seq); output.write(description.getBytes()); output.write('\n'); output.write(sequenceString.getBytes()); output.write('\n'); reads[i] = new SingleReadImpl(id, new NSequenceWithQuality(new NucleotideSequence(new String(seqExp).replace("\n", "")), new SequenceQuality(Arrays.copyOfRange(qualityData, 0, seq.length + qPointer))), description.substring(1)); ++id; } output.close(); return new TestItem(tempFile, reads); }
From source file:com.kakao.hbase.common.Args.java
public Args(String[] args) throws IOException { OptionSet optionSetTemp = createOptionParser().parse(args); List<?> nonOptionArguments = optionSetTemp.nonOptionArguments(); if (nonOptionArguments.size() < 1) throw new IllegalArgumentException(INVALID_ARGUMENTS); String arg = (String) nonOptionArguments.get(0); if (Util.isFile(arg)) { String[] newArgs = (String[]) ArrayUtils.addAll(parseArgsFile(arg), Arrays.copyOfRange(args, 1, args.length)); this.optionSet = createOptionParser().parse(newArgs); this.zookeeperQuorum = (String) optionSet.nonOptionArguments().get(0); } else {// w ww .j a v a 2s . co m this.optionSet = optionSetTemp; this.zookeeperQuorum = arg; } }
From source file:com.yahoo.pulsar.admin.cli.PulsarAdminTool.java
boolean run(String[] args) { if (args.length == 0) { jcommander.usage();/*from ww w .j ava2s. co m*/ return false; } try { jcommander.parse(new String[] { args[0] }); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(); jcommander.usage(); return false; } if (help) { jcommander.usage(); return false; } if (jcommander.getParsedCommand() == null) { jcommander.usage(); return false; } else { String cmd = jcommander.getParsedCommand(); JCommander obj = jcommander.getCommands().get(cmd); CmdBase cmdObj = (CmdBase) obj.getObjects().get(0); return cmdObj.run(Arrays.copyOfRange(args, 1, args.length)); } }
From source file:bb.mcmc.analysis.GewekeConvergeStat.java
@Override protected double calculateEachStat(String key) { final double[] t = traceValues.get(key); final int length = t.length; final int indexStart = (int) Math.floor(length * (1 - frac2)); final int indexEnd = (int) Math.ceil(length * frac1); final double[] dStart = Arrays.copyOfRange(t, 0, indexEnd); final double[] dEnd = Arrays.copyOfRange(t, indexStart, length); final double meanStart = DiscreteStatistics.mean(dStart); final double meanEnd = DiscreteStatistics.mean(dEnd); final double varStart = ConvergeStatUtils.spectrum0(dStart) / dStart.length; final double varEnd = ConvergeStatUtils.spectrum0(dEnd) / dEnd.length; final double bothVar = varStart + varEnd; double stat = (meanStart - meanEnd) / Math.sqrt(bothVar); if (Double.isNaN(stat)) { //Use two separate if to handle other NaN cases later if (Double.isNaN(bothVar)) { stat = Double.NEGATIVE_INFINITY; System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + ". This is due to logged values being unchanged during the run");//. Check log file for details. "); }/*from w w w . j a va 2 s .co m*/ } return stat; }
From source file:org.psit.transwatcher.TransWatcher.java
@Override public void run() { try {//from w ww. j a va 2 s .c o m while (true) { String cardIP = connectAndGetCardIP(); if (cardIP != null) { notifyMessage("Found SD card, IP: " + cardIP); // handshake successful, open permanent TCP connection // to listen to new images Socket newImageListenerSocket = null; try { newImageListenerSocket = new Socket(cardIP, 5566); newImageListenerSocket.setKeepAlive(true); InputStream is = newImageListenerSocket.getInputStream(); byte[] c = new byte[1]; byte[] singleMessage = new byte[255]; int msgPointer = 0; startConnectionKeepAliveWatchDog(newImageListenerSocket); startImageDownloaderQueue(cardIP); setState(State.LISTENING); // loop to wait for new images while (newImageListenerSocket.isConnected()) { if (is.read(c) == 1) { if (0x3E == c[0]) { // > // start of filename msgPointer = 0; } else if (0x00 == c[0]) { // end of filename String msg = new String(Arrays.copyOfRange(singleMessage, 0, msgPointer)); notifyMessage("Image shot: " + msg); // add to download queue queue.add(msg); } else { // single byte. add to buffer singleMessage[msgPointer++] = c[0]; } } } setState(State.SEARCHING_CARD); } catch (IOException e) { notifyMessage("Error during image notification connection!"); } finally { try { newImageListenerSocket.close(); } catch (Exception e) { e.printStackTrace(); } } } else { notifyMessage("No card found, retrying."); } Thread.sleep(2000); } } catch (InterruptedException e) { stopImageDownLoaderQueue(); notifyMessage("Connection abandoned."); } }
From source file:duthientan.mmanm.com.CipherRSA.java
@Override public void decrypt(String filePath) { try {/*from w w w .j a v a 2s .co m*/ Cipher decipher = Cipher.getInstance("RSA"); decipher.init(Cipher.DECRYPT_MODE, privateKey); Path path = Paths.get(filePath); String decryptFilePath = filePath.replace("RSA" + "_", ""); byte[] data = Files.readAllBytes(path); byte[] textDncrypted = null; int chunkSize = 256; if (data.length < 256) { textDncrypted = decipher.doFinal(data); } else { for (int i = 0; i < data.length; i += chunkSize) { byte[] segment = Arrays.copyOfRange(data, i, i + chunkSize > data.length ? data.length : i + chunkSize); byte[] segmentEncrypted = decipher.doFinal(segment); textDncrypted = ArrayUtils.addAll(textDncrypted, segmentEncrypted); } } FileOutputStream fos = new FileOutputStream(decryptFilePath); fos.write(textDncrypted); fos.close(); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchPaddingException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidKeyException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalBlockSizeException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } catch (BadPaddingException ex) { Logger.getLogger(CipherRSA.class.getName()).log(Level.SEVERE, null, ex); } }