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

The following examples show how to use java.util.Stack#subList() . 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: ReferenceProcessor.java    From spoon-examples with GNU General Public License v2.0 6 votes vote down vote up
void scanDependencies(Stack<CtPackageReference> path) {
	CtPackageReference ref = path.peek();
	// return if already scanned
	if (scanned.contains(ref)) {
		return;
	}
	scanned.add(ref);
	Set<CtPackageReference> refs = packRefs.get(ref);
	if (refs != null) {
		for (CtPackageReference p : refs) {
			if (path.contains(p)) {
				List<CtPackageReference> circularPath = new ArrayList<>(
						path.subList(path.indexOf(p), path.size()));
				circularPath.add(p);

				circularPathes.add(circularPath);
				break;
			} else {
				path.push(p);
				scanDependencies(path);
				path.pop();
			}
		}
	}
}
 
Example 2
Source File: References.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static void findCircuits(final Set<Circuit> circuits, final Node node, final Stack<Node> stack) {
    if (stack.contains(node)) {
        final int fromIndex = stack.indexOf(node);
        final int toIndex = stack.size();
        final ArrayList<Node> circularity = new ArrayList<>(stack.subList(fromIndex, toIndex));

        // add ending node to list so a full circuit is shown
        circularity.add(node);

        final Circuit circuit = new Circuit(circularity);

        circuits.add(circuit);

        return;
    }

    stack.push(node);

    for (final Node reference : node.initialReferences) {
        findCircuits(circuits, reference, stack);
    }

    stack.pop();
}
 
Example 3
Source File: StackOperators.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public void execute(ExecutionContext context)
{
    Stack<Object> stack = context.getStack();
    int n = ((Number)stack.pop()).intValue();
    if (n > 0)
    {
        int size = stack.size();
        //Need to copy to a new list to avoid ConcurrentModificationException
        List<Object> copy = new java.util.ArrayList<Object>(
                stack.subList(size - n, size));
        stack.addAll(copy);
    }
}
 
Example 4
Source File: StackOperators.java    From sambox with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ExecutionContext context)
{
    Stack<Object> stack = context.getStack();
    int n = ((Number) stack.pop()).intValue();
    if (n > 0)
    {
        int size = stack.size();
        // Need to copy to a new list to avoid ConcurrentModificationException
        List<Object> copy = new java.util.ArrayList<Object>(stack.subList(size - n, size));
        stack.addAll(copy);
    }
}
 
Example 5
Source File: IvyPatternHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static String substituteParams(String pattern, IvyVariableContainer params,
        Stack<String> substituting) {
    // TODO : refactor this with substituteVariables
    // if you supply null, null is what you get
    if (pattern == null) {
        return null;
    }

    Matcher m = PARAM_PATTERN.matcher(pattern);

    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String var = m.group(1);
        String val = params.getVariable(var);
        if (val != null) {
            int index = substituting.indexOf(var);
            if (index != -1) {
                List<String> cycle = new ArrayList<>(substituting.subList(index, substituting.size()));
                cycle.add(var);
                throw new IllegalArgumentException("cyclic param definition: cycle = " + cycle);
            }
            substituting.push(var);
            val = substituteVariables(val, params, substituting);
            substituting.pop();
        } else {
            val = m.group();
        }
        m.appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\@", "\\\\\\@"));
    }
    m.appendTail(sb);

    return sb.toString();
}
 
Example 6
Source File: StackOperators.java    From PdfBox-Android with Apache License 2.0 5 votes vote down vote up
public void execute(ExecutionContext context)
{
    Stack<Object> stack = context.getStack();
    int n = ((Number)stack.pop()).intValue();
    if (n > 0)
    {
        int size = stack.size();
        //Need to copy to a new list to avoid ConcurrentModificationException
        List<Object> copy = new java.util.ArrayList<Object>(
                stack.subList(size - n, size));
        stack.addAll(copy);
    }
}
 
Example 7
Source File: PrintClassHierarchy.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
private void printHierarchy(final String clazzName, final Stack<Boolean> moreClassesInHierarchy) {
	if (!moreClassesInHierarchy.empty()) {
		for (final Boolean hasColumn : moreClassesInHierarchy.subList(0, moreClassesInHierarchy.size() - 1)) {
			System.out.print(hasColumn.booleanValue() ? PADDING_WITH_COLUMN : PADDING);
		}
	}

	if (!moreClassesInHierarchy.empty()) {
		System.out.print(PADDING_WITH_ENTRY);
	}

	System.out.println(clazzName);

	if (subClazzEntries.containsKey(clazzName)) {
		final List<String> list = subClazzEntries.get(clazzName);

		for (int i = 0; i < list.size(); i++) {
			// if there is another class that comes beneath the next class,
			// flag this level
			moreClassesInHierarchy.push(new Boolean(i < list.size() - 1));

			printHierarchy(list.get(i), moreClassesInHierarchy);

			moreClassesInHierarchy.removeElementAt(moreClassesInHierarchy.size() - 1);
		}
	}
}
 
Example 8
Source File: IvyPatternHelper.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private static String substituteVariables(String pattern, IvyVariableContainer variables,
        Stack<String> substituting) {
    // if you supply null, null is what you get
    if (pattern == null) {
        return null;
    }

    Matcher m = VAR_PATTERN.matcher(pattern);

    boolean useVariables = false;
    StringBuffer sb = null;
    while (m.find()) {
        if (!useVariables) {
            useVariables = true;
            sb = new StringBuffer();
        }
        String var = m.group(1);
        String val = variables.getVariable(var);
        if (val != null) {
            int index = substituting.indexOf(var);
            if (index != -1) {
                List<String> cycle = new ArrayList<>(substituting.subList(index, substituting.size()));
                cycle.add(var);
                throw new IllegalArgumentException("cyclic variable definition: cycle = "
                        + cycle);
            }
            substituting.push(var);
            val = substituteVariables(val, variables, substituting);
            substituting.pop();
        } else {
            val = m.group();
        }
        m.appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\$", "\\\\\\$"));
    }
    if (useVariables) {
        m.appendTail(sb);
        return sb.toString();
    } else {
        return pattern;
    }
}