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

The following examples show how to use java.util.Stack#indexOf() . 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: DefaultModuleDescriptor.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void checkConf(Stack<String> confs, String confName) {
    int index = confs.indexOf(confName);
    if (index != -1) {
        StringBuilder cycle = new StringBuilder();
        for (; index < confs.size(); index++) {
            cycle.append(confs.get(index)).append(" => ");
        }
        cycle.append(confName);
        throw new IllegalStateException("illegal cycle detected in configuration extension: "
                + cycle);
    }
    Configuration conf = getConfiguration(confName);
    if (conf == null) {
        throw new IllegalStateException("unknown configuration '" + confName
                + "'. It is extended by " + confs.get(confs.size() - 1));
    }
    for (String ext : conf.getExtends()) {
        confs.push(conf.getName());
        checkConf(confs, ext.trim());
        confs.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: PathFinder.java    From algorithms101 with MIT License 5 votes vote down vote up
private boolean hasPath(Stack<Integer> path, int from, int to) {
    if (path.contains(from) && path.contains(to)) {
        if (path.indexOf(from) < path.indexOf(to)) { // from must be before
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: FacetContext.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void discoverWithDependencies(Class<? extends F> type, Stack<F> stack) {
    final F facet = facet(type);
    if(!ordered.contains(facet)) {
        final int index = stack.indexOf(facet);
        if(index != -1) {
            // Guice supports this with proxies, but we don't, for now
            throw new IllegalStateException(
                "Circular facet dependency: " +
                Stream.concat(stack.subList(index, stack.size()).stream(), Stream.of(facet))
                      .map(f -> f.getClass().getSimpleName())
                      .collect(Collectors.joining(" -> "))
            );
        }

        stack.push(facet);
        try {
            Injection.dependencies(type).forEach(dependency -> {
                final Class<?> depType = Injection.dependencyType(dependency.getKey().getTypeLiteral()).getRawType();
                if(baseType.isAssignableFrom(depType)) {
                    discoverWithDependencies(depType.asSubclass(baseType), stack);
                }
            });
        } finally {
            stack.pop();
        }

        ordered.add(facet);
        discover(facet);
    }
}
 
Example 5
Source File: SwipeLayout.java    From FragmentRigger with MIT License 5 votes vote down vote up
@Nullable
private Activity getPreActivity() {
    if (mPuppetHost instanceof Activity) {
        Stack<Activity> stack = SwipeActivityManager.getInstance().getActivityStack();
        int index = stack.indexOf(mPuppetHost);
        if (index <= 0) {
            return null;
        }
        return stack.get(index - 1);
    }
    return null;
}
 
Example 6
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 7
Source File: StackUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenElementIsOnStack_thenIndexOfReturnsItsIndex() {
    Stack<Integer> intStack = new Stack<>();
    intStack.push(5);

    int indexOf = intStack.indexOf(5);

    assertEquals(0, indexOf);
}
 
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;
    }
}