/** * @param path path to first element * @param pathTo path to second element * @return environment in which the generic parameters in the path to the first element are bound * to those in the path to the second element, or null type on error */ public static ResolvedName mapGenericParameters( final Deque<? extends INamedElement> path, final Deque<? extends INamedElement> pathTo) { // Construct an environment in which the current function's generic parameters // are bound to those of the eventual override. final Deque<List<? extends ResolvedName>> tableau = new LinkedList<>(ResolvedName.fromNamedElement(path.getLast()).tableau()); final Iterator<? extends INamedElement> pathIt = path.descendingIterator(); while (pathIt.hasNext()) { pathIt.next(); tableau.removeLast(); } CachedIterator<? extends INamedElement> itPathTo = null; CachedIterator<? extends IGenericParameter> itGPTo = null; boolean end = false; { // Initialise iterators into direct override's generic parameters. boolean foundValid = false; itPathTo = Iterators.cached(pathTo.iterator()); while (!foundValid && itPathTo.hasItem()) { itGPTo = Iterators.cached(itPathTo.item().genericParameters().iterator()); while (!foundValid && itGPTo.hasItem()) { foundValid = true; if (!foundValid) itGPTo.next(); } if (!foundValid) itPathTo.next(); } if (!foundValid) end = true; } for (final INamedElement elt : path) { final List<ResolvedName> row = new ArrayList<>(); for (@SuppressWarnings("unused") final IGenericParameter genericParameter : elt.genericParameters()) { if (end) return null; row.add(ResolvedName.fromNamedElement(itGPTo.item())); { // Increment iterators into direct override's generic parameters. boolean init = true; boolean foundValid = false; if (!init) itPathTo = Iterators.cached(pathTo.iterator()); while (!foundValid && itPathTo.hasItem()) { if (!init) itGPTo = Iterators.cached(itPathTo.item().genericParameters().iterator()); while (!foundValid && itGPTo.hasItem()) { if (!init) foundValid = true; init = false; if (!foundValid) itGPTo.next(); } if (!foundValid) itPathTo.next(); } if (!foundValid) end = true; } } tableau.add(row); } if (!end) return null; return ResolvedName.newNameReference(path.getLast(), tableau); }
// 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; }
@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(); }
public TempReading getMinTemp(LocalDateTime userBeginDate, LocalDateTime userEndDate) { double tMin = MAX_TEMP; TempReading minTemp = new TempReading(MAX_TEMP); if (this.queEmpty()) return minTemp; LocalDateTime qBeginDate, qEndDate; qBeginDate = qTemp.getFirst().getTempTime(); qEndDate = qTemp.getLast().getTempTime(); // Test some end conditions if (userEndDate.isBefore(qBeginDate) || userBeginDate.isAfter(qEndDate)) { return minTemp; } TempReading tArray[] = this.toArray(); int len = this.queSize(); LocalDateTime tArrayValue; for (int i = 0; i < len; i++) { tArrayValue = tArray[i].getTempTime(); if ((tArrayValue.isAfter(userBeginDate) || tArrayValue.equals(userBeginDate)) && (tArrayValue.isBefore(userEndDate) || tArrayValue.equals( userEndDate))) { // the test or "equals" is a bit overkill, but it made testing // easier if (tMin > tArray[i].getTemp()) { tMin = tArray[i].getTemp(); minTemp = tArray[i]; } } } return minTemp; }
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 prune() { // Remove all values that are too old TimeInterval periodAllowed = cachedPeriod.before(buffer.getLast().getTimestamp()); while (!buffer.isEmpty() && !periodAllowed.contains(buffer.getFirst().getTimestamp())) { // Discard value buffer.removeFirst(); } }
private ExpressionType getOnType(TreeNode on) { if (on != null) { return on.getExpressionType(); } else { String fqn = cip.getFullName(containingClasses.getLast()); return new ExpressionType(fqn); } }
private void unread(int character) throws IOException { if (character == '\n') { line--; } pushbackReader.unread(character); if (pureTextFromFile.getLast() == character) { pureTextFromFile.pollLast(); } }
// 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 void buildContinueStatement(ContinueStatementTree tree) { if (tree.label() == null) { if (continueTargets.isEmpty()) { throw new IllegalStateException("'continue' statement not in loop or switch statement"); } currentBlock = createUnconditionalJump(tree, continueTargets.getLast()); } else { currentBlock = createUnconditionalJump(tree, null); gotos.add(currentBlock); } }
private void reloadGame() { if (!isReload) return; score = 0; isReload = false; isEnd = false; feedCounter1 = 0; feedCounter2 = 0; List<Rectangle> rectangleList = new ArrayList<>(rectangles); for (Rectangle r : rectangleList) group.getChildren().remove(r); regimeRectangle.setX(-20); Deque<Block> blocksTemp = new ArrayDeque<>(); Deque<Rectangle> rectanglesTemp = new ArrayDeque<>(); head = new Block(100, 150); tale = new Block(90, 150); if (inputDirection != 3) { blocksTemp.push(tale); blocksTemp.push(head); rectanglesTemp.push(new Rectangle(tale.getX(), tale.getY(), 10, 10)); rectanglesTemp.push(new Rectangle(head.getX(), head.getY(), 10, 10)); } else { blocksTemp.push(head); blocksTemp.push(tale); rectanglesTemp.push(new Rectangle(head.getX(), head.getY(), 10, 10)); rectanglesTemp.push(new Rectangle(tale.getX(), tale.getY(), 10, 10)); } blocks = blocksTemp; rectangles = rectanglesTemp; group.getChildren().add(rectangles.getFirst()); group.getChildren().add(rectangles.getLast()); timer.cancel(); timer = null; timer = new Timer(); timer.schedule( new TimerTask() { @Override public void run() { Platform.runLater(() -> play()); } }, 1, 100); }
// leaders log differently void setLeaderState(boolean isLeader) { m_isLeader = isLeader; // The leader doesn't truncate its own SP log; if promoted, // wipe out the SP portion of the existing log. This promotion // action always happens after repair is completed. if (m_isLeader) { if (!m_logSP.isEmpty()) { truncate(m_logSP.getLast().getHandle(), IS_SP); } } }
private Tree unwind(Operator operator) { int prec0 = operator != null ? operator.getPrecedence() : -1; Operator op; Tree tree; while ((op = (tree = list.getLast()).getOperator()) != null) { int prec1 = op.getPrecedence(); if (prec0 < prec1 || operator.getAssoc() == Assoc.LEFT && prec0 == prec1) pop(); else break; } return tree; }
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; }
/** * Set to a specific value. * * <p>This searches for the displayed value, and sets the enum to that particular one. It used to * work off an index, but now it looks for the value. * * <p>If the value is larger than any defined, a new one is created. * * @param value */ protected void selectValue(int value) { for (int i = 0; i < _valueArray.length; i++) { if (_valueArray[i] == value) { // found it, select it _value.setSelectedIndex(i); // now select in the tree TreePath path = _pathArray[i]; for (JTree tree : trees) { tree.setSelectionPath(path); // ensure selection is in visible portion of JScrollPane tree.scrollPathToVisible(path); } return; } } // We can be commanded to a number that hasn't been defined. // But that's OK for certain applications. Instead, we add them as needed log.debug( "Create new item with value " + value + " count was " + _value.getItemCount() + " in " + label()); // lengthen arrays _valueArray = java.util.Arrays.copyOf(_valueArray, _valueArray.length + 1); _valueArray[_valueArray.length - 1] = value; _itemArray = java.util.Arrays.copyOf(_itemArray, _itemArray.length + 1); _itemArray[_itemArray.length - 1] = "Reserved value " + value; _pathArray = java.util.Arrays.copyOf(_pathArray, _pathArray.length + 1); TreeLeafNode node = new TreeLeafNode(_itemArray[_itemArray.length - 1], _itemArray.length - 1); treeNodes.getLast().add(node); _pathArray[_itemArray.length - 1] = new TreePath(node.getPath()); _value.addItem(_itemArray[_itemArray.length - 1]); _value.setSelectedItem(_itemArray[_itemArray.length - 1]); // tell trees to redisplay & select for (JTree tree : trees) { ((DefaultTreeModel) tree.getModel()).reload(); tree.setSelectionPath(_pathArray[_itemArray.length - 1]); // ensure selection is in visible portion of JScrollPane tree.scrollPathToVisible(_pathArray[_itemArray.length - 1]); } }
/** * Returns all values since last check and removes values from the queue. * * @return a new array with the value; never null */ @Override public List<T> getValue() { synchronized (buffer) { if (buffer.isEmpty()) return Collections.emptyList(); // period allowed time = latest - msCache / 1000 TimeInterval periodAllowed = cachedPeriod.before(TimeStamp.asTimestamp(TimeSupport.timestampOf(buffer.getLast()))); while (!buffer.isEmpty() && !periodAllowed.contains( TimeStamp.asTimestamp(TimeSupport.timestampOf(buffer.getFirst())))) { // Discard value buffer.removeFirst(); } return new ArrayList<T>(buffer); } }
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()); } }
public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<List<Integer>>(); if (root == null) { return res; } int curh = 1; // double ended queue Deque<TreeNode> queue = new LinkedList<TreeNode>(); queue.add(root); TreeNode head = root, tail = null; List<Integer> path = new ArrayList<Integer>(); while (!queue.isEmpty()) { TreeNode cur = queue.peek(); if (cur == head) { if (!queue.isEmpty()) { tail = queue.getLast(); } } queue.poll(); path.add(cur.val); if (cur.left != null) { queue.add(cur.left); } if (cur.right != null) { queue.add(cur.right); } if (cur == tail) { if (!queue.isEmpty()) { head = queue.getFirst(); } if ((curh & 1) == 0) { Collections.reverse(path); } res.add(new ArrayList<Integer>(path)); path.clear(); curh++; } } return res; }
/** * @return The list of all basic block in this control flow graph in reversed depth-first * postorder sequence. * <p>Blocks may appear more than once in the sequence. */ public List<Block> getDepthFirstOrderedBlocks() { List<Block> dfsOrderResult = new LinkedList<>(); Set<Block> visited = new HashSet<>(); Deque<Block> worklist = new LinkedList<>(); worklist.add(entryBlock); while (!worklist.isEmpty()) { Block cur = worklist.getLast(); if (visited.contains(cur)) { dfsOrderResult.add(cur); worklist.removeLast(); } else { visited.add(cur); Deque<Block> successors = getSuccessors(cur); successors.removeAll(visited); worklist.addAll(successors); } } Collections.reverse(dfsOrderResult); return dfsOrderResult; }
/** * Runs the server. The server will wait for some match info (which specifies the teams and set of * maps to run) and then begin running matches. */ public void run() { int aWins = 0, bWins = 0; while (!matches.isEmpty()) { Match match = matches.peek(); if (!finished.isEmpty()) match.setInitialTeamMemory(finished.getLast().getComputedTeamMemory()); try { debug("running match " + match); match.initialize(); runMatch(match, proxyWriter); finished.add(match); matches.remove(match); if (match.getWinner() == Team.A) aWins++; else if (match.getWinner() == Team.B) bWins++; match.finish(); // Allow best of three scrimmages -- single game scrims should still work fine // TODO:This "win mode" should probably be something from the database if (mode == Mode.TOURNAMENT || mode == Mode.SCRIMMAGE) { if (aWins == 2 || bWins == 2) break; } } catch (Exception e) { ErrorReporter.report(e); error("couldn't run match: "); this.state = State.ERROR; } } proxyWriter.terminate(); }
private static void renderLayoutBox(List<DisplayCommand> displayList, LayoutBox layoutBox) { System.out.println(layoutBox); switch (layoutBox.getType()) { case BLOCK_NODE: renderBackground(displayList, layoutBox); renderBorders(displayList, layoutBox); for (LayoutBox child : layoutBox.getChildren()) { renderLayoutBox(displayList, child); } break; case INLINE_NODE: InlineBox box = (InlineBox) layoutBox; Optional<Color> colorVal = getColor(layoutBox, "border-color"); Dimensions dims = layoutBox.getDimensions(); Rect borderBox = dims.borderBox(); Deque<LineBox> lines = box.getLines(); if (colorVal.isPresent()) { Color color = colorVal.get(); LineBox firstLine = lines.getFirst(); float boxHeight = firstLine.getBoxHeight(); float lineHeight = firstLine.getLineHeight(); float borderHeight = lineHeight + dims.border.top + dims.border.bottom; // left border displayList.add( new SolidColor( color, new Rect( borderBox.x, borderBox.y + boxHeight - lineHeight, dims.border.left, borderHeight))); LineBox lastLine = lines.getLast(); // right border displayList.add( new SolidColor( color, new Rect( borderBox.x + lastLine.getFilledWidth() + dims.border.left + dims.border.right, borderBox.y + borderHeight * (lines.size() - 1), dims.border.right, borderHeight))); float lineX = dims.content.x - dims.border.left; float lineY = dims.content.y; for (LineBox line : box.getLines()) { // TODO proper line-height calculations float lineWidth = line.getFilledWidth() + dims.border.left + dims.border.right; // top border displayList.add( new SolidColor( color, new Rect(lineX, lineY - dims.border.top, lineWidth, dims.border.top))); // bottom border displayList.add( new SolidColor( color, new Rect(lineX, lineY + lineHeight, lineWidth, dims.border.bottom))); lineY += borderHeight; } } break; default: break; } }
private CommitLogSegment currentSegment() { return segments.getLast(); }
private InternalTestBlockBuilder getCurrentDescribeBlock() { return stack.getLast(); }
public Expression(String s) throws Exception { Deque<Elem> op = new ArrayDeque<Elem>(100); int l = 0; String cur = null; boolean isNum = true; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (ch == '+' || ch == '-') { add(cur, isNum); cur = null; isNum = true; while (!op.isEmpty() && op.getLast().level == l) { deq.addLast(op.pollLast()); } op.add(new Elem(ElemType.FUNC, "" + ch, l)); } else if (ch == '*' || ch == '/') { add(cur, isNum); cur = null; isNum = true; while (!op.isEmpty() && op.getLast().level == l && !op.getLast().value.equals("+") && !op.getLast().value.equals("-")) { deq.addLast(op.pollLast()); } op.add(new Elem(ElemType.FUNC, "" + ch, l)); } else if (ch == ' ') { continue; } else if (ch == '(') { if (cur != null) { op.add(new Elem(ElemType.FUNC, cur, l)); cur = null; isNum = true; } l++; } else if (ch == ')') { if (cur != null) { add(cur, isNum); cur = null; isNum = false; } while (!op.isEmpty() && op.getLast().level == l) { deq.addLast(op.pollLast()); } l--; while (!op.isEmpty() && op.getLast().level == l && !op.getLast().value.equals("+") && !op.getLast().value.equals("-")) { deq.addLast(op.pollLast()); } } else { if (!Character.isDigit(ch) && ch != '.') { isNum = false; } if (cur == null) { cur = "" + ch; } else { cur += ch; } } } if (cur != null) { add(cur, isNum); cur = null; isNum = true; } while (!op.isEmpty() && op.getLast().level == l) { deq.addLast(op.pollLast()); } count(); }
@Nonnull protected Hints getCurrent() { final Deque<Hints> allHints = _hintStack.get(); return allHints != null && !allHints.isEmpty() ? allHints.getLast() : _superHints; }
@Override public <T> T decode(BitBuffer bitbuffer, Class<T> classOfT, Annotation[] extraAnnotations) { AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(), extraAnnotations); UperEncoder.logger.debug("SEQUENCE"); T result = UperEncoder.instantiate(classOfT); Asn1ContainerFieldSorter sorter = new Asn1ContainerFieldSorter(classOfT); boolean extensionPresent = false; if (UperEncoder.hasExtensionMarker(annotations)) { extensionPresent = bitbuffer.get(); UperEncoder.logger.debug( "with extension marker, extension {}", extensionPresent ? "present!" : "absent"); } // Bitmask for optional fields. Deque<Boolean> optionalFieldsMask = new ArrayDeque<>(sorter.optionalOrdinaryFields.size()); for (Field f : sorter.optionalOrdinaryFields) { optionalFieldsMask.add(bitbuffer.get()); UperEncoder.logger.debug( "with optional field {} {}", f.getName(), optionalFieldsMask.getLast() ? "present" : "absent"); } // All ordinary fields (fields within extension root). for (Field f : sorter.ordinaryFields) { if (!UperEncoder.isTestInstrumentation(f) && (UperEncoder.isMandatory(f) || (UperEncoder.isOptional(f) && optionalFieldsMask.pop()))) { UperEncoder.logger.debug("Field : {}", f.getName()); try { f.set(result, UperEncoder.decode2(bitbuffer, f.getType(), f.getAnnotations())); } catch (IllegalAccessException e) { throw new IllegalArgumentException( "can't access 'set method' for field " + f + " of class " + classOfT + " " + e, e); } } } // Extension fields. if (UperEncoder.hasExtensionMarker(annotations) && extensionPresent) { // Number of extensions. int numExtensions = (int) UperEncoder.decodeLengthOfBitmask(bitbuffer); UperEncoder.logger.debug("sequence has {} extension(s)", numExtensions); // Bitmask for extensions. boolean[] bitmaskValueIsPresent = new boolean[numExtensions]; for (int i = 0; i < numExtensions; i++) { bitmaskValueIsPresent[i] = bitbuffer.get(); UperEncoder.logger.debug( "extension {} is {}", i, bitmaskValueIsPresent[i] ? "present" : "absent"); } // Values. UperEncoder.logger.debug("decoding extensions values..."); for (int i = 0; i < numExtensions; i++) { UperEncoder.logger.debug( "sequence extension {} {}", i, bitmaskValueIsPresent[i] ? "present" : "absent"); if (bitmaskValueIsPresent[i]) { UperEncoder.logger.debug("decoding extension {}...", i); Field field = sorter.extensionFields.size() > i ? sorter.extensionFields.get(i) : null; Class<?> classOfElement = field != null ? field.getType() : null; try { Object decodedValue = UperEncoder.decodeAsOpenType(bitbuffer, classOfElement, field.getAnnotations()); if (field != null) { field.set(result, decodedValue); } } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalArgumentException("can't decode " + classOfT, e); } } } } sorter.revertAccess(); return result; }
@Override public void characters(char[] ch, int start, int length) { elementContentStack.getLast().append(ch, start, length); }
public double getCurrentTemp() { return (!queEmpty() ? qTemp.getLast().getTemp() : MIN_TEMP); }
public ExecutionInfo getExecutionInfo() { return infos.getLast(); }