Example usage for java.util LinkedList removeFirst

List of usage examples for java.util LinkedList removeFirst

Introduction

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

Prototype

public E removeFirst() 

Source Link

Document

Removes and returns the first element from this list.

Usage

From source file:de.hasait.genesis.base.freemarker.FreemarkerModelWriter.java

static void write(final Configuration pConfiguration, final Writer pWriter, final Object pModel,
        final Map pParams) throws IOException, TemplateException {
    final Map<Class<?>, Template> templateCache = TEMPLATE_CACHE.get();

    Class<?> currentType = pModel.getClass();
    Template template = templateCache.get(currentType);
    if (template == null) {
        final LinkedList<TypeNode> queue = new LinkedList<TypeNode>();
        queue.add(new TypeNode(null, currentType));

        TemplateNotFoundException firstE = null;

        do {//from  www .  j av a 2s.  co m
            // take first from queue
            TypeNode current = queue.removeFirst();
            currentType = current._type;

            // determine template
            template = templateCache.get(currentType);
            if (template == null) {
                final String templateName = currentType.getSimpleName() + ".ftl";
                try {
                    template = pConfiguration.getTemplate(templateName);
                } catch (final TemplateNotFoundException e) {
                    if (firstE == null) {
                        firstE = e;
                    }
                }
            }

            if (template != null) {
                // fill cache including parents
                templateCache.put(currentType, template);
                while (true) {
                    templateCache.put(currentType, template);
                    current = current._parent;
                    if (current == null) {
                        break;
                    }
                    currentType = current._type;
                }
            } else {
                // fill queue with next nodes
                for (final Class<?> interfaceType : currentType.getInterfaces()) {
                    queue.add(new TypeNode(current, interfaceType));
                }
                final Class<?> superclassType = currentType.getSuperclass();
                if (superclassType != null) {
                    queue.add(new TypeNode(current, superclassType));
                }
            }
        } while (template == null && !queue.isEmpty());

        if (template == null) {
            throw firstE;
        }
    }

    write(pConfiguration, pWriter, template, pModel, pParams);
}

From source file:mx.unam.ecologia.gye.coalescence.model.UniParentalGene.java

public static final void traverse(UniParentalGene upgene, UniParentalGeneVisitor visitor) {
    //log.debug("traverse()");
    LinkedList<UniParentalGene> queue = new LinkedList<UniParentalGene>();
    if (upgene.isAncestor()) {
        queue.add(upgene);//w  w w  . jav a 2 s  . com
    } else {
        return; //nothing to be done!
    }
    while (!(queue.isEmpty())) {
        UniParentalGene upg = (UniParentalGene) queue.removeFirst();
        visitor.visit(upg);
        //log.debug("traverse()::Visited " + upg.toNHXString());

        if (upg.m_LDescendant != null) {
            queue.add(upg.m_LDescendant);
        }
        if (upg.m_RDescendant != null) {
            queue.add(upg.m_RDescendant);
        }
    }
}

From source file:Main.java

public static LinkedList<File> listLinkedFiles(String strPath) {
    LinkedList<File> list = new LinkedList<File>();
    File dir = new File(strPath);
    if (!dir.isDirectory()) {
        return null;
    }/*from   ww  w  . ja v  a 2s . c o  m*/
    File file[] = dir.listFiles();
    for (int i = 0; i < file.length; i++) {
        if (file[i].isDirectory())
            list.add(file[i]);
        else
            System.out.println(file[i].getAbsolutePath());
    }
    File tmp;
    while (!list.isEmpty()) {
        tmp = (File) list.removeFirst();
        if (tmp.isDirectory()) {
            file = tmp.listFiles();
            if (file == null)
                continue;
            for (int i = 0; i < file.length; i++) {
                if (file[i].isDirectory())
                    list.add(file[i]);
                else
                    System.out.println(file[i].getAbsolutePath());
            }
        } else {
            System.out.println(tmp.getAbsolutePath());
        }
    }
    return list;
}

From source file:com.machinepublishers.jbrowserdriver.LogsServer.java

private static void handleMessage(String message, LinkedList<Entry> entries, Level level, String type,
        Settings settings) {//w ww .j a va  2  s.c o  m
    if (settings != null && settings.logsMax() > 0) {
        final Entry entry = new Entry(level, System.currentTimeMillis(), message);
        synchronized (entries) {
            entries.add(entry);
            if (entries.size() > settings.logsMax()) {
                entries.removeFirst();
            }
        }
    }
    if (settings == null || level.intValue() >= settings.loggerLevel()) {
        System.err.println(">" + level.getName() + "/" + type + "/" + message);
    }
}

From source file:com.salsaberries.narchiver.Writer.java

/**
 * Writes all the pages to file./*  www  .j a v a 2  s .c  o m*/
 *
 * @param pages
 * @param location
 */
public static void storePages(LinkedList<Page> pages, String location) {

    logger.info("Dumping " + pages.size() + " pages to file at " + location + "/");

    File file = new File(location);
    // Make sure the directory exists
    if (!file.exists()) {
        try {
            file.mkdirs();
            logger.info("Directory " + file.getAbsolutePath() + " does not exist, creating.");
        } catch (SecurityException e) {
            logger.error(e.getMessage());
        }
    }
    // Write them to the file if they haven't been already written
    while (!pages.isEmpty()) {
        Page page = pages.removeFirst();

        String fileName = file.getAbsolutePath() + "/" + page.getDate() + "|"
                + URLEncoder.encode(page.getTagURL());

        try (BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
            writer.write(page.toString());
        } catch (IOException e) {
            logger.warn(e.getMessage());
        }
        // Temporarily try to reduce memory
        page.setHtml("");
    }
}

From source file:org.dcm4che3.conf.core.misc.DeepEquals.java

/**
 * Get a deterministic hashCode (int) value for an Object, regardless of
 * when it was created or where it was loaded into memory.  The problem
 * with java.lang.Object.hashCode() is that it essentially relies on
 * memory location of an object (what identity it was assigned), whereas
 * this method will produce the same hashCode for any object graph, regardless
 * of how many times it is created.<br/><br/>
 *
 * This method will handle cycles correctly (A->B->C->A).  In this case,
 * Starting with object A, B, or C would yield the same hashCode.  If an
 * object encountered (root, suboject, etc.) has a hashCode() method on it
 * (that is not Object.hashCode()), that hashCode() method will be called
 * and it will stop traversal on that branch.
 * @param obj Object who hashCode is desired.
 * @return the 'deep' hashCode value for the passed in object.
 *//* ww w.ja  va  2 s.c  om*/
public static int deepHashCode(Object obj) {
    Set visited = new HashSet();
    LinkedList<Object> stack = new LinkedList<Object>();
    stack.addFirst(obj);
    int hash = 0;

    while (!stack.isEmpty()) {
        obj = stack.removeFirst();
        if (obj == null || visited.contains(obj)) {
            continue;
        }

        visited.add(obj);

        if (obj.getClass().isArray()) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                stack.addFirst(Array.get(obj, i));
            }
            continue;
        }

        if (obj instanceof Collection) {
            stack.addAll(0, (Collection) obj);
            continue;
        }

        if (obj instanceof Map) {
            stack.addAll(0, ((Map) obj).keySet());
            stack.addAll(0, ((Map) obj).values());
            continue;
        }

        if (hasCustomHashCode(obj.getClass())) { // A real hashCode() method exists, call it.
            hash += obj.hashCode();
            continue;
        }

        Collection<Field> fields = getDeepDeclaredFields(obj.getClass());
        for (Field field : fields) {
            try {
                stack.addFirst(field.get(obj));
            } catch (Exception ignored) {
            }
        }
    }
    return hash;
}

From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java

/**
 * Unset the "return path" that locates the point at which a subflow was included into a primary workflow.
 *
 * @param session the http session// www.  j  a  v  a  2 s .  co m
 */
public static void unsetReturnPath(HttpSession session) {
    LinkedList retstack = (LinkedList) session.getAttribute(AttrConstants.RETURN_LOC_SES_ATTR);

    if ((retstack != null) && (retstack.size() >= 1)) {
        retstack.removeFirst();
    }
}

From source file:org.dcm4che3.conf.core.misc.DeepEquals.java

/**
 * Compare two objects with a 'deep' comparison.  This will traverse the
 * Object graph and perform either a field-by-field comparison on each
 * object (if no .equals() method has been overridden from Object), or it
 * will call the customized .equals() method if it exists.  This method will
 * allow object graphs loaded at different times (with different object ids)
 * to be reliably compared.  Object.equals() / Object.hashCode() rely on the
 * object's identity, which would not consider to equivalent objects necessarily
 * equals.  This allows graphs containing instances of Classes that did no
 * overide .equals() / .hashCode() to be compared.  For example, testing for
 * existence in a cache.  Relying on an objects identity will not locate an
 * object in cache, yet relying on it being equivalent will.<br/><br/>
 *
 * This method will handle cycles correctly, for example A->B->C->A.  Suppose a and
 * a' are two separate instances of the A with the same values for all fields on
 * A, B, and C.  Then a.deepEquals(a') will return true.  It uses cycle detection
 * storing visited objects in a Set to prevent endless loops.
 * @param a Object one to compare/*from w ww  .  j  av  a  2s.  c o m*/
 * @param b Object two to compare
 * @return true if a is equivalent to b, false otherwise.  Equivalent means that
 * all field values of both subgraphs are the same, either at the field level
 * or via the respectively encountered overridden .equals() methods during
 * traversal.
 */
public static boolean deepEquals(Object a, Object b) {
    Set visited = new HashSet<DualKey>();
    LinkedList<DualKey> stack = new LinkedList<DualKey>();
    stack.addFirst(new DualKey(a, b));

    while (!stack.isEmpty()) {

        DualKey dualKey = stack.removeFirst();
        lastDualKey = dualKey;

        visited.add(dualKey);

        if (dualKey._key1 == dualKey._key2) { // Same instance is always equal to itself.
            continue;
        }

        if (dualKey._key1 == null || dualKey._key2 == null) {
            // check if one is null and another is an empty array

            if (dualKey._key1 == null) {
                if (dualKey._key2.getClass().isArray() && ((Object[]) dualKey._key2).length == 0)
                    continue;
            }
            if (dualKey._key2 == null) {
                if (dualKey._key1.getClass().isArray() && ((Object[]) dualKey._key1).length == 0)
                    continue;
            }

            // If either one is null, not equal (both can't be null, due to above comparison).
            return false;
        }

        if (!dualKey._key1.getClass().equals(dualKey._key2.getClass())) { // Must be same class
            return false;
        }

        // Handle all [] types.  In order to be equal, the arrays must be the same 
        // length, be of the same type, be in the same order, and all elements within
        // the array must be deeply equivalent.
        if (dualKey._key1.getClass().isArray()) {
            if (!compareArrays(dualKey._key1, dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        // Special handle SortedSets because they are fast to compare because their
        // elements must be in the same order to be equivalent Sets.
        if (dualKey._key1 instanceof SortedSet) {
            if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Handled unordered Sets.  This is a slightly more expensive comparison because order cannot
        // be assumed, a temporary Map must be created, however the comparison still runs in O(N) time.
        if (dualKey._key1 instanceof Set) {
            if (!compareUnorderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Check any Collection that is not a Set.  In these cases, element order
        // matters, therefore this comparison is faster than using unordered comparison.
        if (dualKey._key1 instanceof Collection) {
            if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Compare two SortedMaps.  This takes advantage of the fact that these
        // Maps can be compared in O(N) time due to their ordering.
        if (dualKey._key1 instanceof SortedMap) {
            if (!compareSortedMap((SortedMap) dualKey._key1, (SortedMap) dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        // Compare two Unordered Maps. This is a slightly more expensive comparison because
        // order cannot be assumed, therefore a temporary Map must be created, however the
        // comparison still runs in O(N) time.
        if (dualKey._key1 instanceof Map) {
            if (!compareUnorderedMap((Map) dualKey._key1, (Map) dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        if (hasCustomEquals(dualKey._key1.getClass())) {
            if (!dualKey._key1.equals(dualKey._key2)) {
                return false;
            }
            continue;
        }

        lastClass = dualKey._key1.getClass().toString();

        // check if we have a custom deepequals method for this class
        CustomDeepEquals de = customDeepEquals.get(dualKey._key1.getClass());
        if (de != null) {
            if (!de.deepEquals(dualKey._key1, dualKey._key2))
                return false;
        } else {
            Collection<Field> fields = getDeepDeclaredFields(dualKey._key1.getClass());

            for (Field field : fields) {
                try {

                    DualKey dk = new DualKey(field.get(dualKey._key1), field.get(dualKey._key2),
                            field.getName());
                    if (!visited.contains(dk)) {
                        stack.addFirst(dk);
                    }
                } catch (Exception ignored) {
                }
            }
        }
    }

    return true;
}

From source file:com.dsclab.loader.app.Loader.java

public static Produce getProduce() {
    TableTask firstTableTask = tableTask.getFirst();
    if (tableTask.size() != 0) {
        LinkedList<String> firstTaskSql = firstTableTask.getTaskSqlList();
        while (firstTaskSql.size() == 0) {
            tableTask.removeFirst();/*from w ww  .j a  va  2  s .c  o m*/
            if (tableTask.size() == 0) {
                return null;
            }
            firstTableTask = tableTask.getFirst();
            firstTaskSql = firstTableTask.getTaskSqlList();
        }
        //firstTableTask = tableTask.getFirst();
        //firstTaskSql = firstTableTask.getTaskSqlList();
        Table firstTableInfo = firstTableTask.getTableInfo();
        System.out.println("Tablename:" + firstTableInfo.getTableName());

        System.out.println("next table:" + tableTask.getFirst().getTableInfo().getTableName());
        String taskSql = firstTaskSql.getFirst();
        firstTaskSql.removeFirst();
        System.out.println("TaskSql:" + taskSql);
        return new Produce(firstTableInfo, taskSql);
    }
    return null;
}

From source file:org.dcm4chee.storage.conf.DeepEquals.java

/**
 * Compare two objects with a 'deep' comparison.  This will traverse the
 * Object graph and perform either a field-by-field comparison on each
 * object (if no .equals() method has been overridden from Object), or it
 * will call the customized .equals() method if it exists.  This method will
 * allow object graphs loaded at different times (with different object ids)
 * to be reliably compared.  Object.equals() / Object.hashCode() rely on the
 * object's identity, which would not consider to equivalent objects necessarily
 * equals.  This allows graphs containing instances of Classes that did no
 * overide .equals() / .hashCode() to be compared.  For example, testing for
 * existence in a cache.  Relying on an objects identity will not locate an
 * object in cache, yet relying on it being equivalent will.<br/><br/>
 *
 * This method will handle cycles correctly, for example A->B->C->A.  Suppose a and
 * a' are two separate instances of the A with the same values for all fields on
 * A, B, and C.  Then a.deepEquals(a') will return true.  It uses cycle detection
 * storing visited objects in a Set to prevent endless loops.
 * @param a Object one to compare//from w  w w .j  a  v  a 2 s.  c om
 * @param b Object two to compare
 * @return true if a is equivalent to b, false otherwise.  Equivalent means that
 * all field values of both subgraphs are the same, either at the field level
 * or via the respectively encountered overridden .equals() methods during
 * traversal.
 */
public static boolean deepEquals(Object a, Object b) {

    Set visited = new HashSet<DualKey>();
    LinkedList<DualKey> stack = new LinkedList<DualKey>();
    stack.addFirst(new DualKey(a, b));

    while (!stack.isEmpty()) {

        DualKey dualKey = stack.removeFirst();
        lastDualKey = dualKey;

        visited.add(dualKey);

        if (dualKey._key1 == dualKey._key2) { // Same instance is always equal to itself.
            continue;
        }

        if (dualKey._key1 == null || dualKey._key2 == null) {
            // check if one is null and another is an empty array

            if (dualKey._key1 == null) {
                if (dualKey._key2.getClass().isArray() && ((Object[]) dualKey._key2).length == 0)
                    continue;
            }
            if (dualKey._key2 == null) {
                if (dualKey._key1.getClass().isArray() && ((Object[]) dualKey._key1).length == 0)
                    continue;
            }

            // If either one is null, not equal (both can't be null, due to above comparison).
            return false;
        }

        if (dualKey._key1 instanceof Map && dualKey._key2 instanceof Map) {
            // if they are maps - forget about comparing exact classes 
        } else if (!dualKey._key1.getClass().equals(dualKey._key2.getClass())) { // Must be same class
            return false;
        }

        // Handle all [] types.  In order to be equal, the arrays must be the same 
        // length, be of the same type, be in the same order, and all elements within
        // the array must be deeply equivalent.
        if (dualKey._key1.getClass().isArray()) {
            if (!compareArrays(dualKey._key1, dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        // Special handle SortedSets because they are fast to compare because their
        // elements must be in the same order to be equivalent Sets.
        if (dualKey._key1 instanceof SortedSet) {
            if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Handled unordered Sets.  This is a slightly more expensive comparison because order cannot
        // be assumed, a temporary Map must be created, however the comparison still runs in O(N) time.
        if (dualKey._key1 instanceof Set) {
            if (!compareUnorderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Check any Collection that is not a Set.  In these cases, element order
        // matters, therefore this comparison is faster than using unordered comparison.
        if (dualKey._key1 instanceof Collection) {
            if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack,
                    visited)) {
                return false;
            }
            continue;
        }

        // Compare two SortedMaps.  This takes advantage of the fact that these
        // Maps can be compared in O(N) time due to their ordering.
        if (dualKey._key1 instanceof SortedMap) {
            if (!compareSortedMap((Map) dualKey._key1, (Map) dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        // Compare two Unordered Maps. This is a slightly more expensive comparison because
        // order cannot be assumed, therefore a temporary Map must be created, however the
        // comparison still runs in O(N) time.
        if (dualKey._key1 instanceof Map) {
            if (!compareUnorderedMap((Map) dualKey._key1, (Map) dualKey._key2, stack, visited)) {
                return false;
            }
            continue;
        }

        if (hasCustomEquals(dualKey._key1.getClass())) {
            if (!dualKey._key1.equals(dualKey._key2)) {
                return false;
            }
            continue;
        }

        lastObject = dualKey._key1;

        // check if we have a custom deepequals method for this class
        CustomDeepEquals de = customDeepEquals.get(dualKey._key1.getClass());
        if (de != null) {
            if (!de.deepEquals(dualKey._key1, dualKey._key2))
                return false;
        } else {
            Collection<Field> fields = getDeepDeclaredFields(dualKey._key1.getClass());

            for (Field field : fields) {
                try {

                    DualKey dk = new DualKey(field.get(dualKey._key1), field.get(dualKey._key2),
                            field.getName());
                    if (!visited.contains(dk)) {
                        stack.addFirst(dk);
                    }
                } catch (Exception ignored) {
                }
            }
        }
    }

    return true;
}