List of usage examples for org.apache.commons.lang3.tuple MutablePair getLeft
@Override
public L getLeft()
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public void trim() { for (Iterator<Entry<String, MutablePair<String, CommentsNodeImpl>>> iterator = this.dataMap.entrySet() .iterator(); iterator.hasNext();) { Entry<String, MutablePair<String, CommentsNodeImpl>> entry = iterator.next(); MutablePair<String, CommentsNodeImpl> value = entry.getValue(); CommentsNodeImpl right = value.getRight(); if (right != null) { right.trim();// ww w. ja va 2 s . co m } if (((right == null) || right.dataMap.isEmpty()) && (value.getLeft() == null)) { iterator.remove(); continue; } if (right == null) { continue; } right.trim(); } }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@SuppressWarnings("unchecked") Map<String, MutablePair<String, ?>> buildMap() { Map<String, MutablePair<String, ?>> resultMap = new LinkedHashMap<>(this.dataMap.size()); for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet()) { MutablePair<String, CommentsNodeImpl> value = entry.getValue(); CommentsNodeImpl right = value.getRight(); String left = value.getLeft(); if ((right == null) && (left == null)) { continue; }// ww w . j a v a 2s . c o m Map<String, MutablePair<String, ?>> rightMap = null; if (right != null) { rightMap = right.buildMap(); if (rightMap.isEmpty()) { rightMap = null; if (left == null) { continue; } } } resultMap.put(entry.getKey(), new MutablePair<>(left, rightMap)); } return resultMap; }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public void join(CommentsNode toJoin_) { if (toJoin_ instanceof EmptyCommentsNode) { return;/*from www.j a v a2s. co m*/ } if (!(toJoin_ instanceof CommentsNodeImpl)) { throw new IllegalArgumentException("Can't join to unknown node type."); } CommentsNodeImpl toJoin = (CommentsNodeImpl) toJoin_; for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : toJoin.dataMap.entrySet()) { String nodeKey = entry.getKey(); MutablePair<String, CommentsNodeImpl> pair = entry.getValue(); String nodeComment = pair.getLeft(); CommentsNodeImpl subNode = pair.getRight(); if (nodeComment != null) { this.setComment(nodeKey, nodeComment); } if (subNode != null) { this.join(nodeKey, subNode); } } }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override @Nullable//from w w w.j a v a 2s .c o m public String getComment(String path) { MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path); if (nodePair != null) { String comment = nodePair.getLeft(); if (comment != null) { return comment; } } MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY); if (anyNodePair != null) { return anyNodePair.getKey(); } return null; }
From source file:org.diorite.config.serialization.comments.CommentsWriter.java
@SuppressWarnings("unchecked") private void write(Map<String, MutablePair<String, ?>> map) throws IOException { this.updateIndent(true); int keys = map.entrySet().size(); int k = 0;/* w w w .j av a2s . c o m*/ for (Entry<String, MutablePair<String, ?>> entry : map.entrySet()) { k += 1; MutablePair<String, ?> pair = entry.getValue(); String comment = pair.getLeft(); Map<String, MutablePair<String, ?>> rightMap = (Map<String, MutablePair<String, ?>>) pair.getRight(); int rightKeys = (rightMap == null) ? 0 : rightMap.size(); boolean newLine = keys > 3; if (comment != null) { this.writeComment(comment); } String key = entry.getKey(); this.writeKey(key); if (rightMap != null) { this.write(rightMap); } if (newLine) { this.writeNewLine(false); } } this.writeNewLine(false); this.updateIndent(false); }
From source file:org.openlmis.fulfillment.Resource2Db.java
Pair<List<String>, List<Object[]>> resourceCsvToBatchedPair(final Resource resource) throws IOException { XLOGGER.entry(resource.getDescription()); // parse CSV/* w ww . j av a 2 s . c o m*/ try (InputStreamReader isReader = new InputStreamReader( new BOMInputStream(resource.getInputStream(), ByteOrderMark.UTF_8))) { CSVParser parser = CSVFormat.DEFAULT.withHeader().withNullString("").parse(isReader); // read header row MutablePair<List<String>, List<Object[]>> readData = new MutablePair<>(); readData.setLeft(new ArrayList<>(parser.getHeaderMap().keySet())); XLOGGER.info("Read header: " + readData.getLeft()); // read data rows List<Object[]> rows = new ArrayList<>(); for (CSVRecord record : parser.getRecords()) { if (!record.isConsistent()) { throw new IllegalArgumentException("CSV record inconsistent: " + record); } List theRow = IteratorUtils.toList(record.iterator()); rows.add(theRow.toArray()); } readData.setRight(rows); XLOGGER.exit("Records read: " + readData.getRight().size()); return readData; } }
From source file:org.opentestsystem.shared.test.cooperation.StageImpl.java
@Override public synchronized void sayCue(Cue cue) { if (cue.isRetained()) { _retainedCues.add(cue);//from w w w.j a va 2s. com } // Pump cue into waiting queues for (ImmutablePair<CuePattern, Queue<Cue>> pair_i : _listeningQueues) { if (pair_i.getLeft().isMatch(cue)) { if (!pair_i.getRight().offer(cue)) { _logger.warn("Cue {} rejected by listening queue", cue.getTag()); } } } // Call callbacks in this thread. for (ImmutablePair<CuePattern, CueCallback> pair_i : _callbacks) { if (pair_i.getLeft().isMatch(cue)) { try { pair_i.getRight().onCue(cue); } catch (Throwable t) { _logger.error("Error raised processing cue callbacks on cue {}", cue.getTag(), t); } } } // Find threads waiting on this cue boolean found = false; int i = 0; while (i < _waitingPatterns.size()) { MutablePair<CuePattern, Cue> pr_i = _waitingPatterns.get(i); if (pr_i.getLeft().isMatch(cue)) { pr_i.setRight(cue); _waitingPatterns.remove(i); found = true; } else { i++; } } // Give found threads a chance to run if (found) { notifyAll(); } }
From source file:org.shaman.terrain.sketch.Graph.java
public void setEdgeWeight(int u, int v, float weight) { ArrayList<MutablePair<Integer, Float>> n1 = graph.get(u); ArrayList<MutablePair<Integer, Float>> n2 = graph.get(v); for (MutablePair<Integer, Float> p : n1) { if (p.getLeft() == v) { p.setRight(weight);/*from www .ja v a2 s .c o m*/ break; } } for (MutablePair<Integer, Float> p : n2) { if (p.getLeft() == u) { p.setRight(weight); break; } } }
From source file:org.shaman.terrain.sketch.Graph.java
@Override public Iterator<Triple<Integer, Integer, Float>> iterator() { return new Iterator<Triple<Integer, Integer, Float>>() { Triple<Integer, Integer, Float> current = null; private int u = 0; private int v = 0; @Override/*from w w w . j a v a 2 s . c o m*/ public boolean hasNext() { while (true) { if (u == graph.size()) { return false; } ArrayList<MutablePair<Integer, Float>> n = graph.get(u); if (v == n.size()) { v = 0; u++; continue; } MutablePair<Integer, Float> p = n.get(v); v++; if (p.getLeft() > u) { current = new ImmutableTriple<>(u, p.getLeft(), p.getRight()); return true; } } } @Override public Triple<Integer, Integer, Float> next() { return current; } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; }
From source file:org.shaman.terrain.sketch.Graph.java
boolean isCyclicUtil(int v, boolean visited[], int parent) { // Mark the current node as visited visited[v] = true;/*from w w w . j a v a2s. com*/ // Recur for all the vertices adjacent to this vertex for (MutablePair<Integer, Float> p : graph.get(v)) { int i = p.getLeft(); if (!visited[i]) { if (isCyclicUtil(i, visited, parent)) { return true; } else if (i != parent) { return true; } } } return false; }