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:org.cesecore.certificates.certificateprofile.CertificateProfile.java
/** * Used for bitmasks that don't fit in an int. * E.g. the 5-byte bitmask for Authentication Terminals *//*from w w w. j a v a2s .c o m*/ public byte[] getCVCLongAccessRights() { if (data.get(CVCLONGACCESSRIGHTS) == null) { return null; } @SuppressWarnings("unchecked") List<Byte> rightsList = (List<Byte>) data.get(CVCLONGACCESSRIGHTS); return ArrayUtils.toPrimitive(rightsList.toArray(new Byte[0])); }
From source file:org.csstudio.opibuilder.converter.model.EdmPointsList.java
/** * Returns the integer value.//w w w . j a v a 2s .c om * @return Value of EdmInt instance. */ public int[] get() { return ArrayUtils.toPrimitive(val.toArray(new Integer[0])); }
From source file:org.diffkit.diff.conf.DKAutomaticTableComparison.java
/** * maps only columns that have same name on both sides. Uses only columns * that don't participate in the key for diffIndexes. Uses the diff keys for * display/*from w w w. j a va 2 s . c o m*/ */ public static DKStandardTableComparison createDefaultTableComparison(DKTableModel lhsModel_, DKTableModel rhsModel_, Float numberTolerance_, Map<String, Float> toleranceMap_) { DKValidate.notNull(lhsModel_, rhsModel_); DKColumnComparison[] map = createDefaultMap(lhsModel_, rhsModel_, numberTolerance_, toleranceMap_); List<Integer> diffIndexesValue = new ArrayList<Integer>(); if (map != null) { for (int i = 0; i < map.length; i++) { if (!map[i].columnsAreKey()) diffIndexesValue.add(i); } } int[] diffIndexes = ArrayUtils.toPrimitive(diffIndexesValue.toArray(new Integer[diffIndexesValue.size()])); int[][] displayIndexes = new int[2][]; displayIndexes[DKSide.LEFT_INDEX] = lhsModel_.getKey(); displayIndexes[DKSide.RIGHT_INDEX] = rhsModel_.getKey(); return new DKStandardTableComparison(lhsModel_, rhsModel_, DKDiff.Kind.BOTH, map, diffIndexes, displayIndexes, Long.MAX_VALUE); }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") public static void runEvaluationMetric(Mode mode, EvaluationMetric metric, Dataset... datasets) throws IOException { StringBuilder sb = new StringBuilder(); // Compute Pearson correlation for the specified datasets for (Dataset dataset : datasets) { computePearsonCorrelation(mode, dataset); }/*from w ww. ja va 2 s . c o m*/ if (metric == PearsonAll) { List<Double> concatExp = new ArrayList<Double>(); List<Double> concatGS = new ArrayList<Double>(); // Concat the scores for (Dataset dataset : datasets) { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); List<String> lines = FileUtils.readLines(expScoresFile); for (String line : lines) { concatExp.add(Double.parseDouble(line)); } } // Concat the gold standard for (Dataset dataset : datasets) { String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<String> lines = FileUtils.readLines(gsScoresFile); for (String line : lines) { concatGS.add(Double.parseDouble(line)); } } double[] concatExpArray = ArrayUtils.toPrimitive(concatExp.toArray(new Double[concatExp.size()])); double[] concatGSArray = ArrayUtils.toPrimitive(concatGS.toArray(new Double[concatGS.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(concatExpArray, concatGSArray); sb.append(correl.toString()); } else if (metric == PearsonMean) { List<Double> scores = new ArrayList<Double>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); scores.add(score); } double mean = 0.0; for (Double score : scores) { mean += score; } mean = mean / scores.size(); sb.append(mean); } else if (metric == PearsonWeightedMean) { List<Double> scores = new ArrayList<Double>(); List<Integer> weights = new ArrayList<Integer>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); File scoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); int weight = FileUtils.readLines(scoresFile).size(); scores.add(score); weights.add(weight); } double mean = 0.0; int weightsum = 0; for (int i = 0; i < scores.size(); i++) { Double score = scores.get(i); Integer weight = weights.get(i); mean += weight * score; weightsum += weight; } mean = mean / weightsum; sb.append(mean); } FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + metric.toString() + ".txt"), sb.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }/*from www. ja va 2 s .co m*/ double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
public static void runEvaluationMetric(Mode mode, EvaluationMetric metric, Dataset... datasets) throws IOException { StringBuilder sb = new StringBuilder(); // Compute Pearson correlation for the specified datasets for (Dataset dataset : datasets) { computePearsonCorrelation(mode, dataset); }//from ww w . j a v a 2s . co m if (metric == PearsonAll) { List<Double> concatExp = new ArrayList<Double>(); List<Double> concatGS = new ArrayList<Double>(); // Concat the scores for (Dataset dataset : datasets) { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); List<String> lines = FileUtils.readLines(expScoresFile); for (String line : lines) { concatExp.add(Double.parseDouble(line)); } } // Concat the gold standard for (Dataset dataset : datasets) { String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<String> lines = FileUtils.readLines(gsScoresFile); for (String line : lines) { concatGS.add(Double.parseDouble(line)); } } double[] concatExpArray = ArrayUtils.toPrimitive(concatExp.toArray(new Double[concatExp.size()])); double[] concatGSArray = ArrayUtils.toPrimitive(concatGS.toArray(new Double[concatGS.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(concatExpArray, concatGSArray); sb.append(correl.toString()); } else if (metric == PearsonMean) { List<Double> scores = new ArrayList<Double>(); for (Dataset dataset : datasets) { File resultFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"); double score = Double.parseDouble(FileUtils.readFileToString(resultFile)); scores.add(score); } double mean = 0.0; for (Double score : scores) { mean += score; } mean = mean / scores.size(); sb.append(mean); } FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + metric.toString() + ".txt"), sb.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }// ww w .j a v a 2s .c o m double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.dragonet.net.DragonetSession.java
private synchronized void sendAllACK() { if (this.queueACK.isEmpty()) { return;// w w w . jav a 2 s . com } int[] ackSeqs = ArrayUtils.toPrimitive(this.queueACK.toArray(new Integer[0])); Arrays.sort(ackSeqs); this.queueACK.clear(); ByteArrayOutputStream allRecBos = new ByteArrayOutputStream(); PEBinaryWriter allRecWriter = new PEBinaryWriter(allRecBos); try { int count = ackSeqs.length; int records = 0; if (count > 0) { int pointer = 1; int start = ackSeqs[0]; int last = ackSeqs[0]; ByteArrayOutputStream recBos = new ByteArrayOutputStream(); PEBinaryWriter recWriter; while (pointer < count) { int current = ackSeqs[pointer++]; int diff = current - last; if (diff == 1) { last = current; } else if (diff > 1) { //Forget about duplicated packets (bad queues?) recBos.reset(); recWriter = new PEBinaryWriter(recBos); if (start == last) { recWriter.writeByte((byte) 0x01); recWriter.writeTriad(start); start = last = current; } else { recWriter.writeByte((byte) 0x00); recWriter.writeTriad(start); recWriter.writeTriad(last); start = last = current; } records++; } } if (start == last) { allRecWriter.writeByte((byte) 0x01); allRecWriter.writeTriad(start); } else { allRecWriter.writeByte((byte) 0x00); allRecWriter.writeTriad(start); allRecWriter.writeTriad(last); } records++; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); PEBinaryWriter writer = new PEBinaryWriter(bos); writer.writeByte((byte) 0xC0); writer.writeShort((short) (records & 0xFFFF)); writer.write(allRecBos.toByteArray()); this.dServer.getNetworkHandler().send(bos.toByteArray(), this.remoteAddress); } catch (IOException e) { } }
From source file:org.dragonet.net.DragonetSession.java
private synchronized void sendAllNACK() { if (this.queueNACK.isEmpty()) { return;/*from w w w . ja va2 s. co m*/ } int[] ackSeqs = ArrayUtils.toPrimitive(this.queueNACK.toArray(new Integer[0])); Arrays.sort(ackSeqs); this.queueNACK.clear(); ByteArrayOutputStream allRecBos = new ByteArrayOutputStream(); PEBinaryWriter allRecWriter = new PEBinaryWriter(allRecBos); try { int count = ackSeqs.length; int records = 0; if (count > 0) { int pointer = 1; int start = ackSeqs[0]; int last = ackSeqs[0]; ByteArrayOutputStream recBos = new ByteArrayOutputStream(); PEBinaryWriter recWriter; while (pointer < count) { int current = ackSeqs[pointer++]; int diff = current - last; if (diff == 1) { last = current; } else if (diff > 1) { //Forget about duplicated packets (bad queues?) recBos.reset(); recWriter = new PEBinaryWriter(recBos); if (start == last) { recWriter.writeByte((byte) 0x01); recWriter.writeTriad(start); start = last = current; } else { recWriter.writeByte((byte) 0x00); recWriter.writeTriad(start); recWriter.writeTriad(last); start = last = current; } records++; } } if (start == last) { allRecWriter.writeByte((byte) 0x01); allRecWriter.writeTriad(start); } else { allRecWriter.writeByte((byte) 0x00); allRecWriter.writeTriad(start); allRecWriter.writeTriad(last); } records++; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); PEBinaryWriter writer = new PEBinaryWriter(bos); writer.writeByte((byte) 0xA0); writer.writeShort((short) (records & 0xFFFF)); writer.write(allRecBos.toByteArray()); this.dServer.getNetworkHandler().send(bos.toByteArray(), this.remoteAddress); } catch (IOException e) { } }
From source file:org.dragonet.net.DragonetSession.java
/** * Process a ACK packet/*from ww w . jav a2s.c o m*/ * * @param buffer The ACK packet binary array */ public void processACKPacket(byte[] buffer) { try { PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(buffer)); int count = reader.readShort(); List<Integer> packets = new ArrayList<>(); for (int i = 0; i < count && reader.available() > 0; ++i) { byte[] tmp = new byte[6]; if (reader.readByte() == (byte) 0x00) { int start = reader.readTriad(); int end = reader.readTriad(); if ((end - start) > 4096) { end = start + 4096; } for (int c = start; c <= end; ++c) { packets.add(c); } } else { packets.add(reader.readTriad()); } } int[] seqNums = ArrayUtils.toPrimitive(packets.toArray(new Integer[0])); for (int seq : seqNums) { if (this.cachedOutgoingPacket.containsKey(seq)) { this.cachedOutgoingPacket.remove(seq); } } } catch (IOException e) { } }