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:com.linuxbox.enkive.web.StatsServlet.java

private void consolidateMapsHelper(Map<String, Object> templateData, Map<String, Object> consolidatedMap,
        LinkedList<String> path, List<ConsolidationKeyHandler> statKeys,
        List<Map<String, Object>> serviceData) {
    for (String key : templateData.keySet()) {
        path.addLast(key);
        ConsolidationKeyHandler matchingConsolidationDefinition = findMatchingPath(path, statKeys);
        if (matchingConsolidationDefinition != null) {
            TreeSet<Map<String, Object>> dataSet = new TreeSet<Map<String, Object>>(new NumComparator());
            for (Map<String, Object> dataMap : serviceData) {
                Map<String, Object> dataVal = createMap(getDataVal(dataMap, path));
                if (dataVal != null && !dataVal.isEmpty()) {
                    dataVal.put(STAT_TIMESTAMP, dataMap.get(STAT_TIMESTAMP));
                    dataSet.add(dataVal);
                }/*ww w  .  j  a  v  a  2 s  .  c  om*/
            }
            putOnPath(path, consolidatedMap, dataSet);
        } else {
            if (templateData.get(key) instanceof Map) {
                consolidateMapsHelper((Map<String, Object>) templateData.get(key), consolidatedMap, path,
                        statKeys, serviceData);
            }
        }
        path.removeLast();
    }
}

From source file:srebrinb.compress.sevenzip.SevenZArchiveEntry.java

/**
 * Sets the (compression) methods to use for entry's content - the
 * default is LZMA2./*from   w  w w .j  a  v a2 s .c  o  m*/
 *
 * <p>Currently only {@link SevenZMethod#COPY}, {@link
 * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link
 * SevenZMethod#DEFLATE} are supported when writing archives.</p>
 *
 * <p>The methods will be consulted in iteration order to create
 * the final output.</p>
 *
 * @param methods the methods to use for the content
 * @since 1.8
 */
public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods) {
    if (methods != null) {
        final LinkedList<SevenZMethodConfiguration> l = new LinkedList<>();
        for (final SevenZMethodConfiguration m : methods) {
            l.addLast(m);
        }
        contentMethods = Collections.unmodifiableList(l);
    } else {
        contentMethods = null;
    }
}

From source file:com.stimulus.archiva.domain.EmailFilter.java

public void setPriority(int id, Priority priority) {
    LinkedList<FilterRule> list = filterRules;
    FilterRule ar = filterRules.get(id);
    list.remove(ar);// w w w . ja  v  a  2s.c o m

    switch (priority) {
    case HIGHER:
        if ((id - 1) <= 0)
            list.addFirst(ar);
        else
            list.add(id - 1, ar);
        break;
    case LOWER:
        if ((id + 1) >= list.size())
            list.addLast(ar);
        else
            list.add(id + 1, ar);
        break;
    case HIGHEST:
        list.addFirst(ar);
        break;
    case LOWEST:
        list.addLast(ar);
        break;
    }
}

From source file:ubic.BAMSandAllen.MatrixPairs.ConnectivityAndAllenDataPair.java

public ConnectivityAndAllenDataPair(String matrixFilename) throws Exception {
    allenCatalog = new StructureCatalogLoader();

    direction = direction.ANYDIRECTION;/*from   w w w  . j av  a 2 s  . co  m*/

    DoubleMatrixReader matrixReader = new DoubleMatrixReader();
    //        matrixReader.setTopLeft( false );
    DoubleMatrix<String, String> connectionMatrix = matrixReader.read(matrixFilename);

    if (!connectionMatrix.getRowNames().equals(connectionMatrix.getColNames())) {
        throw new RuntimeException("error row and col names in diff order");
    }
    // Remove quotes
    // assumes they are in the same order!
    LinkedList<String> newRowNames = new LinkedList<String>();
    for (String row : connectionMatrix.getRowNames()) {
        newRowNames.addLast(row.substring(1, row.length() - 1));
    }

    connectionMatrix.setRowNames(newRowNames);
    connectionMatrix.setColumnNames(newRowNames);

    List<String> regions = connectionMatrix.getColNames();

    // WARNING, removes occurance counts!!
    // set large propigated values to one
    for (String row : regions) {
        for (String col : regions) {
            double connectionMatrixValue = connectionMatrix.getByKeys(row, col);
            if (connectionMatrixValue > 0) {
                connectionMatrix.setByKeys(row, col, 1d);
            } else {
                connectionMatrix.setByKeys(row, col, 0d);
            }
        }
    }

    matrixA = new ABAMSDataMatrix(connectionMatrix, "ConnectivityLoadedMatrix",
            new CorrelationAdjacency(connectionMatrix));

    printConnectionInfo();

    matrixA = matrixA.removeZeroColumns();

    log.info("got Matrix A - connections");
    virtualRegions = new LinkedList<String>();
}

From source file:bobs.is.compress.sevenzip.SevenZArchiveEntry.java

/**
 * Sets the (compression) methods to use for entry's content - the
 * default is LZMA2./*from   w  w w.  j  ava  2  s  .  com*/
 *
 * <p>Currently only {@link SevenZMethod#COPY}, {@link
 * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link
 * SevenZMethod#DEFLATE} are supported when writing archives.</p>
 *
 * <p>The methods will be consulted in iteration order to create
 * the final output.</p>
 *
 * @param methods the methods to use for the content
 * @since 1.8
 */
public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods) {
    if (methods != null) {
        final LinkedList<SevenZMethodConfiguration> l = new LinkedList<SevenZMethodConfiguration>();
        for (final SevenZMethodConfiguration m : methods) {
            l.addLast(m);
        }
        contentMethods = Collections.unmodifiableList(l);
    } else {
        contentMethods = null;
    }
}

From source file:org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry.java

private void registerMouseBinding(boolean first, MouseEventTypeEnum mouseEventType,
        IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
    LinkedList<MouseBinding> mouseEventBindings = this.mouseBindingsMap.get(mouseEventType);
    if (mouseEventBindings == null) {
        mouseEventBindings = new LinkedList<MouseBinding>();
        this.mouseBindingsMap.put(mouseEventType, mouseEventBindings);
    }/*from   w w  w .  ja  v a  2  s. c  om*/
    if (first) {
        mouseEventBindings.addFirst(new MouseBinding(mouseEventMatcher, action));
    } else {
        mouseEventBindings.addLast(new MouseBinding(mouseEventMatcher, action));
    }
}

From source file:org.gcaldaemon.core.FeedUtilities.java

private static final byte[] removeDuplicatedEntries(SyndFeed feed, HashMap feedCache, double duplicationRatio)
        throws Exception {

    // Remove duplicated feed entries
    if (feedCache.isEmpty()) {
        return null;
    }//ww  w .j av  a  2  s .c o  m
    SyndEntry[] entries = getFeedEntries(feed);
    LinkedList duplicatedEntries = new LinkedList();
    HashMap syndEntryCache = new HashMap();
    SyndEntry entry;
    boolean found;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        found = false;

        // Find entry
        Iterator urls = feedCache.keySet().iterator();
        while (urls.hasNext()) {
            String url = (String) urls.next();
            if (url.endsWith(".ics")) {
                continue;
            }
            SyndEntry[] otherEntries = (SyndEntry[]) syndEntryCache.get(url);
            if (otherEntries == null) {
                CachedCalendar container = (CachedCalendar) feedCache.get(url);
                SyndFeed otherFeed = parseFeed(container.previousBody);
                otherEntries = getFeedEntries(otherFeed);
                syndEntryCache.put(url, otherEntries);
            }
            found = foundDuplicatedEntry(entry, otherEntries, duplicationRatio);
            if (found) {
                break;
            }
        }

        // Store duplicated entry
        if (found) {
            duplicatedEntries.addLast(entry);
            log.debug("Duplicated feed entry: " + entry.getTitle().trim());
        }
    }

    // Convert to byte array
    if (!duplicatedEntries.isEmpty()) {
        List list = feed.getEntries();
        list.removeAll(duplicatedEntries);
        WireFeed wire = feed.createWireFeed();
        WireFeedOutput out = new WireFeedOutput();
        StringWriter writer = new StringWriter();
        out.output(wire, writer);
        byte[] bytes = StringUtils.encodeString(writer.toString(), StringUtils.UTF_8);
        return bytes;
    }
    return null;
}

From source file:org.openxdm.xcap.client.test.error.NoParentTest.java

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

    // create content for tests      

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

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

    // create uri keys

    UserDocumentUriKey documentKey = new UserDocumentUriKey(appUsage.getAUID(), user, documentName);
    UserDocumentUriKey fakeAppUsageDocumentKey = new UserDocumentUriKey("eduardomartinsappusage", user,
            documentName);//  w  w w .  ja v  a  2  s .  c o  m

    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStepByPos("list", 2);
    ElementSelectorStep step3 = new ElementSelectorStep("display-name");
    elementSelectorSteps.add(step1);
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    ElementSelector elementSelector = new ElementSelector(elementSelectorSteps);
    UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, null);
    UserElementUriKey fakeAppUsageElementKey = new UserElementUriKey("eduardomartinsappusage", user,
            documentName, elementSelector, null);

    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, new AttributeSelector("name"), null);
    UserAttributeUriKey fakeAttrKey = new UserAttributeUriKey("eduardomartinsappusage", user, documentName,
            elementSelector, new AttributeSelector("name"), null);

    // DOCUMENT PARENT NOT FOUND

    NoParentConflictException exception = new NoParentConflictException(
            ServerConfiguration.SERVER_XCAP_ROOT + '/');
    exception.setSchemeAndAuthorityURI(
            "http://" + ServerConfiguration.SERVER_HOST + ":" + ServerConfiguration.SERVER_PORT);

    // 1. put new document and document parent not found

    // send put request and get response
    Response response = client.put(fakeAppUsageDocumentKey, appUsage.getMimetype(), documentContent, null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 2. put new element and document parent not found

    // send put request and get response
    response = client.put(fakeAppUsageElementKey, ElementResource.MIMETYPE, elementContent, null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 3. put new attribute and document parent not found

    // send put request and get response
    response = client.put(fakeAttrKey, AttributeResource.MIMETYPE, "", null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // DOCUMENT NOT FOUND

    exception = new NoParentConflictException(
            ServerConfiguration.SERVER_XCAP_ROOT + '/' + appUsage.getAUID() + "/users/" + user);
    exception.setSchemeAndAuthorityURI(
            "http://" + ServerConfiguration.SERVER_HOST + ":" + ServerConfiguration.SERVER_PORT);

    // 4. put new element and document not found

    // send put request and get response
    response = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null);
    // check response
    assertTrue("Response must exists", response != null);
    System.out.println("Response Content: " + response.getContent());
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 5. put new attribute and document not found

    // send put request and get response
    response = client.put(attrKey, AttributeResource.MIMETYPE, "", null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // ELEMENT PARENT NOT FOUND

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), documentContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue("Put response code should be 201", response.getCode() == 201);

    exception = new NoParentConflictException(ServerConfiguration.SERVER_XCAP_ROOT + '/' + appUsage.getAUID()
            + "/users/" + user + "/" + documentName + "/~~/resource-lists");
    exception.setSchemeAndAuthorityURI(
            "http://" + ServerConfiguration.SERVER_HOST + ":" + ServerConfiguration.SERVER_PORT);

    // 6. put new element and element parent not found

    // send put request and get response
    response = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 7. put new attribute and element parent not found

    // send put request and get response
    response = client.put(attrKey, AttributeResource.MIMETYPE, "", null);
    // check response
    assertTrue("Response must exists", response != null);
    assertTrue(
            "Response content must be the expected one and response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

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

From source file:org.openxdm.xcap.client.test.error.NotUTF8Test.java

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

    // exception for response codes
    NotUTF8ConflictException exception = new NotUTF8ConflictException();

    // create content for tests

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

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    char notUTF8Char = 0xA9;

    String goodAttrContent = "enemies";
    baos.write(goodAttrContent.getBytes("UTF8"));
    baos.write(notUTF8Char);//from  www .ja  va 2  s . co  m
    byte[] badAttrContent = baos.toByteArray();

    String goodElementContent = "<list xmlns=\"urn:ietf:params:xml:ns:resource-lists\"/>";
    baos.reset();
    baos.write("<list/>".getBytes("UTF8"));
    baos.write(notUTF8Char);
    baos.write("/>".getBytes("UTF8"));
    byte[] badElementContent = baos.toByteArray();

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

    baos.reset();
    baos.write(0xFE);
    baos.write(0xFF);
    String someDocumentContent3 = "<?xml version=\"1.0\" ?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"friends\"/>"
            + "</resource-lists>";
    baos.write(someDocumentContent3.getBytes("UTF8"));
    byte[] badDocumentContent3Bytes = baos.toByteArray();

    // 1. put new document

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

    // send put request and get response
    Response response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent1, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent2, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent3Bytes, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 2. replace document

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), goodDocumentContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue("Put response code should be 201", response.getCode() == 201);

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent1, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent2, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // send put request and get response
    response = client.put(documentKey, appUsage.getMimetype(), badDocumentContent3Bytes, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 3. put new element

    // create uri
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStepByPos("list", 2);
    elementSelectorSteps.add(step1);
    elementSelectorSteps.addLast(step2);
    ElementSelector elementSelector = new ElementSelector(elementSelectorSteps);
    UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, null);

    // send put request and get response
    response = client.put(elementKey, ElementResource.MIMETYPE, badElementContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 4. replace element

    // send put request and get response
    response = client.put(elementKey, ElementResource.MIMETYPE, goodElementContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue("Put response code should be 201", response.getCode() == 201);

    // send put request and get response
    response = client.put(elementKey, ElementResource.MIMETYPE, badElementContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 5. put new attr

    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null);

    // send put request and get response
    response = client.put(attrKey, AttributeResource.MIMETYPE, badAttrContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

    // 6. replace attr

    // send put request and get response
    response = client.put(attrKey, AttributeResource.MIMETYPE, goodAttrContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue("Put response code should be 201", response.getCode() == 201);

    // send put request and get response
    response = client.put(attrKey, AttributeResource.MIMETYPE, badAttrContent, null);
    // check put response
    assertTrue("Put response must exists", response != null);
    assertTrue(
            "Put response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            response.getCode() == exception.getResponseStatus()
                    && response.getContent().equals(exception.getResponseContent()));

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

}

From source file:com.zimbra.cs.fb.ExchangeMessage.java

protected void encodeFb(long s, long e, LinkedList<Byte> buf) {
    int start = millisToMinutes(s);
    int end = start + (int) ((e - s) / 60000);
    ZimbraLog.fb.debug("Start: %s %d", new Date(s).toGMTString(), start);
    ZimbraLog.fb.debug("End:   %s %d", new Date(e).toGMTString(), end);
    // swap bytes and convert to little endian.  then lay out bytes
    // two bytes each for start time, then end time
    buf.addLast((byte) (start & 0xFF));
    buf.addLast((byte) (start >> 8 & 0xFF));
    buf.addLast((byte) (end & 0xFF));
    buf.addLast((byte) (end >> 8 & 0xFF));
}