Example usage for java.util Deque removeFirst

List of usage examples for java.util Deque removeFirst

Introduction

In this page you can find the example usage for java.util Deque removeFirst.

Prototype

E removeFirst();

Source Link

Document

Retrieves and removes the first element of this deque.

Usage

From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java

/**
 * <p>Rotate the component so that the first point is the leftmost.</p>
 * <p>Normalization doesnot make difference when reverse the Fourier series
 * but neuron networks may "feel" easier to recorgnize normalized series.</p>
 * @param points/* ww w . ja v  a 2s .  c o  m*/
 * @return
 */
private static Deque<Point> normalize(Deque<Point> c) {
    double leftmost = Double.MAX_VALUE;
    for (Point p : c) {
        if (p.x < leftmost) {
            leftmost = p.x;
        }
    }
    while (c.getFirst().x > leftmost) {
        c.addLast(c.removeFirst());
    }
    return c;
}

From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java

private Deque<Point> findConnectedComponent(int[] edgeData, int x, int y) {
    Deque<Point> points = new LinkedList<Point>();
    Deque<Point> queue = new LinkedList<Point>();

    edgeData[x + y * width] = WHITE;//  ww w  .  ja va  2  s.com
    Point initialPoint = new Point(x, y);
    points.add(initialPoint);
    queue.push(initialPoint);

    while (!queue.isEmpty()) {
        Point point = queue.removeFirst();
        for (int k = 0; k < 8; k++) {
            int x2 = (int) (point.x + DX[k]);
            int y2 = (int) (point.y + DY[k]);
            if (x2 < 0 || y2 < 0 || x2 >= width || y2 >= height) {
                continue;
            }
            if (edgeData[x2 + y2 * width] == BLACK) {
                edgeData[x2 + y2 * width] = WHITE;
                Point point2 = new Point(x2, y2);
                points.add(point2);
                queue.addLast(point2);
            }
        }
    }
    return points;
}

From source file:org.alfresco.repo.content.transform.TransformerLogger.java

/**
 * Removes an entry. By default removes the first (oldest) entry by may be overridden.
 *//*from  w  w w .j  a va  2  s . c o m*/
protected void remove(Deque<T> entries) {
    entries.removeFirst();
}

From source file:org.anarres.cpp.Main.java

static List<TokenS> replay(Deque<TokenS> input, List<Action> actions) {
    List<TokenS> result = new ArrayList<TokenS>();
    for (Action action : actions) {
        //            System.out.println("Action:" + action + " rest:" + input);
        if (action instanceof Skip) {
            TokenS actual = ((Skip) action).token;
            TokenS expected = input.removeFirst();
            if (!expected.equals(actual)) {
                throw new RuntimeException("Skipping " + actual + ", found " + expected + " input " + input);
            }/*from   www  . jav a  2  s  . co m*/
            result.add(actual);
        } else {
            Replace replace = (Replace) action;
            for (TokenS actual : replace.original) {
                TokenS expected = input.removeFirst();
                if (!expected.equals(actual)) {
                    System.err.println("At " + expected.token.getFile());
                    throw new RuntimeException(
                            "Expected " + expected + " old " + actual + " instead\n" + replace.toJson());
                }
            }
            List<TokenS> replSeq = new ArrayList<TokenS>();
            for (MapSeg mapSeg : replace.mapping) {
                if (mapSeg instanceof New) {
                    for (Token token : ((New) mapSeg).tokens) {
                        replSeq.add(new TokenS(token, Empty.bag()));
                    }
                } else {
                    Sub sub = (Sub) mapSeg;
                    Deque<TokenS> subInput = new LinkedList<>();
                    for (int i : sub.indicies) {
                        subInput.add(replace.original.get(i));
                    }
                    for (TokenS tokenS : replay(subInput, sub.actions)) {
                        replSeq.add(tokenS);
                    }
                }
            }
            for (int i = replSeq.size() - 1; i >= 0; i--) {
                TokenS tokenS = replSeq.get(i);
                input.addFirst(new TokenS(tokenS.token, tokenS.disables.plusAll(replace.disables)));
            }
        }
    }
    return result;
}

From source file:org.apache.sling.etcd.testing.tree.Node.java

@Nonnull
public static Deque<String> names(@Nonnull String key) {
    Deque<String> names = new ArrayDeque<String>(Arrays.asList(key.split("/")));
    if (!names.isEmpty()) {
        names.removeFirst();
    }//www . ja va  2 s .  c  o  m
    return names;
}

From source file:org.jaffa.qm.util.PropertyFilter.java

private static void getFieldList(Class clazz, List<String> fieldList, String prefix, Deque<Class> classStack)
        throws IntrospectionException {
    //To avoid recursion, bail out if the input Class has already been introspected
    if (classStack.contains(clazz)) {
        if (log.isDebugEnabled())
            log.debug("Fields from " + clazz + " prefixed by " + prefix
                    + " will be ignored, since the class has already been introspected as per the stack "
                    + classStack);/*from  w  ww .  j a v  a  2s  .c  o m*/
        return;
    } else
        classStack.addFirst(clazz);

    //Introspect the input Class
    BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
    if (beanInfo != null) {
        PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
        if (pds != null) {
            for (PropertyDescriptor pd : pds) {
                if (pd.getReadMethod() != null && pd.getWriteMethod() != null) {
                    String name = pd.getName();
                    String qualifieldName = prefix == null || prefix.length() == 0 ? name : prefix + '.' + name;
                    Class type = pd.getPropertyType();
                    if (type.isArray())
                        type = type.getComponentType();
                    if (type == String.class || type == Boolean.class || Number.class.isAssignableFrom(type)
                            || IDateBase.class.isAssignableFrom(type) || Currency.class.isAssignableFrom(type)
                            || type.isPrimitive() || type.isEnum())
                        fieldList.add(qualifieldName);
                    else
                        getFieldList(type, fieldList, qualifieldName, classStack);
                }
            }
        }
    }

    classStack.removeFirst();
}

From source file:org.nuxeo.ecm.core.storage.ExpressionEvaluator.java

private static Set<String> parseFullText(String string, int phraseSize) {
    if (string == null) {
        return Collections.emptySet();
    }/*from   w  w w . ja va  2  s.  c  o  m*/
    Set<String> set = new HashSet<String>();
    Deque<String> phraseWords = new LinkedList<>();
    for (String word : WORD_PATTERN.split(string)) {
        word = parseWord(word);
        if (word != null) {
            word = word.toLowerCase();
            set.add(word);
            if (phraseSize > 1) {
                phraseWords.addLast(word);
                if (phraseWords.size() > 1) {
                    if (phraseWords.size() > phraseSize) {
                        phraseWords.removeFirst();
                    }
                    addPhraseWords(set, phraseWords);
                }
            }
        }
    }
    while (phraseWords.size() > 2) {
        phraseWords.removeFirst();
        addPhraseWords(set, phraseWords);
    }
    return set;
}

From source file:org.nuxeo.ecm.core.storage.sql.PersistenceContext.java

/**
 * Removes a property node and its children.
 * <p>// w ww.jav a 2  s . co  m
 * There's less work to do than when we have to remove a generic document
 * node (less selections, and we can assume the depth is small so recurse).
 */
public void removePropertyNode(SimpleFragment hierFragment) throws StorageException {
    // collect children
    Deque<SimpleFragment> todo = new LinkedList<SimpleFragment>();
    List<SimpleFragment> children = new LinkedList<SimpleFragment>();
    todo.add(hierFragment);
    while (!todo.isEmpty()) {
        SimpleFragment fragment = todo.removeFirst();
        todo.addAll(getChildren(fragment.getId(), null, true)); // complex
        children.add(fragment);
    }
    Collections.reverse(children);
    // iterate on children depth first
    for (SimpleFragment fragment : children) {
        // remove from context
        boolean primary = fragment == hierFragment;
        removeFragmentAndDependents(fragment, primary);
        // remove from selections
        // removed from its parent selection
        hierComplex.recordRemoved(fragment);
        // no children anymore
        hierComplex.recordRemovedSelection(fragment.getId());
    }
}

From source file:ro.hasna.ts.math.ml.distance.DynamicTimeWarpingDistance.java

/**
 * <p>//w w  w .jav  a 2s  .c  o m
 * Reference:
 * Daniel Lemire (2008)
 * <i>Faster Sequential Search with a Two-Pass Dynamic-Time-Warping Lower Bound</i>
 * </p>
 *
 * @param v      the vector
 * @param n      the length of the vector
 * @param radius the Sakoe-Chiba band radius
 * @return time series envelope
 */
protected Envelope computeLemireEnvelope(double[] v, int n, int radius) {
    int w = 2 * radius + 1;
    double[] upper = new double[n];
    double[] lower = new double[n];
    int i;

    Deque<Integer> upperList = new LinkedList<>();
    Deque<Integer> lowerList = new LinkedList<>();
    upperList.addLast(0);
    lowerList.addLast(0);
    for (i = 1; i < n; i++) {
        if (i >= w) {
            upper[i - w] = v[upperList.getFirst()];
            lower[i - w] = v[lowerList.getFirst()];
        }
        if (v[i] > v[i - 1]) {
            upperList.removeLast();
            while (!upperList.isEmpty() && v[i] > v[upperList.getLast()]) {
                upperList.removeLast();
            }
        } else {
            lowerList.removeLast();
            while (!lowerList.isEmpty() && v[i] < v[lowerList.getLast()]) {
                lowerList.removeLast();
            }
        }
        upperList.addLast(i);
        lowerList.addLast(i);
        if (i == 2 * w + upperList.getFirst()) {
            upperList.removeFirst();
        } else if (i == 2 * w + lowerList.getFirst()) {
            lowerList.removeFirst();
        }
    }

    for (i = n; i < n + w; i++) {
        upper[i - w] = v[upperList.getFirst()];
        lower[i - w] = v[lowerList.getFirst()];
        if (i - upperList.getFirst() >= 2 * w) {
            upperList.removeFirst();
        }
        if (i - lowerList.getFirst() >= 2 * w) {
            lowerList.removeFirst();
        }
    }

    return new Envelope(lower, upper);
}

From source file:uniol.apt.adt.automaton.FiniteAutomatonUtility.java

static private Set<State> followEpsilons(Set<State> states) {
    Set<State> result = new HashSet<>(states);
    Deque<State> unhandled = new LinkedList<>(result);
    while (!unhandled.isEmpty()) {
        State state = unhandled.removeFirst();
        for (State newState : state.getFollowingStates(Symbol.EPSILON)) {
            if (result.add(newState))
                unhandled.add(newState);
        }/*from w  w w .j  av a 2 s. c  o  m*/
    }

    return result;
}