List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:io.cloudslang.lang.compiler.Extension.java
public static String[] getSlangFileExtensionValues() { return Arrays.copyOfRange(extensionValues, 0, 3); }
From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java
public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption("r", "ref-seq", true, "Trim points are given as positions in a reference sequence from this file"); options.addOption("i", "inclusive", false, "Trim points are inclusive"); options.addOption("l", "length", true, "Minimum length of sequence after trimming"); options.addOption("f", "filled-ratio", true, "Minimum ratio of filled model positions of sequence after trimming"); options.addOption("o", "out", true, "Write sequences to directory (default=cwd)"); options.addOption("s", "stats", true, "Write stats to file"); PrintWriter statsOut = new PrintWriter(new NullWriter()); boolean inclusive = false; int minLength = 0; int minTrimmedLength = 0; int maxNs = 0; int maxTrimNs = 0; int trimStart = 0; int trimStop = 0; Sequence refSeq = null;/*from w w w .j a v a 2 s . c o m*/ float minFilledRatio = 0; int expectedModelPos = -1; String[] inputFiles = null; File outdir = new File("."); try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("ref-seq")) { refSeq = readRefSeq(new File(line.getOptionValue("ref-seq"))); } if (line.hasOption("inclusive")) { inclusive = true; } if (line.hasOption("length")) { minLength = Integer.valueOf(line.getOptionValue("length")); } if (line.hasOption("filled-ratio")) { minFilledRatio = Float.valueOf(line.getOptionValue("filled-ratio")); } if (line.hasOption("out")) { outdir = new File(line.getOptionValue("out")); if (!outdir.isDirectory()) { outdir = outdir.getParentFile(); System.err.println("Output option is not a directory, using " + outdir + " instead"); } } if (line.hasOption("stats")) { statsOut = new PrintWriter(line.getOptionValue("stats")); } args = line.getArgs(); if (args.length < 3) { throw new Exception("Unexpected number of arguments"); } trimStart = Integer.parseInt(args[0]); trimStop = Integer.parseInt(args[1]); inputFiles = Arrays.copyOfRange(args, 2, args.length); if (refSeq != null) { expectedModelPos = SeqUtils.getMaskedBySeqString(refSeq.getSeqString()).length(); trimStart = translateCoord(trimStart, refSeq, CoordType.seq, CoordType.model); trimStop = translateCoord(trimStop, refSeq, CoordType.seq, CoordType.model); } } catch (Exception e) { new HelpFormatter().printHelp("SequenceTrimmer <trim start> <trim stop> <aligned file> ...", options); System.err.println("Error: " + e.getMessage()); } System.err.println("Starting sequence trimmer"); System.err.println("* Input files: " + Arrays.asList(inputFiles)); System.err.println("* Minimum Length: " + minLength); System.err.println("* Trim point inclusive?: " + inclusive); System.err.println("* Trim points: " + trimStart + "-" + trimStop); System.err.println("* Min filled ratio: " + minFilledRatio); System.err.println("* refSeq: " + ((refSeq == null) ? "model" : refSeq.getSeqName() + " " + refSeq.getDesc())); Sequence seq; SeqReader reader; TrimStats stats; writeStatsHeader(statsOut); FastaWriter seqWriter; File in; for (String infile : inputFiles) { in = new File(infile); reader = new SequenceReader(in); seqWriter = new FastaWriter(new File(outdir, "trimmed_" + in.getName())); while ((seq = reader.readNextSequence()) != null) { if (seq.getSeqName().startsWith("#")) { seqWriter.writeSeq(seq.getSeqName(), "", trimMetaSeq(seq.getSeqString(), trimStart, trimStop)); continue; } stats = getStats(seq, trimStart, trimStop); boolean passed = didSeqPass(stats, minLength, minTrimmedLength, maxNs, maxTrimNs, minFilledRatio); writeStats(statsOut, seq.getSeqName(), stats, passed); if (passed) { seqWriter.writeSeq(seq.getSeqName(), seq.getDesc(), new String(stats.trimmedBases)); } } reader.close(); seqWriter.close(); } statsOut.close(); }
From source file:com.codebutler.farebot.key.ClassicCardKeys.java
public static ClassicCardKeys fromDump(String keyType, byte[] keyData) { List<ClassicSectorKey> keys = new ArrayList<>(); int numSectors = keyData.length / KEY_LEN; for (int i = 0; i < numSectors; i++) { int start = i * KEY_LEN; keys.add(new ClassicSectorKey(keyType, Arrays.copyOfRange(keyData, start, start + KEY_LEN))); }//from ww w . ja va2 s .com return new ClassicCardKeys(keys.toArray(new ClassicSectorKey[keys.size()])); }
From source file:io.cloudslang.lang.compiler.Extension.java
public static Extension[] getSlangFileExtensions() { return Arrays.copyOfRange(values(), 0, 3); }
From source file:com.codebutler.farebot.keys.ClassicCardKeys.java
public static ClassicCardKeys fromDump(String keyType, byte[] keyData) { List<ClassicSectorKey> keys = new ArrayList<ClassicSectorKey>(); int numSectors = keyData.length / KEY_LEN; for (int i = 0; i < numSectors; i++) { int start = i * KEY_LEN; keys.add(new ClassicSectorKey(keyType, Arrays.copyOfRange(keyData, start, start + KEY_LEN))); }/* www.j ava2 s . c o m*/ return new ClassicCardKeys(keys.toArray(new ClassicSectorKey[keys.size()])); }
From source file:io.cloudslang.lang.compiler.Extension.java
public static String[] getPropertiesFileExtensionValues() { return Arrays.copyOfRange(extensionValues, 3, 4); }
From source file:mongodb.MongoUtils.java
public static void construct(Document doc, String attribut, Object valeur) { if (!attribut.contains(".")) { doc.append(attribut, valeur);// www. jav a 2 s . c o m } else { String[] parties = attribut.split("\\."); if (doc.get(parties[0]) == null) doc.append(parties[0], new Document()); construct((Document) doc.get(parties[0]), StringUtils.join(Arrays.copyOfRange(parties, 1, parties.length), "."), valeur); } }
From source file:Main.java
/** * Copies elements from original into a new array, from indexes start (inclusive) to end (exclusive). * The original order of elements is preserved. If end is greater than original.length, * the result is padded with the value null. * @param orig the original array// w w w . ja v a 2 s . c om * @param start the start index, inclusive * @param end the end index, exclusive * @return the new array */ @SuppressLint("NewApi") public static String[] copyOfRange(String[] orig, int start, int end) { int curVersion = android.os.Build.VERSION.SDK_INT; if (curVersion < Build.VERSION_CODES.GINGERBREAD) { String[] res = new String[end - start]; for (int i = 0; i < res.length; i++) { res[i] = orig[i + start]; } return res; } else { return Arrays.copyOfRange(orig, start, end); } }
From source file:com.naver.divideandconquer.closestpair.ClosestPair.java
public Pair calculate(Point[] points, int start, int end) { if (end - start < 3) { if (end - start == 2) { return calculateAllCaseClosestPair(Arrays.copyOfRange(points, start, end)); }//from www .j a v a 2 s .com Pair pair = new Pair(points[start], points[end], calculateDistance(points[start], points[end])); return pair; } int mid = (start + end) / 2; Pair leftPir = calculate(points, start, mid); Pair rigthPair = calculate(points, mid, end); Pair minPair = leftPir.getDistance() < rigthPair.getDistance() ? leftPir : rigthPair; Pair centerClosestPair = getCenterClosestPair(Arrays.copyOfRange(points, start, end), minPair.getDistance()); if (centerClosestPair != null) { return centerClosestPair.getDistance() < minPair.getDistance() ? centerClosestPair : minPair; } return minPair; }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.feature.InstanceIdFeature.java
public static Feature retrieve(JCas jcas, TextClassificationUnit unit) { String fullId = DocumentMetaData.get(jcas).getDocumentId(); String[] parts = fullId.split("_"); fullId = StringUtils.join(Arrays.copyOfRange(parts, 0, parts.length - 1), "_"); fullId = fullId + "_" + unit.getId(); String suffix = unit.getSuffix(); if (suffix != null && suffix.length() > 0) { fullId = fullId + "_" + suffix; }// w w w . j ava 2 s .c o m return new Feature(ID_FEATURE_NAME, fullId); }