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.openxdm.xcap.client.test.success.DeleteElementByNameTest.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\">"
            + "<display-name>" + "</display-name>" + "</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 ElementSelectorStep("list");
    ElementSelectorStep step3 = new ElementSelectorStep("display-name");
    elementSelectorSteps.add(step1);//  ww w  .  java 2 s  . c  o m
    elementSelectorSteps.addLast(step2);
    elementSelectorSteps.addLast(step3);
    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.error.CannotDeleteTest.java

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

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

    String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"friends\">"
            + "<entry uri=\"sip:alice@example.com\"/>" +
            //"<entry-ref ref=\"resource-lists/users/sip%3Ababel%40example.com/index/~~/resource-lists/list\"/>" +
            "<list name=\"enemies\"/>"
            + "<external anchor=\"http://localhost:8888/xcap-root/resource-lists/users/sip%3Abill%40example.com/index/~~/resource-lists/list\"/>"
            + "<entry-ref ref=\"resource-lists/users/sip%3Ababel%40example.com/index/~~/resource-lists/list\"/>"
            + "<cannot-delete name=\"fake\" xmlns=\"extension\"/>"
            + "<cannot-delete name=\"fake\" xmlns=\"extension\"/>" +
            //"<entry uri=\"sip:alice@example.com\"/>" +
            "</list>" + "</resource-lists>";

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

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

    // create element selector      
    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 a  v a  2 s  .c o  m*/
    elementSelectorSteps.addLast(step2);
    ElementSelector elementSelector = new ElementSelector(elementSelectorSteps);

    // create namespace bindings to be used in this test
    Map<String, String> nsBindings = new HashMap<String, String>();
    nsBindings.put("pre", "extension");

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

    // create elem uri      
    ElementSelectorStep step3 = new ElementSelectorStepByPos("*", 5);
    elementSelectorSteps.addLast(step3);
    UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName,
            elementSelector, nsBindings);
    // send delete and get response
    Response deleteResponse = client.delete(elementKey, null);
    assertTrue("Delete response must exists", deleteResponse != null);
    assertTrue(
            "Delete response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            deleteResponse.getCode() == exception.getResponseStatus()
                    && deleteResponse.getContent().equals(exception.getResponseContent()));

    // create elem uri      
    step3 = new ElementSelectorStepByPos("pre:cannot-delete", 1);
    elementSelectorSteps.removeLast();
    elementSelectorSteps.addLast(step3);
    elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, nsBindings);
    // send delete request and get response
    deleteResponse = client.delete(elementKey, null);
    assertTrue("Delete response must exists", deleteResponse != null);
    assertTrue(
            "Delete response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            deleteResponse.getCode() == exception.getResponseStatus()
                    && deleteResponse.getContent().equals(exception.getResponseContent()));

    //create elem uri      
    step3 = new ElementSelectorStepByPosAttr("*", 5, "name", "fake");
    elementSelectorSteps.removeLast();
    elementSelectorSteps.addLast(step3);
    elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, nsBindings);
    // send delete request and get response
    deleteResponse = client.delete(elementKey, null);
    assertTrue("Delete response must exists", deleteResponse != null);
    assertTrue(
            "Delete response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            deleteResponse.getCode() == exception.getResponseStatus()
                    && deleteResponse.getContent().equals(exception.getResponseContent()));

    // send delete request and get response
    step3 = new ElementSelectorStepByPosAttr("pre:cannot-delete", 1, "name", "fake");
    elementSelectorSteps.removeLast();
    elementSelectorSteps.addLast(step3);
    elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, nsBindings);
    deleteResponse = client.delete(elementKey, null);
    assertTrue("Delete response must exists", deleteResponse != null);
    assertTrue(
            "Delete response content must be the expected and the response code should be "
                    + exception.getResponseStatus(),
            deleteResponse.getCode() == exception.getResponseStatus()
                    && deleteResponse.getContent().equals(exception.getResponseContent()));

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

From source file:org.openxdm.xcap.client.test.success.PutNewElementByNameTest.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 ElementSelectorStep("entry");
    elementSelectorSteps.add(step1);/*from  www .  j  a va2 s .  c  o 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.ReplaceExistingElementByNameTest.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 ElementSelectorStep("entry");
    elementSelectorSteps.add(step1);//  w  ww  .  j a  va2 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\"><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:com.mirth.connect.plugins.serverlog.ServerLogProvider.java

public LinkedList<String[]> getServerLogs(String sessionId) {
    // work with deep copied clone of the static server logs object in
    // order to avoid multiple threads ConcurrentModificationException.
    LinkedList<String[]> serverLogsCloned = new LinkedList<String[]>();

    try {// ww w . ja  va2s. co m
        serverLogsCloned = (LinkedList<String[]>) SerializationUtils.clone(serverLogs);
    } catch (SerializationException e) {
        // ignore
    }

    if (lastDisplayedServerLogIdBySessionId.containsKey(sessionId)) {
        // client exist with the sessionId.
        // -> only display new log entries.
        long lastDisplayedServerLogId = lastDisplayedServerLogIdBySessionId.get(sessionId);

        LinkedList<String[]> newServerLogEntries = new LinkedList<String[]>();
        // FYI, channelLog.size() will never be larger than LOG_SIZE =
        // 100.
        for (String[] aServerLog : serverLogsCloned) {
            if (lastDisplayedServerLogId < Long.parseLong(aServerLog[0])) {
                newServerLogEntries.addLast(aServerLog);
            }
        }

        if (newServerLogEntries.size() > 0) {
            // put the lastDisplayedLogId into the HashMap. index 0 is
            // the most recent entry, and index0 of that entry contains
            // the logId.
            lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(newServerLogEntries.get(0)[0]));
        }

        try {
            return SerializationUtils.clone(newServerLogEntries);
        } catch (SerializationException e) {
            logger.error(e);
        }
    } else {
        // brand new client. i.e. brand new session id, and all log
        // entries are new.
        // -> display all log entries.
        if (serverLogsCloned.size() > 0) {
            lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(serverLogsCloned.get(0)[0]));
        } else {
            // no log exist at all. put the currentLogId-1, which is the
            // very latest logId.
            lastDisplayedServerLogIdBySessionId.put(sessionId, logId - 1);
        }

        try {
            return SerializationUtils.clone(serverLogsCloned);
        } catch (SerializationException e) {
            logger.error(e);
        }
    }

    return null;
}

From source file:org.openxdm.xcap.client.test.success.PutNewElementByPosTest.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 ElementSelectorStepByPos("entry", 1);
    elementSelectorSteps.add(step1);//w  w  w . java  2s  . c  o 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:alma.acs.tmcdb.compare.TestHighLevelNodes.java

private String[] getSubNodes(DAL dal, String subnode) throws Exception {
    ArrayList<String> subnodes = new ArrayList<String>();

    LinkedList<String> stack = new LinkedList<String>();
    stack.addLast(subnode);

    while (!stack.isEmpty()) {
        String parentNode = stack.removeLast().toString();

        String nodes = dal.list_nodes(parentNode);
        if (nodes.length() > 0) {
            StringTokenizer tokenizer = new StringTokenizer(nodes);
            while (tokenizer.hasMoreTokens()) {
                String nodeName = tokenizer.nextToken();
                if (nodeName.endsWith(".xml"))
                    continue;

                String fullName = parentNode + "/" + nodeName;
                stack.addLast(fullName);
                // strip off relative path
                subnodes.add(fullName.substring(subnode.length() + 1));
            }/*from  w  ww .j a  v  a2  s. com*/
        }
    }

    String[] retVal = new String[subnodes.size()];
    subnodes.toArray(retVal);
    return retVal;
}

From source file:org.openxdm.xcap.client.test.success.ReplaceExistingElementByPosTest.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 ElementSelectorStepByPos("entry", 1);
    elementSelectorSteps.add(step1);/*from  w  ww  .  j  a  v a  2  s  .c o  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\"><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.NotXMLAttributeValueTest.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  . ja v  a2 s.c  o m
    elementSelectorSteps.addLast(step2);
    UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName,
            new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null);

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

    // 2. put new attr

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

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

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

    // 2. replace attr

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

    // check put response
    assertTrue("Put response must exists", attrPutResponse != null);
    assertTrue("Put response code should be 201, instead it was " + attrPutResponse.getCode() + ", content = "
            + attrPutResponse.getContent(), attrPutResponse.getCode() == 201);

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

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

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

    //TODO bad char and entity refs puts

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

From source file:org.gephi.statistics.plugin.GraphDistance.java

public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
    isCanceled = false;/*from   w w w . j av  a  2  s.  c  om*/
    AttributeTable nodeTable = attributeModel.getNodeTable();
    AttributeColumn eccentricityCol = nodeTable.getColumn(ECCENTRICITY);
    AttributeColumn closenessCol = nodeTable.getColumn(CLOSENESS);
    AttributeColumn betweenessCol = nodeTable.getColumn(BETWEENNESS);
    if (eccentricityCol == null) {
        eccentricityCol = nodeTable.addColumn(ECCENTRICITY, "Eccentricity", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }
    if (closenessCol == null) {
        closenessCol = nodeTable.addColumn(CLOSENESS, "Closeness Centrality", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }
    if (betweenessCol == null) {
        betweenessCol = nodeTable.addColumn(BETWEENNESS, "Betweenness Centrality", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }

    hgraph.readLock();

    N = hgraph.getNodeCount();

    betweenness = new double[N];
    eccentricity = new double[N];
    closeness = new double[N];
    diameter = 0;
    avgDist = 0;
    shortestPaths = 0;
    radius = Integer.MAX_VALUE;
    HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
    int index = 0;
    for (Node s : hgraph.getNodes()) {
        indicies.put(s, index);
        index++;
    }

    Progress.start(progress, hgraph.getNodeCount());
    int count = 0;
    for (Node s : hgraph.getNodes()) {
        Stack<Node> S = new Stack<Node>();

        LinkedList<Node>[] P = new LinkedList[N];
        double[] theta = new double[N];
        int[] d = new int[N];
        for (int j = 0; j < N; j++) {
            P[j] = new LinkedList<Node>();
            theta[j] = 0;
            d[j] = -1;
        }

        int s_index = indicies.get(s);

        theta[s_index] = 1;
        d[s_index] = 0;

        LinkedList<Node> Q = new LinkedList<Node>();
        Q.addLast(s);
        while (!Q.isEmpty()) {
            Node v = Q.removeFirst();
            S.push(v);
            int v_index = indicies.get(v);

            EdgeIterable edgeIter = null;
            if (isDirected) {
                edgeIter = ((HierarchicalDirectedGraph) hgraph).getOutEdgesAndMetaOutEdges(v);
            } else {
                edgeIter = hgraph.getEdgesAndMetaEdges(v);
            }

            for (Edge edge : edgeIter) {
                Node reachable = hgraph.getOpposite(v, edge);

                int r_index = indicies.get(reachable);
                if (d[r_index] < 0) {
                    Q.addLast(reachable);
                    d[r_index] = d[v_index] + 1;
                }
                if (d[r_index] == (d[v_index] + 1)) {
                    theta[r_index] = theta[r_index] + theta[v_index];
                    P[r_index].addLast(v);
                }
            }
        }
        double reachable = 0;
        for (int i = 0; i < N; i++) {
            if (d[i] > 0) {
                avgDist += d[i];
                eccentricity[s_index] = (int) Math.max(eccentricity[s_index], d[i]);
                closeness[s_index] += d[i];
                diameter = Math.max(diameter, d[i]);
                reachable++;
            }
        }

        radius = (int) Math.min(eccentricity[s_index], radius);

        if (reachable != 0) {
            closeness[s_index] /= reachable;
        }

        shortestPaths += reachable;

        double[] delta = new double[N];
        while (!S.empty()) {
            Node w = S.pop();
            int w_index = indicies.get(w);
            ListIterator<Node> iter1 = P[w_index].listIterator();
            while (iter1.hasNext()) {
                Node u = iter1.next();
                int u_index = indicies.get(u);
                delta[u_index] += (theta[u_index] / theta[w_index]) * (1 + delta[w_index]);
            }
            if (w != s) {
                betweenness[w_index] += delta[w_index];
            }
        }
        count++;
        if (isCanceled) {
            hgraph.readUnlockAll();
            return;
        }
        Progress.progress(progress, count);
    }

    avgDist /= shortestPaths;//mN * (mN - 1.0f);

    for (Node s : hgraph.getNodes()) {
        AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
        int s_index = indicies.get(s);

        if (!isDirected) {
            betweenness[s_index] /= 2;
        }
        if (isNormalized) {
            closeness[s_index] = (closeness[s_index] == 0) ? 0 : 1.0 / closeness[s_index];
            betweenness[s_index] /= isDirected ? (N - 1) * (N - 2) : (N - 1) * (N - 2) / 2;
        }
        row.setValue(eccentricityCol, eccentricity[s_index]);
        row.setValue(closenessCol, closeness[s_index]);
        row.setValue(betweenessCol, betweenness[s_index]);
    }
    hgraph.readUnlock();
}