/** * Uses the extraction template generated by the {@link #templateGeneration} process and utilizes * some own characteristics of the target page pt to extract the content of it which first needs * to be parsed to a DOM tree <em>tp</em>. * * @param tt The previouslz generated extraction template * @param tp_i The root DOM element of the document to predict the main content for */ public void newsContentExtraction(Deque<Token> tt, Token tp_i) { // templateNode <-- tt.firstElement Token templateNode = tt.getFirst(); if (templateNode.getName().equals(tp_i.getName()) && templateNode.getLevel() == tp_i.getLevel() && templateNode.getSibNo() == tp_i.getSibNo()) { tt.removeFirst(); if (tt.size() > 0) { Token nextTemplateNode = tt.getFirst(); if (tp_i.getChildren() == null || tp_i.getChildren().length == 0) { LOG.info(tp_i.getText()); while (nextTemplateNode.getParentNo() == templateNode.getNo()) { tt.removeFirst(); templateNode = nextTemplateNode; nextTemplateNode = tt.getFirst(); } } else { if (nextTemplateNode.getParentNo() != templateNode.getNo()) { System.out.println(this.deleteEmbeddedNoise(tp_i.getSubtreeText())); } for (int j = 0; j < tp_i.getChildren().length; j++) { this.newsContentExtraction(tt, tp_i.getChildren()[j]); } } } else { LOG.info(this.deleteEmbeddedNoise(tp_i.getSubtreeText())); } } }
@Override public void undefine(int line, int column, String name) { // Add an object for this macro event. MacroDef newDef = new MacroDef(currRef, MacroDef.UNDEFINE, line, column); currRef.macroEventList.add(newDef); newDef.name = name; // Now process the undefine. Scope currScope = scopeStack.getFirst(); // First look for local SCOPED define if (currScope.defMap.containsKey(name)) { newDef.undefWhat = currScope.defMap.remove(name); return; } // Second look for a named include file argument newDef.undefWhat = currInclude.undefine(name); if (newDef.undefWhat != null) return; // Third look for a non-local SCOPED define Iterator<Scope> it = scopeStack.iterator(); it.next(); // skip the current scope - already checked. while (it.hasNext()) { currScope = it.next(); if (currScope.defMap.containsKey(name)) { newDef.undefWhat = currScope.defMap.remove(name); return; } } // Fourth look for a GLOBAL define if (globalDefMap.containsKey(name)) newDef.undefWhat = globalDefMap.remove(name); }
/** * @param instanceFrame instance frame * @return iterable over instance members of the frame, including those nested in namespaces */ public static Iterable<? extends INamedElement> instanceMembers( final IInstanceFrame instanceFrame) { final List<INamedElement> members = new ArrayList<>(); // Iterate over the member functions of the frame, including those nested in namespaces. final Deque<INamedElement> queue = new LinkedList<>(); queue.addLast(instanceFrame); while (!queue.isEmpty()) { final INamedElement cur = queue.getFirst(); queue.removeFirst(); final INamedElementContainer contCur = (INamedElementContainer) cur; for (final INamedElement member : contCur.members()) if (Ast.membership(member) == (contCur == instanceFrame ? ScopeMembership.InstanceMember : ScopeMembership.StaticMember)) { members.add(member); if (member instanceof INamedElementContainer) { // Tail-recursively treat this nested namespace. queue.addLast(member); } } } return members; }
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 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 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); }
@Override public void define(int line, int column, String name, String value, int type) { MacroDef newDef = new MacroDef(currRef, type, line, column); newDef.name = name; newDef.value = value; if (type == MacroDef.GLOBAL) globalDefMap.put(newDef.name, newDef); if (type == MacroDef.SCOPED) { Scope currScope = scopeStack.getFirst(); currScope.defMap.put(newDef.name, newDef); } currRef.macroEventList.add(newDef); }
private String getHostName(final HttpServerExchange exchange) { final Deque<String> host = exchange.getRequestHeaders().get(HOST); if (host != null) { String hostName = host.getFirst(); if (hostName.contains(":")) { hostName = hostName.substring(0, hostName.indexOf(":")); } return hostName; } return null; }
public double count() throws Exception { Deque<Double> ans = new ArrayDeque(10); for (Elem elem : deq) { if (elem.type == ElemType.NUM) { ans.addLast((Double) elem.value); } else if (elem.type == ElemType.VAR) { String f = (String) elem.value; if (f.equalsIgnoreCase("t")) { ans.addLast((double) time); } else if (f.equalsIgnoreCase("w")) { ans.addLast((double) w); } else if (f.equalsIgnoreCase("pi")) { ans.addLast(Math.PI); } else { throw new Exception("Unknown variable: \'" + f + "\'"); } } else { String f = (String) elem.value; if (f.equals("+")) { ans.addLast(ans.pollLast() + ans.pollLast()); } else if (f.equals("-")) { ans.addLast(-ans.pollLast() + ans.pollLast()); } else if (f.equals("*")) { ans.addLast(ans.pollLast() * ans.pollLast()); } else if (f.equals("/")) { ans.addLast(1d / ans.pollLast() * ans.pollLast()); } else if (f.equalsIgnoreCase("cos")) { ans.addLast(Math.cos(ans.pollLast())); } else if (f.equalsIgnoreCase("sin")) { ans.addLast(Math.sin(ans.pollLast())); } else if (f.equalsIgnoreCase("tg") || f.equalsIgnoreCase("tan")) { ans.addLast(Math.tan(ans.pollLast())); } else if (f.equalsIgnoreCase("ctg")) { ans.addLast(1d / Math.tan(ans.pollLast())); } else if (f.equalsIgnoreCase("abs")) { ans.addLast(Math.abs(ans.pollLast())); } else if (f.equalsIgnoreCase("sign")) { ans.addLast(Math.signum(ans.pollLast())); } else if (f.equalsIgnoreCase("exp")) { ans.addLast(Math.exp(ans.pollLast())); } else if (f.equalsIgnoreCase("ln")) { ans.addLast(Math.log(ans.pollLast())); } else if (f.equalsIgnoreCase("lg")) { ans.addLast(Math.log10(ans.pollLast())); } else { throw new Exception("Unknown function: \'" + f + "\'"); } } } return ans.getFirst(); }
private static void add(float x, float y) { Deque<Vector2f> tmp = new ArrayDeque<Vector2f>(); while (!graphRes.isEmpty() && graphRes.getFirst().x < x) { tmp.addLast(graphRes.pollFirst()); } tmp.addLast(new Vector2f(x, y)); while (!graphRes.isEmpty()) { tmp.addLast(graphRes.pollFirst()); } graphRes = tmp; while (y / graph1dY > height) { frame.jSliderdY1.setValue(frame.jSliderdY1.getValue() + 1); } }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { String elem = localName; if (elem.isEmpty()) { elem = qName; } // check doc structure sanity if (!elemStack.getFirst().equals(elem)) { throw new IllegalStateException( String.format("Elem ending expected: %s, but was: %s", elemStack.getFirst(), elem)); } ElementHandler elemHandler = handlerStack.removeFirst(); if (sb != null) { String txt = sb.toString(); // ! txt.trim(); elemHandler.characters(txt); sb = null; } elemHandler.endElement(); elemStack.removeFirst(); }
public void discardRemainder() throws XMLStreamException { final Context context = stack.getFirst(); if (context.depth > 0) { try { doDiscard(); } finally { context.depth--; } } else { try { throw readPastEnd(getLocation()); } finally { safeClose(); } } }
/** * 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); } }
/** * @param fn function * @return eventual overrides of the function, unifying those differing only in generic derivation */ public static Iterable<? extends IFunction> eventualOverrides(final IFunction fn) { // Iterate over the eventually overridden functions, // unifying those differing only through generic derivation. final Set<IFunction> processedEO = new LinkedHashSet<>(); final Deque<IFunction> queueEO = new LinkedList<>(); queueEO.addLast(fn); while (!queueEO.isEmpty()) { final IFunction fnEO = queueEO.getFirst(); queueEO.removeFirst(); if (!processedEO.contains(fnEO)) { processedEO.add(fnEO); // Tail-recurse on the function's direct overrides. for (final ResolvedName directOverride : fnEO.directOverrides()) queueEO.addLast((IFunction) directOverride.namedElement()); } } return processedEO; }
public int nextTag() throws XMLStreamException { final Context context = stack.getFirst(); if (context.depth > 0) { final int next = streamReader.nextTag(); if (next == END_ELEMENT) { context.depth--; } else if (next == START_ELEMENT) { context.depth++; } return next; } else { try { throw readPastEnd(getLocation()); } finally { safeClose(); } } }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { String elem = localName; if (elem.isEmpty()) { elem = qName; } elemStack.addFirst(elem); ElementHandler contextHandler = handlerStack.getFirst(); ElementHandler elemHandler = contextHandler.getHandler(elem); if (elemHandler == null) { throw new IllegalStateException( String.format( "Context handler %s have not returned handler for elem %s", contextHandler, elemStack)); } handlerStack.addFirst(elemHandler); elemHandler.startElement(attributes); }
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; }
/** * Find a MacroDef by name. NOTE: I have not yet implemented {*} and other such built-in macro * reference tricks. Not sure how soon I'll need those. There's a good chance that this function * will return null. */ private MacroDef findMacroDef(String name) { MacroDef ret; Scope currScope = scopeStack.getFirst(); // First look for local SCOPED define ret = currScope.defMap.get(name); if (ret != null) return ret; // Second look for a named include file argument ret = currInclude.lookupNamedArg(name); if (ret != null) return ret; // Third look for a non-local SCOPED define Iterator<Scope> it = scopeStack.iterator(); it.next(); // skip the current scope - already checked. while (it.hasNext()) { currScope = it.next(); ret = currScope.defMap.get(name); if (ret != null) return ret; } // Fourth look for a GLOBAL define ret = globalDefMap.get(name); return ret; }
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; } }
@Override public MSEOccurrence getCurrentMSEOccurrence() { if (_mseOccurences.size() > 0) return _mseOccurences.getFirst(); else return null; }
public boolean hasNext() throws XMLStreamException { return stack.getFirst().depth > 0 && streamReader.hasNext(); }
@Override public void sawOpcode(int seen) { try { int removed = 0; if (!ifBlocks.isEmpty()) { Iterator<IfBlock> it = ifBlocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if ((getPC() >= block.getEnd())) { it.remove(); removed++; } } } if (removed > 1) { activeUnconditional = null; } if (!casePositions.isEmpty() && (casePositions.getFirst().intValue() == getPC())) { casePositions.removeFirst(); activeUnconditional = null; lookingForResetOp = true; } if (lookingForResetOp) { if (isResetOp(seen)) { lookingForResetOp = false; } else { return; } } if (isBranch(seen)) { if (activeUnconditional != null) { activeUnconditional = null; if (!ifBlocks.isEmpty()) { ifBlocks.removeLast(); } lookingForResetOp = true; } int target = getBranchTarget(); if (getBranchOffset() > 0) { if ((seen == GOTO) || (seen == GOTO_W)) { gotoBranchPCs.set(target); } else if ((catchPCs == null) || !catchPCs.get(getNextPC())) { ifBlocks.addLast(new IfBlock(getNextPC(), target)); } } else { removeLoopBlocks(target); } } else if (isReturn(seen)) { if ((activeUnconditional != null) && !gotoBranchPCs.get(activeUnconditional.getEnd())) { int ifSize = activeUnconditional.getEnd() - activeUnconditional.getStart(); int elseSize = getPC() - activeUnconditional.getEnd(); double ratio = (double) ifSize / (double) elseSize; if (ratio > lowBugRatioLimit) { bugReporter.reportBug( new BugInstance( this, BugType.BL_BURYING_LOGIC.name(), ratio > normalBugRatioLimit ? NORMAL_PRIORITY : LOW_PRIORITY) .addClass(this) .addMethod(this) .addSourceLineRange( this, activeUnconditional.getStart(), activeUnconditional.getEnd())); throw new StopOpcodeParsingException(); } } else if (!ifBlocks.isEmpty() && (getNextPC() == ifBlocks.getFirst().getEnd()) && !gotoAcrossPC(getNextPC())) { activeUnconditional = ifBlocks.getFirst(); } } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { int[] offsets = getSwitchOffsets(); int pc = getPC(); for (int offset : offsets) { casePositions.addFirst(Integer.valueOf(pc + offset)); } } } finally { stack.sawOpcode(this, seen); } }
public String getCurrentQuery() { return queries.getFirst(); }
@Override public void includeEnd() { scopeStack.removeFirst(); currInclude = scopeStack.getFirst().includeRef; currRef = currRef.getParent(); }
@Override public T front() { return sequence.getFirst(); }
public Outline getConverted() { return converted.getFirst(); }
public Component getNewRep(String format) { // sort on format type if (format.equals("checkbox")) { // this only makes sense if there are exactly two options ComboCheckBox b = new ComboCheckBox(_value, this); comboCBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("radiobuttons")) { ComboRadioButtons b = new ComboRadioButtons(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("onradiobutton")) { ComboRadioButtons b = new ComboOnRadioButton(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("offradiobutton")) { ComboRadioButtons b = new ComboOffRadioButton(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("tree")) { DefaultTreeModel dModel = new DefaultTreeModel(treeNodes.getFirst()); JTree dTree = new JTree(dModel); trees.add(dTree); JScrollPane dScroll = new JScrollPane(dTree); dTree.setRootVisible(false); dTree.setShowsRootHandles(true); dTree.setScrollsOnExpand(true); dTree.setExpandsSelectedPaths(true); dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); // arrange for only leaf nodes can be selected dTree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath[] paths = e.getPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode o = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if (o.getChildCount() > 0) { ((JTree) e.getSource()).removeSelectionPath(paths[i]); } } // now record selection if (paths.length >= 1) { if (paths[0].getLastPathComponent() instanceof TreeLeafNode) { // update value of Variable setValue(_valueArray[((TreeLeafNode) paths[0].getLastPathComponent()).index]); } } } }); // select initial value TreePath path = _pathArray[_value.getSelectedIndex()]; dTree.setSelectionPath(path); // ensure selection is in visible portion of JScrollPane dTree.scrollPathToVisible(path); if (getReadOnly()) { log.error("read only variables cannot use tree format: {}", item()); } updateRepresentation(dScroll); return dScroll; } else { // return a new JComboBox representing the same model VarComboBox b = new VarComboBox(_value.getModel(), this); comboVars.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } }