indexOf ( )源码实例Demo

java.util.Stack#indexOf ( )源码实例Demo

下面列出了java.util.Stack#indexOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ant-ivy   文件: DefaultModuleDescriptor.java
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();
    }
}
 
源代码2 项目: tomee   文件: References.java
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();
}
 
源代码3 项目: algorithms101   文件: PathFinder.java
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;
}
 
源代码4 项目: ProjectAres   文件: FacetContext.java
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);
    }
}
 
源代码5 项目: FragmentRigger   文件: SwipeLayout.java
@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;
}
 
源代码6 项目: ant-ivy   文件: IvyPatternHelper.java
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();
}
 
源代码7 项目: tutorials   文件: StackUnitTest.java
@Test
public void whenElementIsOnStack_thenIndexOfReturnsItsIndex() {
    Stack<Integer> intStack = new Stack<>();
    intStack.push(5);

    int indexOf = intStack.indexOf(5);

    assertEquals(0, indexOf);
}
 
源代码8 项目: ant-ivy   文件: IvyPatternHelper.java
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;
    }
}