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:org.geoserver.importer.Directory.java

public List<Directory> flatten() {
    List<Directory> flat = new ArrayList<Directory>();

    LinkedList<Directory> q = new LinkedList<Directory>();
    q.addLast(this);
    while (!q.isEmpty()) {
        Directory dir = q.removeFirst();
        flat.add(dir);/*from w  w  w  .  j  a  va 2s .c o m*/

        for (Iterator<FileData> it = dir.getFiles().iterator(); it.hasNext();) {
            FileData f = it.next();
            if (f instanceof Directory) {
                Directory d = (Directory) f;
                it.remove();
                q.addLast(d);
            }
        }
    }

    return flat;
}

From source file:com.rapidminer.operator.preprocessing.discretization.MinimalEntropyDiscretization.java

private ArrayList<Double> getSplitpoints(LinkedList<double[]> startPartition, Attribute label) {
    LinkedList<LinkedList<double[]>> border = new LinkedList<LinkedList<double[]>>();
    ArrayList<Double> result = new ArrayList<Double>();
    border.addLast(startPartition);
    while (!border.isEmpty()) {
        LinkedList<double[]> currentPartition = border.removeFirst();
        Double splitpoint = this.getMinEntropySplitpoint(currentPartition, label);
        if (splitpoint != null) {
            result.add(splitpoint);/*from  w  w w. j  a  v  a 2  s .c  o m*/
            double splitValue = splitpoint.doubleValue();
            LinkedList<double[]> newPartition1 = new LinkedList<double[]>();
            LinkedList<double[]> newPartition2 = new LinkedList<double[]>();
            Iterator<double[]> it = currentPartition.iterator();
            while (it.hasNext()) { // Create new partitions.
                double[] attributeLabelPair = it.next();
                if (attributeLabelPair[0] <= splitValue) {
                    newPartition1.addLast(attributeLabelPair);
                } else {
                    newPartition2.addLast(attributeLabelPair);
                }
            }
            border.addLast(newPartition1);
            border.addLast(newPartition2);
        }
    }
    return result; // Empty ArrayList if no Splitpoint could be found.

}

From source file:org.openxdm.xcap.client.test.success.PutNewElementByAttrTest.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\"/>"
            + "</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 ElementSelectorStepByAttr("*", "name", "friends");
    ElementSelectorStep step3 = new ElementSelectorStepByAttr("entry", "uri", "sip:alice@example.com");
    elementSelectorSteps.add(step1);/*from   w  w  w .  j a  v a  2  s  .  co m*/
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    UserElementUriKey elemKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), null);

    // the elem to put
    String element = "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"/>";
    String element2 = "<entry uri=\"sip:alice@example.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\"/>";

    // send put request and get response
    Response elemPutResponse = client.put(elemKey, ElementResource.MIMETYPE, element, null);

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

    // 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 200 and the elem value must equals the one sent in put",
            elemGetResponse.getCode() == 200
                    && (XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element)
                            || XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element2)));

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

From source file:org.openxdm.xcap.client.test.success.ReplaceExistingElementByAttrTest.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\">"
            + "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"/>"
            + "</list>" + "</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 ElementSelectorStepByAttr("*", "name", "friends");
    ElementSelectorStep step3 = new ElementSelectorStepByAttr("entry", "uri", "sip:alice@example.com");
    elementSelectorSteps.add(step1);/*from ww w .j ava 2 s  .c om*/
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    UserElementUriKey elemKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), null);

    // the elem to put
    String element = "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"><display-name>alice</display-name></entry>";
    String element2 = "<entry uri=\"sip:alice@example.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\"><display-name>alice</display-name></entry>";

    // send put request and get response
    Response elemPutResponse = client.put(elemKey, ElementResource.MIMETYPE, element, null);

    // check put response
    assertTrue("Put response must exists", elemPutResponse != null);
    assertTrue("Put response code should be 200", elemPutResponse.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 200 and the elem value must equals the one sent in put",
            elemGetResponse.getCode() == 200
                    && (XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element)
                            || XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element2)));

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

}

From source file:edu.cmu.sv.modelinference.eventtool.PredictionModel.java

public List<Range<Integer>> findThresholdViolations(double[] xs, double[] yObserved) {
    int maxPredictions = Math.min(xs.length, upperThreshold.size());
    LinkedList<Range<Integer>> violations = new LinkedList<>();
    boolean ongoingViolation = false;
    int violationStart = 0;
    for (int i = 1; i < maxPredictions; i++) {
        double x = xs[i];
        if (!ongoingViolation && isViolation((int) x, yObserved[i])) {
            violationStart = (int) xs[i];
            ongoingViolation = true;//from w w w  .ja  v  a  2s  . co  m
        } else if (ongoingViolation && !isViolation((int) x, yObserved[i])) {
            violations.addLast(Range.closedOpen(violationStart, (int) x));
            ongoingViolation = false;
        }
    }
    return violations;
}

From source file:org.waveprotocol.box.server.robots.dataapi.BaseApiServlet.java

/**
 * Handles an {@link OperationResults} by submitting the deltas that are
 * generated and writing a response to the robot.
 *
 * @param operations the operations//from   w w  w.ja v  a  2 s.  c  o  m
 * @param results the results of the operations performed.
 * @param resp the servlet to write the response in.
 * @param version the version of the protocol to use for writing a response.
 * @throws IOException if the response can not be written.
 */
private void handleResults(List<OperationRequest> operations, OperationResults results,
        HttpServletResponse resp, ProtocolVersion version) throws IOException {
    OperationUtil.submitDeltas(results, waveletProvider, LOGGING_REQUEST_LISTENER);

    // Ensure that responses are returned in the same order as corresponding
    // requests.
    LinkedList<JsonRpcResponse> responses = Lists.newLinkedList();
    for (OperationRequest operation : operations) {
        String opId = operation.getId();
        JsonRpcResponse response = results.getResponses().get(opId);
        responses.addLast(response);
    }

    String jsonResponse = robotSerializer.serialize(responses, GsonFactory.JSON_RPC_RESPONSE_LIST_TYPE,
            version);
    LOG.fine("Returning the following Json: " + jsonResponse);

    // Write the response back through the HttpServlet
    try {
        resp.setContentType(JSON_CONTENT_TYPE);
        PrintWriter writer = resp.getWriter();
        writer.append(jsonResponse);
        writer.flush();
        resp.setStatus(HttpServletResponse.SC_OK);
    } catch (IOException e) {
        LOG.severe("IOException during writing of a response", e);
        throw e;
    }
}

From source file:org.openxdm.xcap.client.test.success.PutNewElementByAttrPosTest.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\"/>"
            + "</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 ElementSelectorStepByAttr("*", "name", "friends");
    ElementSelectorStep step3 = new ElementSelectorStepByPosAttr("entry", 1, "uri", "sip:alice@example.com");
    elementSelectorSteps.add(step1);/*from  w ww .j  av a2s.  co  m*/
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    UserElementUriKey elemKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), null);

    // the elem to put
    String element = "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"/>";
    String element2 = "<entry uri=\"sip:alice@example.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\"/>";

    // send put request and get response
    Response elemPutResponse = client.put(elemKey, ElementResource.MIMETYPE, element, null);

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

    // 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 200 and the elem value must equals the one sent in put",
            elemGetResponse.getCode() == 200
                    && (XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element)
                            || XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element2)));

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

From source file:org.openxdm.xcap.client.test.success.ReplaceExistingElementByAttrPosTest.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\">"
            + "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"/>"
            + "</list>" + "</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 ElementSelectorStepByAttr("*", "name", "friends");
    ElementSelectorStep step3 = new ElementSelectorStepByPosAttr("entry", 1, "uri", "sip:alice@example.com");
    elementSelectorSteps.add(step1);//www  .ja  v a 2  s  .  com
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    UserElementUriKey elemKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), null);

    // the elem to put
    String element = "<entry xmlns=\"urn:ietf:params:xml:ns:resource-lists\" uri=\"sip:alice@example.com\"><display-name>alice</display-name></entry>";
    String element2 = "<entry uri=\"sip:alice@example.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\"><display-name>alice</display-name></entry>";

    // send put request and get response
    Response elemPutResponse = client.put(elemKey, ElementResource.MIMETYPE, element, null);

    // check put response
    assertTrue("Put response must exists", elemPutResponse != null);
    assertTrue("Put response code should be 200", elemPutResponse.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 200 and the elem value must equals the one sent in put",
            elemGetResponse.getCode() == 200
                    && (XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element)
                            || XMLValidator.weaklyEquals((String) elemGetResponse.getContent(), element2)));

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

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

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

    // create exception for return codes
    UnsupportedMediaTypeException exception = new UnsupportedMediaTypeException();

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

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

    // CREATES//from   w ww .ja  v  a2  s  . c o m

    // send put request and get response
    Response response = client.put(documentKey, "badmimetype", documentContent, null);

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

    // 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);

    String elementContent = "<list name=\"friends\"/>";

    // create element selector      
    LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
    ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
    ElementSelectorStep step2 = new ElementSelectorStepByAttr("list", "name", "friends");
    elementSelectorSteps.add(step1);
    elementSelectorSteps.addLast(step2);
    ElementSelector elementSelector = new ElementSelector(elementSelectorSteps);

    // create element uri key as a fake document uri key, no other way to send a bad mimetype      
    UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, null);
    UnsupportedMediaTypeFakeDocumentUriKey evilKey = new UnsupportedMediaTypeFakeDocumentUriKey(elementKey);

    // send put request and get response      
    response = client.put(evilKey, "badmimetype", elementContent, null);

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

    elementSelectorSteps.removeLast();
    ElementSelectorStep step3 = new ElementSelectorStep("list");
    elementSelectorSteps.add(step3);
    elementSelector = new ElementSelector(elementSelectorSteps);

    AttributeSelector attributeSelector = new AttributeSelector("name");

    // create uri key      
    UserAttributeUriKey attributeKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, attributeSelector, null);
    AnotherUnsupportedMediaTypeFakeDocumentUriKey anotherEvilKey = new AnotherUnsupportedMediaTypeFakeDocumentUriKey(
            attributeKey);
    // send put request and get response
    response = client.put(anotherEvilKey, "badmimetype", "friends", null);

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

    // REPLACES

    // send put request and get response
    response = client.put(documentKey, "badmimetype", documentContent, null);

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

    // create uri key      
    elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null);

    // send put request and get response
    response = client.put(evilKey, "badmimetype", elementContent, null);

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

    // send put request and get response
    response = client.put(attributeKey, AttributeResource.MIMETYPE, "friends", 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(anotherEvilKey, "badmimetype", "friends", null);

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

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

From source file:ubic.pubmedgate.interactions.focusedAnalysis.FilterConnectionMatrix.java

public FilterConnectionMatrix(String filename) throws Exception {
    direction = Direction.ANYDIRECTION;/*from   ww w. j a  v a  2s. co m*/
    DoubleMatrixReader matrixReader = new DoubleMatrixReader();
    // matrixReader.setTopLeft( false );
    this.filename = filename;
    connectionMatrix = matrixReader.read(filename);
    log.info("Loaded matrix: " + connectionMatrix.rows() + " X " + connectionMatrix.columns());
    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);
    bamsLoader = new BAMSDataLoader();

    // load BAMS matrix from NIF (not up-propigated)
    BAMSFromNIFDataLoader connectionLoader = new BAMSFromNIFDataLoader();
    boolean skipFibers = true;
    DoubleMatrix<String, String> BAMSNIFConnectionMatrix = connectionLoader.getBAMSMatrix(direction, false,
            false, skipFibers);
    BAMSNIFConnections = new ABAMSDataMatrix(BAMSNIFConnectionMatrix, "NIFConnectivity",
            new CorrelationAdjacency(BAMSNIFConnectionMatrix));
    BAMSNIFConnections = BAMSNIFConnections.removeZeroColumns();
    BAMSNIFConnections = BAMSNIFConnections.removeZeroRows();
    log.info("NIF Connections:" + BAMSNIFConnections.getDimensionString());

}