Java Code Examples for java.util.Stack#remove()

The following examples show how to use java.util.Stack#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MathResolver.java    From vespa with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the internal list of operator-expression pairs into a corresponding combined grouping expression. When
 * this method returns there is no residue of the conversion, and this object can be reused.
 *
 * @return The grouping expression corresponding to the pushed arithmetic operations.
 */
public GroupingExpression resolve() {
    if (items.size() == 1) {
        return items.remove(0).exp; // optimize common case
    }
    Stack<Item> stack = new Stack<>();
    stack.push(items.remove(0));
    while (!items.isEmpty()) {
        Item item = items.remove(0);
        while (stack.size() > 1 && stack.peek().type.pre >= item.type.pre) {
            pop(stack);
        }
        stack.push(item);
    }
    while (stack.size() > 1) {
        pop(stack);
    }
    return stack.remove(0).exp;
}
 
Example 2
Source File: WolfWorkUSBImporter.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private int importOrphanedIslands(uSkyBlock plugin, File orphanFile) {
    try (ObjectInputStream in = new WolfWorkObjectInputStream(new FileInputStream(orphanFile))) {
        Object stackObj = in.readObject();
        if (stackObj instanceof Stack) {
            int countOrphan = 0;
            Stack<SerializableLocation> stack = (Stack) stackObj;
            while (!stack.isEmpty()) {
                SerializableLocation remove = stack.remove(0);
                plugin.getOrphanLogic().addOrphan(remove.getLocation());
                countOrphan++;
            }
            if (!orphanFile.delete()) {
                orphanFile.deleteOnExit();
            }
            return countOrphan;
        }
    } catch (IOException | ClassNotFoundException e) {
        log(Level.WARNING, "Unable to read the orphanedIslands.bin file", e);
    }
    return 0;
}
 
Example 3
Source File: MarkupAbstractIndenter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void discardProcessedMarkupItems(Stack<MarkupItem> stack, int startIndex, int endIndex) {
    for (int index = endIndex; index >= startIndex; index--) {
        MarkupItem item = stack.get(index);
        // #198659 - when a document is not valid (eg. accicentally a tag was not closed)
        // then below assert can be triggered; disabling it for now
        //assert item.processed || item.virtual : "assumption here is that a tag within process tag must be either processed or perhaps virtual: item="+item+" stack="+(getStack().size() < 30 ? getStack() : "[too many items]");
        stack.remove(index);
    }
}
 
Example 4
Source File: PlainJsonDocumentSerializer.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private void writeResource(JsonGenerator gen, ResourceIdentifier resourceId,
		Map<ResourceIdentifier, Resource> resourceMap, Stack<ResourceIdentifier> inclusionStack,
		SerializerProvider serializerProvider) throws IOException {

	if (resourceId.getId() != null) {
		// new resources do not have an ID
		inclusionStack.add(resourceId.toIdentifier());
	}

	gen.writeStartObject();
	if (resourceId.getId() != null) {
		gen.writeStringField("id", resourceId.getId());
	}
	gen.writeStringField("type", resourceId.getType());

	if (resourceId instanceof Resource) {
		Resource resource = (Resource) resourceId;
		writeLinks(gen, resource.getLinks(), serializerProvider);
		writeMeta(gen, resource.getMeta(), serializerProvider);
		writeAttributes(gen, resource.getAttributes(), serializerProvider);
		writeRelationships(gen, resource.getRelationships(), resourceMap, inclusionStack, serializerProvider);
	}
	gen.writeEndObject();
	if (resourceId != null) {
		inclusionStack.remove(resourceId);
	}
}
 
Example 5
Source File: Solution.java    From codekata with MIT License 5 votes vote down vote up
public List<Point> outerTrees(Point[] points) {
    Arrays.sort(points, new Comparator<Point>() {
        @Override
        public int compare(Point p1, Point p2) {
            return p1.x == p2.x ? p1.y - p2.y : p1.x - p2.x;
        }
    });

    Stack<Point> result = new Stack<>();

    for (Point point : points) {
        while (result.size() > 1 && isValid(result.get(result.size() - 2), result.peek(), point)) {
            result.pop();
        }
        result.add(point);
    }
    if (result.size() == points.length) return result;

    for (int i = points.length - 2; i > 0; i--) {
        while (result.size() > 1 && isValid(result.get(result.size() - 2), result.peek(), points[i])) {
            result.pop();
        }
        result.add(points[i]);
    }

    while (isValid(result.get(result.size() - 2), result.peek(), result.get(0))) {
        result.remove(result.size() - 1);
    }
    return result;
}
 
Example 6
Source File: MathResolver.java    From vespa with Apache License 2.0 5 votes vote down vote up
public Expression resolve() {
    Stack<Item> stack = new Stack<>();
    stack.push(items.remove(0));
    while (!items.isEmpty()) {
        Item item = items.remove(0);
        while (stack.size() > 1 && stack.peek().op.precedes(item.op)) {
            pop(stack);
        }
        stack.push(item);
    }
    while (stack.size() > 1) {
        pop(stack);
    }
    return stack.remove(0).exp;
}
 
Example 7
Source File: PLAAbsListView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
/**
 * @return A view from the ScrapViews collection. These are unordered.
 */
View getScrapView(int position) {

    if(getHeaderViewsCount() > position){
        //non scraped view.
        return null;
    }

    final Stack<View> scrapViews;
    if (mViewTypeCount == 1) {
        scrapViews = mCurrentScrap;
    } else {
        final int whichScrap = mAdapter.getItemViewType(position);
        if (whichScrap >= 0 && whichScrap < mScrapViews.length) {
            scrapViews = mScrapViews[whichScrap];
        } else {
            return null;
        }
    }

    // look for the exact same layout
    int size = scrapViews.size();
    for(int i = size - 1; i >= 0; --i) {
        final LayoutParams lp = (LayoutParams) scrapViews.get(i).getLayoutParams();
        if(lp.scrappedFromPosition == position) {
            return scrapViews.remove(i);
        }
    }

    if (size > 0) {
        // reused the oldest one.
        return scrapViews.remove(0);
    } else {
        return null;
    }
}
 
Example 8
Source File: PLAAbsListView.java    From Lay-s with MIT License 5 votes vote down vote up
/**
 * @return A view from the ScrapViews collection. These are unordered.
 */
View getScrapView(int position) {

    if(getHeaderViewsCount() > position){
        //non scraped view.
        return null;
    }

    final Stack<View> scrapViews;
    if (mViewTypeCount == 1) {
        scrapViews = mCurrentScrap;
    } else {
        final int whichScrap = mAdapter.getItemViewType(position);
        if (whichScrap >= 0 && whichScrap < mScrapViews.length) {
            scrapViews = mScrapViews[whichScrap];
        } else {
            return null;
        }
    }

    // look for the exact same layout
    int size = scrapViews.size();
    for(int i = size - 1; i >= 0; --i) {
        final LayoutParams lp = (LayoutParams) scrapViews.get(i).getLayoutParams();
        if(lp.scrappedFromPosition == position) {
            return scrapViews.remove(i);
        }
    }

    if (size > 0) {
        // reused the oldest one.
        return scrapViews.remove(0);
    } else {
        return null;
    }
}
 
Example 9
Source File: RTOperationManager.java    From memoir with Apache License 2.0 4 votes vote down vote up
private void push(Operation op, Stack<Operation> stack) {
    if (stack.size() >= MAX_NR_OF_OPERATIONS) {
        stack.remove(0);
    }
    stack.push(op);
}
 
Example 10
Source File: RTOperationManager.java    From memoir with Apache License 2.0 4 votes vote down vote up
private void push(Operation op, Stack<Operation> stack) {
    if (stack.size() >= MAX_NR_OF_OPERATIONS) {
        stack.remove(0);
    }
    stack.push(op);
}
 
Example 11
Source File: Analysis_Timed.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
private static boolean checkStack(PrjState nextPrjState, PrjState stateStackTop,
			Stack<LinkedList<Transition>> lpnTranStack, Stack<Integer> curIndexStack,
			HashSet<PrjState> stateStack, boolean subsets,
			boolean supersets){
		
		boolean existingState = false;
		
		if(!subsets && !supersets){
			return stateStack.contains(nextPrjState);
		}
		
		ZoneType nextZone = ((TimedState) nextPrjState.get(0)).getZone();
		
		PrjState stackStateIterator = stateStackTop;
		int stackDepth = 1;
		while(stackStateIterator != null){
			
			if(!projectUntimedEquals(nextPrjState, stackStateIterator)){
				stackStateIterator = stackStateIterator.getFather();
				stackDepth++;
				continue;
			}
			
			ZoneType iteratorZone = ((TimedState) stackStateIterator.get(0)).getZone();
			
			// Check for subset.
			if(subsets && nextZone.subset(iteratorZone) 
					|| (nextZone.equals(iteratorZone))){
				
//				if(supersets){
//					existingState |= true;
//				}
//				else{
				existingState = true;
				break;
				//}
			}
			
			if(!supersets){
				stackStateIterator = stackStateIterator.getFather();
				stackDepth++;
				continue;
			}

			// Check for the superset.
			if(iteratorZone.subset(nextZone)){
				PrjState father = stackStateIterator.getFather();
				PrjState child = stackStateIterator.getChild();

				if(child != null){
					child.setFather(father);
				}
				if(father != null){
					father.setChild(child);
				}


				// Remove the corresponding items on the stacks and state set.
				lpnTranStack.remove(lpnTranStack.size() - stackDepth);
				curIndexStack.remove(curIndexStack.size() - stackDepth);
				stateStack.remove(stackStateIterator);
				
				stackStateIterator = stackStateIterator.getFather();
				continue;
			}

			stackStateIterator = stackStateIterator.getFather();
			stackDepth++;
		}
		
		
		return existingState;
	}
 
Example 12
Source File: RTOperationManager.java    From Android-RTEditor with Apache License 2.0 4 votes vote down vote up
private void push(Operation op, Stack<Operation> stack) {
    if (stack.size() >= MAX_NR_OF_OPERATIONS) {
        stack.remove(0);
    }
    stack.push(op);
}
 
Example 13
Source File: Timeline.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public Shape getOutline(int frame, int time, RenderContext renderContext, Matrix transformation, boolean stroked) {
    Frame fr = getFrame(frame);
    Area area = new Area();
    Stack<Clip> clips = new Stack<>();
    for (int d = maxDepth; d >= 0; d--) {
        Clip currentClip = null;
        for (int i = clips.size() - 1; i >= 0; i--) {
            Clip cl = clips.get(i);
            if (cl.depth <= d) {
                clips.remove(i);
            }
        }
        if (!clips.isEmpty()) {
            currentClip = clips.peek();
        }
        DepthState layer = fr.layers.get(d);
        if (layer == null) {
            continue;
        }
        if (!layer.isVisible) {
            continue;
        }
        CharacterTag character = swf.getCharacter(layer.characterId);
        if (character instanceof DrawableTag) {
            DrawableTag drawable = (DrawableTag) character;
            Matrix m = transformation.concatenate(new Matrix(layer.matrix));

            int drawableFrameCount = drawable.getNumFrames();
            if (drawableFrameCount == 0) {
                drawableFrameCount = 1;
            }

            int dframe = time % drawableFrameCount;
            if (character instanceof ButtonTag) {
                dframe = ButtonTag.FRAME_UP;
                if (renderContext.cursorPosition != null) {
                    ButtonTag buttonTag = (ButtonTag) character;
                    Shape buttonShape = buttonTag.getOutline(ButtonTag.FRAME_HITTEST, time, layer.ratio, renderContext, m, stroked);
                    if (buttonShape.contains(renderContext.cursorPosition)) {
                        if (renderContext.mouseButton > 0) {
                            dframe = ButtonTag.FRAME_DOWN;
                        } else {
                            dframe = ButtonTag.FRAME_OVER;
                        }
                    }
                }
            }

            Shape cshape = ((DrawableTag) character).getOutline(dframe, time, layer.ratio, renderContext, m, stroked);
            Area addArea = new Area(cshape);
            if (currentClip != null) {
                Area a = new Area(new Rectangle(displayRect.Xmin, displayRect.Ymin, displayRect.getWidth(), displayRect.getHeight()));
                a.subtract(new Area(currentClip.shape));
                addArea.subtract(a);
            }

            if (layer.clipDepth > -1) {
                Clip clip = new Clip(addArea, layer.clipDepth);
                clips.push(clip);
            } else {
                area.add(addArea);
            }
        }
    }
    return area;
}