Example usage for java.util LinkedList addLast

List of usage examples for java.util LinkedList addLast

Introduction

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

Prototype

public void addLast(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:name.martingeisse.api.tools.LocalizationFileAction.java

private void handleFolder(File folder, LinkedList<String> packageStack) {
    if (!folder.isDirectory()) {
        throw new IllegalArgumentException("not a folder: " + folder);
    }/*from   www. j a va  2s . c o m*/
    for (File file : folder.listFiles()) {
        if (file.isDirectory()) {
            packageStack.addLast(file.getName());
            handleFolder(file, packageStack);
            packageStack.removeLast();
        } else if (file.isFile()) {
            String fileName = file.getName();
            int underscoreIndex = fileName.indexOf('_');
            if (underscoreIndex != -1 && fileName.endsWith(DOT_PROPERTIES)) {
                String baseName = fileName.substring(0, underscoreIndex);
                String localeName = fileName.substring(underscoreIndex + 1,
                        fileName.length() - DOT_PROPERTIES.length());
                if (acceptLocale(localeName)) {
                    onLocalizationFile(packageStack, file, baseName, localeName);
                }
            }
        }
    }
}

From source file:com.intirix.cloudpasswordmanager.pages.BaseActivity.java

protected void addNavigationItems(LinkedList<NavigationItem> navItems) {
    if (autoLogoffService.isSessionStillValid()) {
        navItems.addFirst(new LogOffNavigationItem(this, sessionService));
        navItems.addLast(new PasswordListNavigationItem(this));
        navItems.addLast(new SettingsNavigationItem(this));

    } else {//  w  w  w  .  j  a  v  a2  s.c  o m
        navItems.addFirst(new LoginNavigationItem(this));
    }
    navItems.addLast(new AboutNavigationItem(this));
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

/**
 * Builds the dawg based on the words added.
 *
 * @return the new Dawg instance// ww  w.  j a va2 s. co m
 */
public Dawg build() {
    compress();

    for (Node node : nodeList)
        node.index = -1;

    LinkedList<Node> stack = new LinkedList<Node>();

    nodeList.clear();
    stack.clear();
    stack.addLast(root);

    int index = 0;

    while (!stack.isEmpty()) {
        Node ptr = stack.removeFirst();
        if (-1 == ptr.index)
            ptr.index = index++;
        nodeList.add(ptr);

        for (Node nextChild : ptr.nextChildren)
            stack.addLast(nextChild);
        if (null != ptr.child)
            stack.addLast(ptr.child);
    }

    int[] ints = new int[index];

    for (Node node : nodeList)
        ints[node.index] = node.toInteger();

    return new Dawg(ints);
}

From source file:org.red5.io.object.Serializer.java

/**
 * Writes an iterator out to the output/* w w w  . j a va  2  s. c o  m*/
 *
 * @param out          Output writer
 * @param it           Iterator to write
 */
protected void writeIterator(Output out, Iterator<Object> it) {
    if (log.isDebugEnabled()) {
        log.debug("writeIterator");
    }
    // Create LinkedList of collection we iterate thru and write it out later
    LinkedList<Object> list = new LinkedList<Object>();
    while (it.hasNext()) {
        list.addLast(it.next());
    }
    // Write out collection
    out.writeArray(list, this);
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

private void compress() {
    LinkedList<Node> stack = new LinkedList<Node>();
    int index = 0;

    stack.addLast(root);
    while (!stack.isEmpty()) {
        Node ptr = stack.removeFirst();

        ptr.index = index++;/*from   www  .j  a v a 2 s  .  c o  m*/
        if (root != ptr)
            ptr.siblings = ptr.parent.nextChildren.size() - 1 + (null == ptr.parent.child ? 0 : 1);
        nodeList.add(ptr);

        for (Node nextChild : ptr.nextChildren)
            stack.add(nextChild);
        if (null != ptr.child)
            stack.add(ptr.child);
    }

    // assign child depths to all nodes
    for (Node node : nodeList)
        if (node.terminal) {
            node.childDepth = 0;

            Node ptr = node;
            int depth = 0;
            while (root != ptr) {
                ptr = ptr.parent;
                ++depth;
                if (depth > ptr.childDepth)
                    ptr.childDepth = depth;
                else
                    break;
            }
        }

    // bin nodes by child depth
    for (Node node : nodeList) {
        LinkedList<Node> nodes = childDepths.get(node.childDepth);
        if (null == nodes) {
            nodes = new LinkedList<Node>();
            nodes.add(node);
            childDepths.put(node.childDepth, nodes);
        } else
            nodes.add(node);
    }

    int maxDepth = -1;
    for (int depth : childDepths.keySet())
        if (depth > maxDepth)
            maxDepth = depth;

    for (int depth = 0; depth <= maxDepth; ++depth) {
        LinkedList<Node> nodes = childDepths.get(depth);
        if (null == nodes)
            continue;

        for (ListIterator<Node> pickNodeIter = nodes.listIterator(); pickNodeIter.hasNext();) {
            Node pickNode = pickNodeIter.next();

            if ((null == pickNode.replaceMeWith) && pickNode.isChild && (0 == pickNode.siblings))
                for (ListIterator<Node> searchNodeIter = nodes
                        .listIterator(pickNodeIter.nextIndex()); searchNodeIter.hasNext();) {
                    Node searchNode = searchNodeIter.next();
                    if ((null == searchNode.replaceMeWith) && searchNode.isChild && (0 == searchNode.siblings)
                            && pickNode.equals(searchNode)) {
                        searchNode.parent.child = pickNode;
                        searchNode.replaceMeWith = pickNode;
                    }
                }
        }
    }
}

From source file:org.openxdm.xcap.client.test.success.DeleteAttributeTest.java

@Test
public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri      
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    String newContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"friends\"/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), newContent, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStep("list");
    elementSelectorSteps.add(step1);//ww w. ja  va 2  s. c o m
    elementSelectorSteps.addLast(step2);
    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null);

    // send delete request and get response
    Response attrDeleteResponse = client.delete(attrKey, null);

    // check delete response
    assertTrue("Delete response must exists", attrDeleteResponse != null);
    assertTrue("Delete response code should be 200", attrDeleteResponse.getCode() == 200);

    // send get request and get response
    Response attrGetResponse = client.get(attrKey, null);

    // check get response
    assertTrue("Get response must exists", attrGetResponse != null);
    assertTrue("Get response code should be 404", attrGetResponse.getCode() == 404);

    // clean up
    client.delete(key, null);

}

From source file:org.openxdm.xcap.client.test.success.GetNamespaceBindingsTest.java

@Test
public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri      
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    String documentContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), documentContent, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStep("pre:list");
    elementSelectorSteps.add(step1);/*from  w  w  w  .j a  v a2  s  .  c  o  m*/
    elementSelectorSteps.addLast(step2);
    Map<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("pre", appUsage.getDefaultDocumentNamespace());
    XcapUriKey namespacesKey = new UserNamespaceBindingsUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), namespaces);

    // send get request and get response
    Response namespacesGetResponse = client.get(namespacesKey, null);

    String expectedResponseContent = "<list xmlns=\"urn:ietf:params:xml:ns:resource-lists\"/>";

    // check get response
    assertTrue("Get response must exists", namespacesGetResponse != null);
    assertTrue("Get response code should be 200 and the content must be the expected",
            namespacesGetResponse.getCode() == 200 && XMLValidator
                    .weaklyEquals((String) namespacesGetResponse.getContent(), expectedResponseContent));

    // clean up
    client.delete(key, null);
}

From source file:org.openxdm.xcap.client.test.success.PutNewAttributeTest.java

@Test
public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri      
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    String newContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), newContent, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStep("list");
    elementSelectorSteps.add(step1);//  w  w w  .j av a  2 s .co m
    elementSelectorSteps.addLast(step2);
    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null);

    // send put request and get response
    Response attrPutResponse = client.put(attrKey, AttributeResource.MIMETYPE, "friends", null);

    // check put response
    assertTrue("Put response must exists", attrPutResponse != null);
    assertTrue("Put response code should be 201", attrPutResponse.getCode() == 201);

    // send get request and get response
    Response attrGetResponse = client.get(attrKey, null);

    // check get response
    assertTrue("Get response must exists", attrGetResponse != null);
    assertTrue("Get response code should be 200 and the attr value must equals the one sent in put",
            attrGetResponse.getCode() == 200
                    && XMLValidator.weaklyEquals((String) attrGetResponse.getContent(), "friends"));

    // clean up
    client.delete(key, null);
}

From source file:org.openxdm.xcap.client.test.success.DeleteElementByPosTest.java

@Test
public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri      
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    // the doc to put
    String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"friends\"/>"
            + "<list name=\"enemies\"/>" + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), document, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStepByPos("*", 2);
    elementSelectorSteps.add(step1);/*from w  ww .jav a 2 s  .  c o  m*/
    elementSelectorSteps.addLast(step2);
    UserElementUriKey elemKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), null);

    // send delete request and get response
    Response elemDeleteResponse = client.delete(elemKey, null);

    // check delete response
    assertTrue("Delete response must exists", elemDeleteResponse != null);
    assertTrue("Delete response code should be 200", elemDeleteResponse.getCode() == 200);

    // send get request and get response
    Response elemGetResponse = client.get(elemKey, null);

    // check get response
    assertTrue("Get response must exists", elemGetResponse != null);
    assertTrue("Get response code should be 404", elemGetResponse.getCode() == 404);

    // clean up
    client.delete(key, null);
}

From source file:org.openxdm.xcap.client.test.success.ReplaceExistingAttributeTest.java

@Test
public void test() throws HttpException, IOException, JAXBException, InterruptedException {

    // create uri      
    UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);

    String newContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"enemies\"/>"
            + "</resource-lists>";

    // send put request and get response
    Response initialPutResponse = client.put(key, appUsage.getMimetype(), newContent, null);

    // check put response
    assertTrue("Put response must exists", initialPutResponse != null);
    assertTrue("Put response code should be 201", initialPutResponse.getCode() == 201);

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStep("list");
    elementSelectorSteps.add(step1);/*from w  w  w.  j av a 2  s .  c  o  m*/
    elementSelectorSteps.addLast(step2);
    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null);

    // send put request and get response
    Response attrPutResponse = client.put(attrKey, AttributeResource.MIMETYPE, "friends", null);

    // check put response
    assertTrue("Put response must exists", attrPutResponse != null);
    assertTrue("Put response code should be 200", attrPutResponse.getCode() == 200);

    // send get request and get response
    Response attrGetResponse = client.get(attrKey, null);

    // check get response
    assertTrue("Get response must exists", attrGetResponse != null);
    assertTrue("Get response code should be 200 and the attr value must equals the one sent in put",
            attrGetResponse.getCode() == 200
                    && XMLValidator.weaklyEquals((String) attrGetResponse.getContent(), "friends"));

    // clean up
    client.delete(key, null);
}