protected void visitBlobsField(T state, Field field) throws PropertyException { Type type = field.getType(); if (type.isSimpleType()) { // scalar } else if (type.isComplexType()) { // complex property String name = field.getName().getPrefixedName(); T childState = getChild(state, name, type); if (childState != null) { path.addLast(name); visitBlobsComplex(childState, (ComplexType) type); path.removeLast(); } } else { // array or list Type fieldType = ((ListType) type).getFieldType(); if (fieldType.isSimpleType()) { // array } else { // complex list String name = field.getName().getPrefixedName(); path.addLast(name); int i = 0; for (T childState : getChildAsList(state, name)) { path.addLast(String.valueOf(i++)); visitBlobsComplex(childState, (ComplexType) fieldType); path.removeLast(); } path.removeLast(); } } }
private void buildSwitchStatement(SwitchStatementTree tree) { // FIXME useless node created for default cases. SwitchStatementTree switchStatementTree = tree; Block switchSuccessor = currentBlock; // process condition currentBlock = createBlock(); currentBlock.terminator = switchStatementTree; switches.addLast(currentBlock); build(switchStatementTree.expression()); // process body currentBlock = createBlock(switchSuccessor); breakTargets.addLast(switchSuccessor); if (!switchStatementTree.cases().isEmpty()) { CaseGroupTree firstCase = switchStatementTree.cases().get(0); for (CaseGroupTree caseGroupTree : Lists.reverse(switchStatementTree.cases())) { build(caseGroupTree.body()); switches.getLast().successors.add(currentBlock); if (!caseGroupTree.equals(firstCase)) { // No block predecessing the first case group. currentBlock = createBlock(currentBlock); } } } breakTargets.removeLast(); // process condition currentBlock = switches.removeLast(); }
private void buildForStatement(ForStatementTree tree) { Block falseBranch = currentBlock; // process step currentBlock = createBlock(); Block updateBlock = currentBlock; for (StatementTree updateTree : Lists.reverse(tree.update())) { build(updateTree); } continueTargets.addLast(currentBlock); // process body currentBlock = createBlock(currentBlock); breakTargets.addLast(falseBranch); build(tree.statement()); breakTargets.removeLast(); continueTargets.removeLast(); Block body = currentBlock; // process condition ExpressionTree condition = tree.condition(); if (condition != null) { currentBlock = createBranch(tree, body, falseBranch); buildCondition(condition, body, falseBranch); } else { currentBlock = createUnconditionalJump(tree, body); } updateBlock.successors.add(currentBlock); // process init currentBlock = createBlock(currentBlock); for (StatementTree init : Lists.reverse(tree.initializer())) { build(init); } }
public boolean removeLastComponent() throws NoSuchElementException { Object component = equation.removeLast(); component = equation.removeLast(); if (component instanceof Operator) return true; return false; }
public void setLimit(int limit) { this.limit = limit; while (past.size() > limit) { past.removeLast(); } while (future.size() > limit) { future.removeLast(); } }
@Override public void endElement(String uri, String localName, String qName) { if (path(categoryPath)) { currentText.addCategory(new StringCategory(String.valueOf(elementContentStack.getLast()))); } if (path(textPath)) { currentText.setText(String.valueOf(elementContentStack.getLast())); } if (path(rootPath)) { texts.add(currentText); } elementStack.removeLast(); elementContentStack.removeLast(); }
@Test public void Deque_addLast_removeLast_AddsRemovesTwo() { deque.addLast("firstString"); deque.addLast("secondString"); assertFalse(deque.isEmpty()); assertEquals(deque.size(), 2); String returnedString = deque.removeLast(); assertEquals(returnedString, "secondString"); assertFalse(deque.isEmpty()); assertEquals(deque.size(), 1); returnedString = deque.removeLast(); assertEquals(returnedString, "firstString"); assertTrue(deque.isEmpty()); assertEquals(deque.size(), 0); }
public void addEntry(LogEntry entry) { logDeque.push(entry); if (logDeque.size() > maxSize) { logDeque.removeLast(); } }
private static void deepVisitInternal( Object o, Predicate<Field> fieldPredicate, List<Object> visited, Deque<Object> refChain, Visitor visitor) throws IllegalArgumentException, IllegalAccessException { Class<?> clazz = (o != null) ? o.getClass() : null; refChain.addLast(o); Iterable<Object> filteredRefChain = Iterables.filter(refChain, Predicates.not(Predicates.instanceOf(Dumpers.Entry.class))); try { if (o == null) { // no-op } else if (isClassUntraversable(clazz)) { visitor.visit(o, filteredRefChain); } else if (containsSame(visited, o)) { // no-op } else { visited.add(o); boolean subTreeComplete = visitor.visit(o, filteredRefChain); if (!subTreeComplete) { Map<String, Object> members = findMembers(o, fieldPredicate); for (Map.Entry<String, Object> entry : members.entrySet()) { deepVisitInternal(entry.getValue(), fieldPredicate, visited, refChain, visitor); } } } } finally { refChain.removeLast(); } }
/** Do the last entry that was undone again. */ public void redo() { if (canRedo()) { final HistoryAction entry = redoList.removeLast(); entry.redo(); undoList.addLast(entry); } }
/** Undo the last entry that was added to this history. */ public void undo() { if (canUndo()) { final HistoryAction entry = undoList.removeLast(); entry.undo(); redoList.addLast(entry); } }
public void insert(T state) { past.addFirst(present); if (past.size() > limit) { past.removeLast(); } future.clear(); present = state; }
@Test(expected = NoSuchElementException.class) public void Deque_addLast_removeFirst_throwsIfEmpty() { deque.addFirst("firstString"); deque.addFirst("secondString"); deque.removeLast(); deque.removeLast(); deque.removeFirst(); }
private void buildForEachStatement(ForEachStatement tree) { // TODO(npe) One solution is to create a forstatement node depending on type of expression // (iterable or array) and build CFG from it. Block afterLoop = currentBlock; currentBlock = createBlock(); Block loopback = currentBlock; continueTargets.addLast(loopback); breakTargets.addLast(afterLoop); build(tree.statement()); breakTargets.removeLast(); continueTargets.removeLast(); currentBlock = createBranch(tree, currentBlock, afterLoop); loopback.successors.add(currentBlock); build(tree.variable()); build(tree.expression()); currentBlock = createBlock(currentBlock); }
private void buildDoWhileStatement(DoWhileStatementTree tree) { DoWhileStatementTree s = tree; Block falseBranch = currentBlock; Block loopback = createBlock(); // process condition currentBlock = createBranch(s, loopback, falseBranch); buildCondition(s.condition(), loopback, falseBranch); // process body currentBlock = createBlock(currentBlock); continueTargets.addLast(loopback); breakTargets.addLast(falseBranch); build(s.statement()); breakTargets.removeLast(); continueTargets.removeLast(); loopback.successors.add(currentBlock); currentBlock = createBlock(currentBlock); }
public StackedByThreadHints popStackElement() { final Deque<Hints> allHints = _hintStack.get(); allHints.removeLast(); if (allHints.isEmpty()) { _hintStack.remove(); } return this; }
private final void end(QueryPart part) { if (visitParts != null) { for (VisitListener listener : visitListeners) listener.visitEnd(visitContext); if (visitParts.removeLast() != part) throw new RuntimeException("Mismatch between visited query parts"); } }
@Override protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { Subject subject = getSubject(request, response); if (!subject.isAuthenticated() && !subject.isRemembered()) { // 如果没有登录,直接进行之后的流程 return true; } Session session = subject.getSession(); // String username = (String) subject.getPrincipal(); String account = ((ShiroUser) subject.getPrincipal()).getAccount(); Serializable sessionId = session.getId(); // TODO 同步控制 Deque<Serializable> deque = cache.get(account); if (deque == null) { deque = new LinkedList<Serializable>(); cache.put(account, deque); } // 如果队列里没有此sessionId,且用户没有被踢出;放入队列 if (!deque.contains(sessionId) && session.getAttribute("kickout") == null) { deque.push(sessionId); } // 如果队列里的sessionId数超出最大会话数,开始踢人 while (deque.size() > maxSession) { Serializable kickoutSessionId = null; if (kickoutAfter) { // 如果踢出后者 kickoutSessionId = deque.removeFirst(); } else { // 否则踢出前者 kickoutSessionId = deque.removeLast(); } try { Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId)); if (kickoutSession != null) { // 设置会话的kickout属性表示踢出了 kickoutSession.setAttribute("kickout", true); } } catch (Exception e) { // ignore exception } } // 如果被踢出了,直接退出,重定向到踢出后的地址 if (session.getAttribute("kickout") != null) { // 会话被踢出了 try { subject.logout(); } catch (Exception e) { // ignore } saveRequest(request); WebUtils.issueRedirect(request, response, kickoutUrl); return false; } return true; }
@Override public final C end(Clause clause) { if (clause != null && visitClauses != null) { for (VisitListener listener : visitListeners) listener.clauseEnd(visitContext); if (visitClauses.removeLast() != clause) throw new IllegalStateException("Mismatch between visited clauses!"); } return (C) this; }
// Here are the details of the matching. We track the current brace depth, and we artificially // consider that the whole file is at brace depth 1 inside a pseudo-class whose name is the // name of the package. When we see a class definition, we push the fully-qualified name of the // class on a stack so that we can associate abstract methods we find with the possibly-nested // class they belong to. A class definition must occur at brace depth one more than the class // containing it, which is equivalent to saying that the brace depth must be the same as the // class stack depth. This check excludes local class definitions within methods and // initializers. If we meet these constraints and we see the word "class" followed by an // identifier Foo, then we consider that we are entering the definition of class Foo. We determine // the fully-qualified name of Foo, which is container.Foo, where container is the current top of // the class stack (initially, the package name). We push this new fully-qualified name on the // class stack. We have not yet seen the left brace with the class definition so at this point the // class stack depth is one more than the brace depth. When we subsequently see a right brace that // takes us back to this situation then we know we have completed the definition of Foo and we can // pop it from the class stack. // // We check that the token after "class" is indeed an identifier to avoid confusion // with Foo.class. Even though the tokenizer does not distinguish between identifiers and // keywords, it is enough to exclude the single word "instanceof" because that is the only word // that can legally appear after Foo.class (though in a legal program the resultant expression // will always be true). // // Again, we are at the top level of a class when the brace depth is equal to the class stack // depth. If we then see the word "abstract" then that is the start either of an abstract class // definition or of an abstract method. We record that we have seen "abstract" and we cancel // that indication as soon as we see a left brace, to exclude the abstract class case, and also // the case of interfaces or @interfaces redundantly declared abstract. Now, when // we see an identifier that is preceded by an uncanceled "abstract" and followed by a left paren // then we have found an abstract method of the class on the top of the class stack. We record it // in the list of abstract methods of the class on the top of the class stack. We don't bother // checking that the method has no parameters, because an @AutoValue class will cause a compiler // error if there are abstract methods with parameters, since the @AutoValue processor doesn't // know how to implement them in the concrete subclass it generates. Map<String, List<String>> abstractMethods(JavaTokenizer tokenizer, String packageName) { Map<String, List<String>> abstractMethods = new HashMap<String, List<String>>(); Deque<String> classStack = new ArrayDeque<String>(); classStack.addLast(packageName); int braceDepth = 1; boolean sawAbstract = false; String className = null; for (String previousToken = "", token = tokenizer.nextToken(); token != null; previousToken = token, token = tokenizer.nextToken()) { boolean topLevel = (braceDepth == classStack.size()); if (className != null) { // get last term in fully-qualified class name (e.g. "class some.package.Bar { ...") if (token.equals(".")) { className = tokenizer.nextToken(); continue; } else { if (Character.isJavaIdentifierStart(className.charAt(0)) && !className.equals("instanceof")) { String container = classStack.getLast(); // container might be empty in the case of a packageless class classStack.add(container.isEmpty() ? className : container + "." + className); } className = null; } } if (token.equals("{")) { braceDepth++; sawAbstract = false; } else if (token.equals("}")) { braceDepth--; if (topLevel) { classStack.removeLast(); } } else if (topLevel) { if (token.equals("class") || token.equals("interface")) { className = tokenizer.nextToken(); } else if (token.equals("abstract")) { sawAbstract = true; } else if (token.equals("(")) { if (sawAbstract && Character.isJavaIdentifierStart(previousToken.charAt(0))) { List<String> methods = abstractMethods.get(classStack.getLast()); if (methods == null) { methods = new ArrayList<String>(); abstractMethods.put(classStack.getLast(), methods); } methods.add(previousToken); } sawAbstract = false; } } } return abstractMethods; }
public void solve() { if (end == null) { // return; } solved = !solved; GridVertex current = origin; Deque<GridVertex> deque = new LinkedList<GridVertex>(); current.setColor(green); current.visit(); while (current != end) { if (solved) { repaint(); } Set<GridVertex> tempSet = current.getUnVisitedNeighborSet(); tempSet.removeAll(current.getWalledSet()); if (tempSet.isEmpty()) { current.setColor(Color.WHITE); try { current = deque.pop(); } catch (NoSuchElementException e) { for (int i = 0; i < 40; i++) { System.out.print("*"); } System.out.println("\nNo solution exists."); for (int i = 0; i < 40; i++) { System.out.print("*"); } return; } } else { deque.push(current); GridVertex chosen = tempSet.iterator().next(); current = chosen; current.visit(); } if (solved) { current.setColor(green); } } while (!deque.isEmpty()) { deque.removeLast().setColor(solved ? Color.ORANGE : Color.WHITE); repaint(); } end.setColor(solved ? Color.ORANGE : Color.WHITE); component.repaint(); System.out.println("Solved!"); }
public static Deque<BuildingWithHeight> examineBuildingsWithSunset(Iterator<Integer> sequence) { int buildingIdx = 0; Deque<BuildingWithHeight> buildingsWithSunset = new LinkedList<>(); while (sequence.hasNext()) { Integer buildingHeight = sequence.next(); while (!buildingsWithSunset.isEmpty() && (Integer.compare(buildingHeight, buildingsWithSunset.getLast().height) >= 0)) { buildingsWithSunset.removeLast(); } buildingsWithSunset.addLast(new BuildingWithHeight(buildingIdx++, buildingHeight)); } return buildingsWithSunset; }
/** Close all closeables contained by this instance. */ @Override public void close() { Set<AutoCloseable> set = closeables.getAndSet(null); if (set != null) { // Close all closeables in reverse order. Deque<AutoCloseable> list = new LinkedList<>(set); while (!list.isEmpty()) { close(list.removeLast()); } // For gc. set.clear(); } }
@Override public void onUpdate() { super.onUpdate(); int phase = (initialPhase + particleAge) % 64; motionY = 0.1f; motionX = cos[phase] * Config.soulFXPerturb; motionZ = sin[phase] * Config.soulFXPerturb; particleTrail.addFirst(new Double3(posX, posY, posZ)); while (particleTrail.size() > Config.soulFXTrailLength) particleTrail.removeLast(); if (!Config.globalEnabled) setDead(); }
public void exec(String inCommand) throws CalcCommandsException { Double d1, d2; if (stack.size() > 1) { d1 = stack.removeLast(); d2 = stack.removeLast(); stack.addLast(d2 * d1); } else if ((stack.size() == 0)) { throw new CalcCommandsException( "List is empty! " + this.getClass().getSimpleName() + ".exec(" + inCommand + ") fail!"); } else { throw new CalcCommandsException( "List contains only one number! " + this.getClass().getSimpleName() + ".exec(" + inCommand + ") fail!"); } }
// TODO(bazel-team): run this on the Skylark docs too. private static String getFirstUnclosedTag(String src, boolean printHelp) { Matcher commentMatcher = COMMENT_PATTERN.matcher(src); src = commentMatcher.replaceAll(""); Matcher tagMatcher = TAG_PATTERN.matcher(src); Deque<String> tagStack = new ArrayDeque<>(); while (tagMatcher.find()) { String tag = tagMatcher.group(1); String rest = tagMatcher.group(2); String strippedTag = tag.substring(1); // Ignoring self closing tags. if (!rest.endsWith("/") // Ignoring unchecked tags. && !UNCHECKED_HTML_TAGS.contains(tag) && !UNCHECKED_HTML_TAGS.contains(strippedTag)) { if (tag.startsWith("/")) { // Closing tag. Removing '/' from the beginning. tag = strippedTag; String lastTag = tagStack.removeLast(); if (!lastTag.equals(tag)) { if (printHelp) { System.err.println( "Unclosed tag: " + lastTag + "\n" + "Trying to close with: " + tag + "\n" + "Stack of open tags: " + tagStack + "\n" + "Last 200 characters:\n" + src.substring(Math.max(tagMatcher.start() - 200, 0), tagMatcher.start())); } return lastTag; } } else { // Starting tag. tagStack.addLast(tag); } } } return null; }
// Here are the details of the matching. We track the current brace depth, and we artificially // consider that the whole file is at brace depth 1 inside a pseudo-class whose name is the // name of the package. When we see a class definition, we push the fully-qualified name of the // class on a stack so that we can associate abstract methods we find with the possibly-nested // class they belong to. A class definition must occur at brace depth one more than the class // containing it, which is equivalent to saying that the brace depth must be the same as the // class stack depth. This check excludes local class definitions within methods and // initializers. If we meet these constraints and we see the word "class" followed by an // identifier Foo, then we consider that we are entering the definition of class Foo. We determine // the fully-qualified name of Foo, which is container.Foo, where container is the current top of // the class stack (initially, the package name). We push this new fully-qualified name on the // class stack. We have not yet seen the left brace with the class definition so at this point the // class stack depth is one more than the brace depth. When we subsequently see a right brace that // takes us back to this situation then we know we have completed the definition of Foo and we can // pop it from the class stack. // // We check that the token after "class" is indeed an identifier to avoid confusion // with Foo.class. Even though the tokenizer does not distinguish between identifiers and // keywords, it is enough to exclude the single word "instanceof" because that is the only word // that can legally appear after Foo.class (though in a legal program the resultant expression // will always be true). // // Again, we are at the top level of a class when the brace depth is equal to the class stack // depth. If we then see the word "abstract" then that is the start either of an abstract class // definition or of an abstract method. We record that we have seen "abstract" and we cancel // that indication as soon as we see a left brace, to exclude the abstract class case, and also // the case of interfaces or @interfaces redundantly declared abstract. Now, when // we see an identifier that is preceded by an uncanceled "abstract" and followed by a left paren // then we have found an abstract method of the class on the top of the class stack. We record it // in the list of abstract methods of the class on the top of the class stack. We don't bother // checking that the method has no parameters, because an @AutoCursor class will cause a compiler // error if there are abstract methods with parameters, since the @AutoCursor processor doesn't // know how to implement them in the concrete subclass it generates. ImmutableListMultimap<String, String> abstractMethods( JavaTokenizer tokenizer, String packageName) { ImmutableListMultimap.Builder<String, String> abstractMethods = ImmutableListMultimap.builder(); Deque<String> classStack = new ArrayDeque<String>(); classStack.addLast(packageName); int braceDepth = 1; boolean sawAbstract = false; String className = null; for (String previousToken = "", token = tokenizer.nextToken(); token != null; previousToken = token, token = tokenizer.nextToken()) { boolean topLevel = (braceDepth == classStack.size()); if (className != null) { if (Character.isJavaIdentifierStart(className.charAt(0)) && !className.equals("instanceof")) { String container = classStack.getLast(); // container might be empty in the case of a packageless class classStack.add(container.isEmpty() ? className : container + "." + className); } className = null; } if (token.equals("{")) { braceDepth++; sawAbstract = false; } else if (token.equals("}")) { braceDepth--; if (topLevel) { classStack.removeLast(); } } else if (topLevel) { if (token.equals("class") || token.equals("interface")) { className = tokenizer.nextToken(); } else if (token.equals("abstract")) { sawAbstract = true; } else if (token.equals("(")) { if (sawAbstract && Character.isJavaIdentifierStart(previousToken.charAt(0))) { abstractMethods.put(classStack.getLast(), previousToken); } sawAbstract = false; } } } return abstractMethods.build(); }
private boolean checkCorrectness() { Deque<DocStructure> structuresToCheck = new LinkedList<>(); structuresToCheck.add(root); while (!structuresToCheck.isEmpty()) { DocStructure docStructure = structuresToCheck.removeLast(); boolean contained = subDocuments.contains(docStructure.getType(), docStructure.getIndex()); if (!contained) { throw new IllegalStateException( "The structure references the subdocument " + docStructure.getType() + " with index " + docStructure.getIndex() + ", which is not " + "contained in the subdocuments table"); } } return true; }
private void clean(Date date) { long difference; boolean delete; if (deque.size() == 0) { return; } delete = false; do { Event e = deque.getLast(); difference = date.getTime() - e.getDate().getTime(); if (difference > 10000) { System.out.printf("Cleaner: %s\n", e.getEvent()); deque.removeLast(); delete = true; } } while (difference > 10000); if (delete) { System.out.printf("Cleaner: Size of the queue: %d\n", deque.size()); } }
@Override public ObjectInspector getObjectInspector() { // Read the configuration parameters String columnNameProperty = conf.get(serdeConstants.LIST_COLUMNS); // NOTE: if "columns.types" is missing, all columns will be of String type String columnTypeProperty = conf.get(serdeConstants.LIST_COLUMN_TYPES); // Parse the configuration parameters ArrayList<String> columnNames = new ArrayList<String>(); Deque<Integer> virtualColumns = new ArrayDeque<Integer>(); if (columnNameProperty != null && columnNameProperty.length() > 0) { String[] colNames = columnNameProperty.split(","); for (int i = 0; i < colNames.length; i++) { if (VirtualColumn.VIRTUAL_COLUMN_NAMES.contains(colNames[i])) { virtualColumns.addLast(i); } else { columnNames.add(colNames[i]); } } } if (columnTypeProperty == null) { // Default type: all string StringBuilder sb = new StringBuilder(); for (int i = 0; i < columnNames.size(); i++) { if (i > 0) { sb.append(":"); } sb.append("string"); } columnTypeProperty = sb.toString(); } ArrayList<TypeInfo> fieldTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty); while (virtualColumns.size() > 0) { fieldTypes.remove(virtualColumns.removeLast()); } StructTypeInfo rowType = new StructTypeInfo(); rowType.setAllStructFieldNames(columnNames); rowType.setAllStructFieldTypeInfos(fieldTypes); return OrcRecordUpdater.createEventSchema(OrcStruct.createObjectInspector(rowType)); }