Example usage for java.util LinkedList push

List of usage examples for java.util LinkedList push

Introduction

In this page you can find the example usage for java.util LinkedList push.

Prototype

public void push(E e) 

Source Link

Document

Pushes an element onto the stack represented by this list.

Usage

From source file:com.ikanow.aleph2.analytics.spark.utils.SparkTechnologyUtils.java

/** Validate the job
 * @param new_analytic_bucket/*from   w  w  w  .  j  ava 2  s  .c o m*/
 * @param jobs
 * @return
 */
public static BasicMessageBean validateJobs(final DataBucketBean new_analytic_bucket,
        final Collection<AnalyticThreadJobBean> jobs) {

    //TODO (ALEPH-63): validate batch enrichment            

    final LinkedList<String> mutable_errs = new LinkedList<>();

    jobs.stream().forEach(job -> {
        if (null == job.config()) {
            mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM, new_analytic_bucket.full_name(),
                    job.name(), "config"));
        } else {
            final SparkTopologyConfigBean config = BeanTemplateUtils
                    .from(job.config(), SparkTopologyConfigBean.class).get();
            if (SparkType.jvm == Optional.ofNullable(config.language()).orElse(SparkType.jvm)) { // JVM validation
                if (null == config.entry_point()) {
                    mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM,
                            new_analytic_bucket.full_name(), job.name(), "config.entry_point"));
                }
            } else if (SparkType.python == Optional.ofNullable(config.language()).orElse(SparkType.jvm)) { // JVM validation
                if ((null == config.entry_point()) && (null == config.script())) {
                    mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM,
                            new_analytic_bucket.full_name(), job.name(), "config.entry_point|config.script"));
                }
            }
        }
    });

    return ErrorUtils.buildMessage(mutable_errs.isEmpty(), SparkTechnologyUtils.class, "validateJobs",
            mutable_errs.stream().collect(Collectors.joining(";")));
}

From source file:com.codenvy.commons.lang.TarUtils.java

private static void addDirectoryRecursively(TarArchiveOutputStream tarOut, String parentPath, File dir,
        long modTime, FilenameFilter filter) throws IOException {
    final int parentPathLength = parentPath.length() + 1;
    final LinkedList<File> q = new LinkedList<>();
    q.add(dir);/*from  w w w  .  j av  a 2s .c o  m*/
    while (!q.isEmpty()) {
        final File current = q.pop();
        final File[] list = current.listFiles();
        if (list != null) {
            for (File f : list) {
                if (filter.accept(current, f.getName())) {
                    final String entryName = f.getAbsolutePath().substring(parentPathLength).replace('\\', '/');
                    if (f.isDirectory()) {
                        addDirectoryEntry(tarOut, entryName, f, modTime);
                        q.push(f);
                    } else if (f.isFile()) {
                        addFileEntry(tarOut, entryName, f, modTime);
                    }
                }
            }
        }
    }
}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

private static int bfsDepth(List<TreeNode> roots) {
    LinkedList<TreeNode> queue = Lists.newLinkedList();
    for (TreeNode root : roots) {
        root.setLayer(0);/*from  w  w  w  .j  a va  2s  .  c  om*/
        queue.push(root);
    }

    int depth = 0;
    while (!queue.isEmpty()) {
        TreeNode cur = queue.poll();
        if (cur.getLayer() > depth) {
            depth = cur.getLayer();
        }
        for (TreeNode n : cur.getChildren()) {

            int newLayer = cur.getLayer() + 1;
            if (!n.isVisited() || n.getLayer() < newLayer) {
                if (!n.inCircle(cur)) {
                    //n and cur is not in loop
                    n.setLayer(newLayer);
                    if (!queue.contains(n)) {
                        queue.push(n);
                    }
                } else if (n.addLoopNode(cur)) {
                    // loop nodes only set layer once.
                    n.setLayer(newLayer);
                }
            }

        }
    }
    return depth;
}

From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java

/**
 * Gets the hierarchy of a given class.//from w  w w .j  a v a 2  s.c o  m
 *
 * @author paouelle
 *
 * @param <T> the type of the class to get the hierarchy for
 *
 * @param  clazz the class to get the hierarchy for
 * @return a list of all classes in the given class's hierarchy starting with
 *         the specified class
 */
public static <T> List<Class<?>> getClassHierarchy(Class<?> clazz) {
    org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class");
    final LinkedList<Class<?>> classes = new LinkedList<>();

    while (clazz != null) {
        classes.push(clazz);
        clazz = clazz.getSuperclass();
    }
    return classes;
}

From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java

/**
 * Gets all declared members of a given type (up the super class hierarchy).
 *
 * @author paouelle//w  w  w.  j  a  va2s  .c  om
 *
 * @param <T> the type of members to retrieve (either {@link Field},
 *            {@link Method}, or {@link Constructor})
 *
 * @param  type the type of members to retrieve
 * @param  clazz the class from which to find all declared members
 * @param  up <code>true</code> to look up the class hierarchy;
 *         <code>false</code> to only look at the specified class level
 * @return a list in the provided order for all declared members
 * @throws NullPointerException if <code>type</code> or
 *         <code>clazz</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>type</code> is not
 *         {@link Field}, {@link Method}, or {@link Constructor}
 */
public static <T extends Member> List<T> getAllDeclaredMembers(Class<T> type, Class<?> clazz, boolean up) {
    org.apache.commons.lang3.Validate.notNull(type, "invalid null member type");
    org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class");
    final LinkedList<Class<?>> classes = new LinkedList<>();

    if (up) {
        while (clazz != null) {
            classes.push(clazz);
            clazz = clazz.getSuperclass();
        }
    } else {
        classes.push(clazz);
    }
    final List<T> members = new ArrayList<>(12);

    while (!classes.isEmpty()) {
        clazz = classes.pop();
        for (final T m : ReflectionUtils.getDeclaredMembers(type, clazz)) {
            members.add(m);
        }
    }
    return members;
}

From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java

/**
 * Gets all members of a given type (up the super class hierarchy) annotated
 * with the specified annotation.//from w w  w . j a  v a  2s . c o  m
 *
 * @author paouelle
 *
 * @param <T> the type of members to retrieve (either {@link Field},
 *            {@link Method}, or {@link Constructor})
 *
 * @param  type the type of members to retrieve
 * @param  clazz the class from which to find all annotated members
 * @param  annotation the annotation for which to find all members
 * @param  up <code>true</code> to look up the class hierarchy;
 *         <code>false</code> to only look at the specified class level
 * @return a list in the provided order for all annotated members
 * @throws NullPointerException if <code>type</code>,
 *         <code>clazz</code> or <code>annotation</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>type</code> is not
 *         {@link Field}, {@link Method}, or {@link Constructor}
 */
public static <T extends Member> List<T> getAllMembersAnnotatedWith(Class<T> type, Class<?> clazz,
        Class<? extends Annotation> annotation, boolean up) {
    org.apache.commons.lang3.Validate.notNull(type, "invalid null member type");
    org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class");
    org.apache.commons.lang3.Validate.notNull(annotation, "invalid null annotation class");
    final LinkedList<Class<?>> classes = new LinkedList<>();

    if (up) {
        while (clazz != null) {
            classes.push(clazz);
            clazz = clazz.getSuperclass();
        }
    } else {
        classes.push(clazz);
    }
    final List<T> members = new ArrayList<>(12);

    while (!classes.isEmpty()) {
        clazz = classes.pop();
        for (final T m : ReflectionUtils.getDeclaredMembers(type, clazz)) {
            if ((m instanceof AnnotatedElement)
                    && ((AnnotatedElement) m).getAnnotationsByType(annotation).length > 0) {
                members.add(m);
            }
        }
    }
    return members;
}

From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java

/**
 * Gets all members of a given type (up the super class hierarchy) annotated
 * with the specified annotation./*from  w ww  . ja va 2 s  .  c  o  m*/
 *
 * @author paouelle
 *
 * @param <T> the type of members to retrieve (either {@link Field},
 *            {@link Method}, or {@link Constructor})
 * @param <A> the type of annotation to search for
 *
 * @param  type the type of members to retrieve
 * @param  clazz the class from which to find all annotated members
 * @param  annotation the annotation for which to find all members
 * @param  up <code>true</code> to look up the class hierarchy;
 *         <code>false</code> to only look at the specified class level
 * @return a non-<code>null</code> map in the provided order for all annotated
 *         members with their found annotations
 * @throws NullPointerException if <code>type</code>,
 *         <code>clazz</code> or <code>annotation</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>type</code> is not
 *         {@link Field}, {@link Method}, or {@link Constructor}
 */
public static <T extends Member, A extends Annotation> Map<T, A[]> getAllAnnotationsForMembersAnnotatedWith(
        Class<T> type, Class<?> clazz, Class<A> annotation, boolean up) {
    org.apache.commons.lang3.Validate.notNull(type, "invalid null member type");
    org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class");
    org.apache.commons.lang3.Validate.notNull(annotation, "invalid null annotation class");
    final LinkedList<Class<?>> classes = new LinkedList<>();

    if (up) {
        while (clazz != null) {
            classes.push(clazz);
            clazz = clazz.getSuperclass();
        }
    } else {
        classes.push(clazz);
    }
    final Map<T, A[]> members = new LinkedHashMap<>(12);

    while (!classes.isEmpty()) {
        clazz = classes.pop();
        for (final T m : ReflectionUtils.getDeclaredMembers(type, clazz)) {
            if (m instanceof AnnotatedElement) {
                final A[] as = ((AnnotatedElement) m).getAnnotationsByType(annotation);

                if (as.length > 0) {
                    members.put(m, as);
                }
            }
        }
    }
    return members;
}

From source file:disko.AnalysisContext.java

protected LinkedList<HGHandle> getScope() {
    LinkedList<HGHandle> S = scope.get();
    if (S == null) {
        S = new LinkedList<HGHandle>();
        if (initialScope != null)
            S.push(initialScope);
        scope.set(S);/*from w  w w .j  a  v a  2  s .  co m*/
    }
    return S;
}

From source file:org.jdto.util.expression.Expression.java

/**
 * Parse the expression into something easily evaluable.
 * @param expression//from  w ww  . j av  a2s.co  m
 * @return 
 */
private synchronized ExpressionTerm parseExpression(String expression) {

    position = 0;

    LinkedList<String> precedenceStack = new LinkedList<String>();

    //add the first imaginary parentheses.
    precedenceStack.push("(");

    //append a closing parenthesis to the expression.
    expression = expression + ")";

    //the previous token.
    String token = null;

    StringBuilder postFix = new StringBuilder();

    /**
     * Go through the expression.
     */
    while (!precedenceStack.isEmpty() && position < expression.length()) {

        //use the token from previous iteration
        token = readToken(token, expression);

        //if is a left parentheses
        if ("(".equals(token)) {
            precedenceStack.push(token);
            postFix.append(" "); //a separation
            continue;
        }

        //check if it is an operator
        Operator operator = Operator.getOperaorByString(token);
        if (operator != null) {
            postFix.append(" "); //add a seprarator char to the result.
            while (operator.precedence(precedenceStack.peek())) {
                postFix.append(precedenceStack.pop());
                postFix.append(" ");
            }
            precedenceStack.push(token);
            continue;
        }

        //check if it is a right parenthesis
        if (")".equals(token)) {
            postFix.append(" "); //add a separator to the result.
            while (!"(".equals(precedenceStack.peek())) {
                String stackElement = precedenceStack.pop();

                if (isOperator(stackElement)) {
                    postFix.append(stackElement);
                    postFix.append(" ");
                }
            }
            //remove the extra parenthesis
            precedenceStack.pop();
            continue;
        }

        //if everything else fails, just add the token to the postfix expr
        postFix.append(token);
        //and we're done with the loop here
    }

    //at this point we need to convert the postfix expression into terms.
    if (!precedenceStack.isEmpty()) {
        throw new IllegalArgumentException("Could not parse expression!");
    }

    return parsePostfixExpr(postFix.toString());
}

From source file:com.bmwcarit.barefoot.markov.KState.java

/**
 * Gets the most likely sequence of state candidates <i>s<sub>0</sub>, s<sub>1</sub>, ...,
 * s<sub>t</sub></i>.// w  w w  . ja v a  2 s.co  m
 *
 * @return List of the most likely sequence of state candidates.
 */
public List<C> sequence() {
    if (sequence.isEmpty()) {
        return null;
    }

    C kestimate = null;

    for (C candidate : sequence.peekLast().one()) {
        if (kestimate == null || candidate.seqprob() > kestimate.seqprob()) {
            kestimate = candidate;
        }
    }

    LinkedList<C> ksequence = new LinkedList<>();

    for (int i = sequence.size() - 1; i >= 0; --i) {
        if (kestimate != null) {
            ksequence.push(kestimate);
            kestimate = kestimate.predecessor();
        } else {
            ksequence.push(sequence.get(i).one().iterator().next());
            assert (sequence.get(i).one().size() == 1);
        }
    }

    return ksequence;
}