List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:PathUtils.java
/** * Calculates the relative path between a specified root directory and a target path. * * @param root The absolute path of the root directory. * @param target The path to the target file or directory. * @return The relative path between the specified root directory and the target path. * @throws IllegalArgumentException <ul><li>The root file cannot be null.</li><li>The target cannot be * null.</li><li>The root file must be a directory.</li><li>The root file must be * absolute.</li></ul> *///from w w w.ja v a2s. co m public static String relativize(final File root, final File target) throws IllegalArgumentException { if (root == null) throw new IllegalArgumentException("The root file cannot be null."); if (target == null) throw new IllegalArgumentException("The target cannot be null."); if (!root.isDirectory()) throw new IllegalArgumentException("The root file must be a directory."); if (!root.isAbsolute()) throw new IllegalArgumentException("The root file must be absolute."); if (!target.isAbsolute()) return target.toString(); if (root.equals(target)) return "."; // Deconstruct hierarchies final Deque<File> rootHierarchy = new ArrayDeque<File>(); for (File f = root; f != null; f = f.getParentFile()) rootHierarchy.push(f); final Deque<File> targetHierarchy = new ArrayDeque<File>(); for (File f = target; f != null; f = f.getParentFile()) targetHierarchy.push(f); // Trace common root while (rootHierarchy.size() > 0 && targetHierarchy.size() > 0 && rootHierarchy.peek().equals(targetHierarchy.peek())) { rootHierarchy.pop(); targetHierarchy.pop(); } // Create relative path final StringBuilder sb = new StringBuilder(rootHierarchy.size() * 3 + targetHierarchy.size() * 32); while (rootHierarchy.size() > 0) { sb.append(".."); rootHierarchy.pop(); if (rootHierarchy.size() > 0 || targetHierarchy.size() > 0) sb.append(File.separator); } while (targetHierarchy.size() > 0) { sb.append(targetHierarchy.pop().getName()); if (targetHierarchy.size() > 0) sb.append(File.separator); } return sb.toString(); }
From source file:org.dragonet.net.ClientChunkManager.java
public ClientChunkManager(DragonetSession session) { this.session = session; this.chunksLoaded = new ArrayList<>(); this.chunksQueue = new ArrayDeque<>(); }
From source file:com.yoncabt.ebr.jdbcbridge.pool.DataSource.java
public DataSource(String name) throws SQLException { this.standBy = new ArrayDeque<>(); this.used = new ArrayDeque<>(); this.name = name; driver = EBRConf.INSTANCE.getValue("report.datasource." + name + ".driver", ""); if (StringUtils.isEmpty(driver)) { throw new IllegalArgumentException(name + " driver not found"); }//from www . j a v a 2s . co m url = EBRConf.INSTANCE.getValue("report.datasource." + name + ".url", ""); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(name + " url not found"); } user = EBRConf.INSTANCE.getValue("report.datasource." + name + ".user", ""); if (StringUtils.isEmpty(user)) { throw new IllegalArgumentException(name + " user not found"); } pass = EBRConf.INSTANCE.getValue("report.datasource." + name + ".pass", ""); if (StringUtils.isEmpty(pass)) { throw new IllegalArgumentException(name + " pass not found"); } minPool = EBRConf.INSTANCE.getValue("report.datasource." + name + ".minPool", 5); maxPool = EBRConf.INSTANCE.getValue("report.datasource." + name + ".maxPool", 50); connectionCheckQuery = EBRConf.INSTANCE.getValue("report.datasource." + name + ".connectionCheckQuery", ""); try { initPool(); } catch (SQLException ex) { logManager.error("ignoring connection error for startup", ex); } }
From source file:br.usp.poli.lta.cereda.aa.model.Stack.java
/** * Construtor. Inicializa a pilha. */ public Stack() { stack = new ArrayDeque<>(); }
From source file:com.tussle.script.StackedBindings.java
public StackedBindings(Map<String, Object> startValues) { bindingStack = new ArrayDeque<>(); bindingMap = new HashMap<>(); bindingStack.push(new SimpleBindings(startValues)); for (Map.Entry<String, Object> entry : startValues.entrySet()) { ArrayDeque<Object> toPut = new ArrayDeque<>(); toPut.push(entry.getValue());/* w ww.j ava 2 s .c o m*/ bindingMap.put(entry.getKey(), toPut); } }
From source file:edu.ehu.galan.lite.model.Corpus.java
/** * * @param pLanguage */ public Corpus(String pLanguage) { language = pLanguage; docList = new ArrayDeque<>(); }
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.AutomatonToDot.java
public String convertToDot(Automaton<T> automaton, Transformer<Step<T>, String> edgeLabelTransformer) { StringBuilder sb = new StringBuilder(); sb.append("digraph finite_state_machine {\n" + "\trankdir=LR;\n" + "\tnode [shape = circle];\n"); List<State<T>> finiteStates = new LinkedList<State<T>>(); Deque<State<T>> queue = new ArrayDeque<State<T>>(); Set<State<T>> visited = new HashSet<State<T>>(); queue.addLast(automaton.getInitialState()); visited.add(automaton.getInitialState()); while (!queue.isEmpty()) { State<T> actual = queue.removeFirst(); if (actual.getFinalCount() > 0) { finiteStates.add(actual);//from ww w . ja v a2 s . c o m } for (Step<T> step : automaton.getDelta().get(actual)) { sb.append("\t"); sb.append(step.getSource().getName()); sb.append(" -> "); sb.append(step.getDestination().getName()); sb.append(" [ label = \""); sb.append(edgeLabelTransformer.transform(step)); sb.append("|"); sb.append(step.getUseCount()); sb.append("\" ];\n"); if (!visited.contains(step.getDestination())) { queue.addLast(step.getDestination()); visited.add(step.getDestination()); } } } sb.append("\n}"); return sb.toString(); }
From source file:org.maikelwever.droidpile.ViewMessageActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.messagesToDownload = new ArrayDeque<String>(); this.mailpileMessage = new MailpileMessage(getIntent().getExtras()); adapter = new MessageExpandableListAdapter(ViewMessageActivity.this, getFragmentManager()); getSupportActionBar().setTitle(this.mailpileMessage.title); View vi = getLayoutInflater().inflate(R.layout.activity_view_message, null); ExpandableListView listView = (ExpandableListView) vi.findViewById(R.id.view_message_listview); listView.setAdapter(adapter);// w w w . ja v a 2s . co m setContentView(vi); if (this.parsedMessage == null) { new FetchMessageTask().execute(mailpileMessage.messageId); progressDialog = ProgressDialog.show(ViewMessageActivity.this, "", getString(R.string.download_please_wait), true, true); } }
From source file:org.apache.hadoop.hbase.procedure2.ProcedureEventQueue.java
@InterfaceAudience.Private public synchronized void suspendProcedure(final Procedure proc) { if (waitingProcedures == null) { waitingProcedures = new ArrayDeque<Procedure>(); }/*from www . jav a 2s . co m*/ waitingProcedures.addLast(proc); }
From source file:org.deeplearning4j.text.corpora.treeparser.BinarizeTreeTransformer.java
@Override public Tree transform(Tree t) { if (t == null) return null; Deque<Pair<Tree, String>> stack = new ArrayDeque<>(); stack.add(new Pair<>(t, t.label())); String originalLabel = t.label(); while (!stack.isEmpty()) { Pair<Tree, String> curr = stack.pop(); Tree node = curr.getFirst();//from w ww. j av a 2 s. co m for (Tree child : node.children()) stack.add(new Pair<>(child, curr.getSecond())); if (node.children().size() > 2) { List<String> children = new ArrayList<>(); for (int i = 0; i < node.children().size(); i++) children.add(node.children().get(i).label()); Tree copy = node.clone(); //clear out children node.children().clear(); Tree currNode = node; for (int i = 1; i < children.size() - 1; i++) { if (factor.equals("right")) { Tree newNode = new Tree(currNode); List<String> subChildren = children.subList(i, Math.min(i + horizontonalMarkov, children.size())); newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(subChildren, "-")); newNode.setParent(currNode); currNode.children().add(copy.children().remove(0)); currNode.firstChild().setParent(currNode); currNode.children().add(newNode); currNode = newNode; } else { Tree newNode = new Tree(currNode); newNode.setParent(copy.firstChild()); List<String> childLabels = children .subList(Math.max(children.size() - i - horizontonalMarkov, 0), i); Collections.reverse(childLabels); newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(childLabels, "-")); currNode.children().add(newNode); currNode.firstChild().setParent(currNode); currNode.children().add(copy.children().remove(copy.children().size() - 1)); currNode.lastChild().setParent(currNode); currNode = newNode; } } currNode.children().addAll(new ArrayList<>(copy.children())); } } addPreTerminal(t); return t; }