Example usage for java.util LinkedList pop

List of usage examples for java.util LinkedList pop

Introduction

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

Prototype

public E pop() 

Source Link

Document

Pops an element from the stack represented by this list.

Usage

From source file:org.wwscc.storage.SQLDataInterface.java

@Override
public void updateChallenge(Challenge c) {
    try {/* ww w  .  ja  va2s  .com*/
        LinkedList<Object> vals = c.getValues();
        vals.add(vals.pop());
        executeUpdate("update challenges set eventid=?,name=?,depth=? where challengeid=?", vals);
    } catch (SQLException ioe) {
        logError("updateChallenge", ioe);
    }
}

From source file:net.joaopeixoto.geode.server.functions.PatternFunctions.java

/**
 * Replace here with your favorite algorithm
 *//*ww w  .  j a  va2  s .co  m*/
@GemfireFunction
public DistanceResult distance(List<Metric> metrics) {
    Assert.notEmpty(metrics);
    Metric first = metrics.get(0);

    LinkedList<Metric> currentWindow = new LinkedList<>();
    LinkedList<Metric> matchedWindow = new LinkedList<>();
    double minDistance = THRESHOLD;
    int matchCount = 0;

    log.debug("Checking for patterns comparing with {}", metrics);

    List<Metric> localValues = new ArrayList<>(metricRegion.values());

    /**
     * Ensure the local values are ordered. {@link Region#values()} does not guarantee it.
     */
    Collections.sort(localValues);
    for (Metric metric : localValues) {

        // Ignore overlapping points or noise
        if (metric.getTimestamp() >= first.getTimestamp() || metric.getValue().compareTo(BigDecimal.TEN) < 1) {
            if (!currentWindow.isEmpty()) {
                currentWindow.pop();
            }
            continue;
        }

        currentWindow.add(metric);
        if (currentWindow.size() > 13) {
            currentWindow.pop();
        }

        /**
         * We only compare windows the same size (for now)
         */
        if (currentWindow.size() == 13) {

            TimeWarpInfo compare = DTW.compare(metricToSeries(currentWindow), metricToSeries(metrics),
                    Distances.EUCLIDEAN_DISTANCE);
            if (compare.getDistance() <= 1D) {
                matchCount++;
                matchedWindow = new LinkedList<>(currentWindow);
            }
        }
    }

    if (matchCount > 0) {
        return new DistanceResult(matchedWindow, minDistance, matchCount);
    }
    return null;
}

From source file:org.bimserver.charting.Containers.TreeNode.java

public int getLeafNodeCount() {
    int leafCount = 0;
    LinkedList<TreeNode> nodes = new LinkedList<TreeNode>(Arrays.asList(this));
    TreeNode thisNode = null;//from   w w  w  . jav  a2  s .com
    while (nodes.size() > 0) {
        thisNode = nodes.pop();
        if (thisNode.Children.length > 0) {
            int n = thisNode.Children.length;
            while (--n >= 0)
                nodes.push(thisNode.Children[n]);
        } else
            leafCount++;
    }
    return leafCount;
}

From source file:org.bimserver.charting.Containers.TreeNode.java

public void collapseAllNodesWithNullNames() {
    // Copied from: walkNodesFromRootToLeaves.
    LinkedList<TreeNode> nodes = new LinkedList<TreeNode>(Arrays.asList(this));
    TreeNode thisNode = null;/*w w  w .  ja  v a  2 s .c  o  m*/
    while (nodes.size() > 0) {
        thisNode = nodes.pop();
        // If not root and name is string "null", this node will be collapsed. Otherwise, keep iterating tree.
        if (!thisNode.isRoot() && thisNode.Name.equals("null")) {
            // Collapse non-leaf node: reparent children to parent of collapsing node.
            if (thisNode.Children.length > 0) {
                TreeNode newParent = thisNode.Parent;
                //
                int n = thisNode.Children.length;
                while (--n >= 0) {
                    // Remove child node from the node that's getting collapsed.
                    TreeNode childNodeToBeReparented = thisNode.remove(n);
                    // Reparent the child.
                    newParent.add(childNodeToBeReparented);
                    // Add the child to be processed.
                    nodes.push(childNodeToBeReparented);
                }
                // Remove the node that's being collapsed.
                thisNode.removeFromParent();
            }
            // Collapse leaf node: remove this node.
            else {
                thisNode.removeFromParent();
            }
        } else {
            if (thisNode.Children.length > 0) {
                int n = thisNode.Children.length;
                while (--n >= 0)
                    nodes.push(thisNode.Children[n]);
            }
        }
    }
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.ReplicaGroupRebalanceSegmentStrategy.java

/**
 * Uniformly distribute segments across servers in a replica group. It adopts a simple algorithm that pre-computes
 * the number of segments per server after rebalance and tries to assign/remove segments to/from a server until it
 * becomes to have the correct number of segments.
 *
 * @param serversInReplicaGroup A list of servers within the same replica group
 * @param serverToSegments A Mapping of servers to their segments
 *//*from  ww w  . jav a  2  s. c om*/
private void rebalanceReplicaGroup(List<String> serversInReplicaGroup,
        Map<String, LinkedList<String>> serverToSegments, Set<String> segmentsToCover) {
    // Make sure that all the segments are covered only once within a replica group.
    Set<String> currentCoveredSegments = new HashSet<>();
    for (String server : serversInReplicaGroup) {
        Iterator<String> segmentIter = serverToSegments.get(server).iterator();
        while (segmentIter.hasNext()) {
            String segment = segmentIter.next();
            if (currentCoveredSegments.contains(segment)) {
                segmentIter.remove();
            } else {
                currentCoveredSegments.add(segment);
            }
        }
    }

    // Compute the segments to add
    LinkedList<String> segmentsToAdd = new LinkedList<>(segmentsToCover);
    segmentsToAdd.removeAll(currentCoveredSegments);

    // Compute the number of segments per server after rebalance than numSegmentsPerServer
    int numSegmentsPerServer = segmentsToCover.size() / serversInReplicaGroup.size();

    // Remove segments from servers that has more segments
    for (String server : serversInReplicaGroup) {
        LinkedList<String> segmentsInServer = serverToSegments.get(server);
        int segmentToMove = numSegmentsPerServer - segmentsInServer.size();
        if (segmentToMove < 0) {
            // Server has more segments than needed, remove segments from this server
            for (int i = 0; i < Math.abs(segmentToMove); i++) {
                segmentsToAdd.add(segmentsInServer.pop());
            }
        }
    }

    // Add segments to servers that has less segments than numSegmentsPerServer
    for (String server : serversInReplicaGroup) {
        LinkedList<String> segmentsInServer = serverToSegments.get(server);
        int segmentToMove = numSegmentsPerServer - segmentsInServer.size();
        if (segmentToMove > 0) {
            // Server has less segments than needed, add segments from this server
            for (int i = 0; i < segmentToMove; i++) {
                segmentsInServer.add(segmentsToAdd.pop());
            }
        }
    }

    // Handling the remainder of segments to add
    int count = 0;
    while (!segmentsToAdd.isEmpty()) {
        int serverIndex = count % serversInReplicaGroup.size();
        serverToSegments.get(serversInReplicaGroup.get(serverIndex)).add(segmentsToAdd.pop());
        count++;
    }
}

From source file:org.eclipse.che.vfs.impl.fs.LocalFileSystemTest.java

protected List<String> flattenDirectory(String vfsPath) {
    java.io.File directory = getIoFile(vfsPath);
    assertTrue("Not a directory ", directory.isDirectory());
    final int splitIndex = directory.getAbsolutePath().length() + 1;
    List<String> files = new ArrayList<>();
    LinkedList<java.io.File> q = new LinkedList<>();
    q.add(directory);//  ww  w  . j  a  va  2 s .c om
    while (!q.isEmpty()) {
        java.io.File current = q.pop();
        java.io.File[] list = current.listFiles(SERVICE_DIR_FILTER);
        if (list != null) {
            for (java.io.File f : list) {
                files.add(f.getAbsolutePath().substring(splitIndex));
                if (f.isDirectory()) {
                    q.push(f);
                }
            }
        }
    }
    if (!files.isEmpty()) {
        java.util.Collections.sort(files);
    }
    return files;
}

From source file:org.bimserver.charting.Containers.TreeNode.java

public Iterator<TreeNode> iterateLeafNodes() {
    LinkedList<TreeNode> nodes = new LinkedList<TreeNode>(Arrays.asList(this));
    LinkedList<TreeNode> leafNodes = new LinkedList<>();
    TreeNode thisNode = null;//from   ww  w.j  a v  a 2 s.  co m
    while (nodes.size() > 0) {
        thisNode = nodes.pop();
        if (thisNode.Children.length > 0) {
            int i = -1;
            int n = thisNode.Children.length;
            while (++i < n)
                nodes.push(thisNode.Children[i]);
        } else
            leafNodes.push(thisNode);
    }
    return leafNodes.iterator();
}

From source file:org.bimserver.charting.Containers.TreeNode.java

public Iterator<TreeNode> iterateFromLeafNodesToRoot() {
    LinkedList<TreeNode> nodes = new LinkedList<TreeNode>(Arrays.asList(this));
    LinkedList<TreeNode> returningNodes = new LinkedList<>();
    TreeNode thisNode = null;//from   ww  w.j  a  va  2s.  c o m
    while (nodes.size() > 0) {
        thisNode = nodes.pop();
        returningNodes.push(thisNode);
        if (thisNode.Children.length > 0) {
            int i = -1;
            int n = thisNode.Children.length;
            while (++i < n)
                nodes.push(thisNode.Children[i]);
        }
    }
    return returningNodes.iterator();
}

From source file:org.bimserver.charting.Containers.TreeNode.java

public Iterator<TreeNode> iterateFromRootToLeafNodes() {
    LinkedList<TreeNode> nodes = new LinkedList<TreeNode>(Arrays.asList(this));
    LinkedList<TreeNode> returningNodes = new LinkedList<TreeNode>();
    TreeNode thisNode = null;/*from   w w  w.j a va 2 s. c o  m*/
    while (nodes.size() > 0) {
        thisNode = nodes.pop();
        returningNodes.add(thisNode);
        if (thisNode.Children.length > 0) {
            int n = thisNode.Children.length;
            while (--n >= 0)
                nodes.push(thisNode.Children[n]);
        }
    }
    return returningNodes.iterator();
}

From source file:org.eclipse.che.vfs.impl.fs.LocalFileSystemTest.java

protected void compareDirectories(java.io.File a, java.io.File b, boolean checkServiceDirs) throws IOException {
    if (!a.isDirectory() || !b.isDirectory()) {
        fail();/*from  w ww  .ja  v  a2  s.c o  m*/
    }
    LinkedList<Pair<java.io.File, java.io.File>> q = new LinkedList<>();
    q.add(new Pair<>(a, b));
    while (!q.isEmpty()) {
        Pair<java.io.File, java.io.File> current = q.pop();
        java.io.File[] files1 = current.first.listFiles(checkServiceDirs ? null : SERVICE_DIR_FILTER);
        java.io.File[] files2 = current.second.listFiles(checkServiceDirs ? null : SERVICE_DIR_FILTER);
        if (files1 == null || files2 == null || files1.length != files2.length) {
            fail();
        }
        Arrays.sort(files1);
        Arrays.sort(files2);
        for (int i = 0; i < files1.length; i++) {
            java.io.File file1 = files1[i];
            java.io.File file2 = files2[i];
            if (!file1.getName().equals(file2.getName())) {
                fail();
            }
            if (file1.isFile()) {
                try (FileInputStream in1 = new FileInputStream(file1);
                        FileInputStream in2 = new FileInputStream(file2)) {
                    compareStreams(in1, in2);
                }
            } else {
                q.push(new Pair<>(file1, file2));
            }
        }
    }
}