Search in sources :

Example 56 with Stack

use of java.util.Stack in project jersey by jersey.

the class EntityTypesTest method testJAXBListRepresentationJSON.

@Test
public void testJAXBListRepresentationJSON() throws Exception {
    final WebTarget target = target("JAXBListResourceJSON");
    Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new LinkedList<>(a);
    b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
    }, "application/json"), new GenericType<Queue<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new HashSet<>(a);
    b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
    }, "application/json"), new GenericType<Set<JaxbBean>>() {
    });
    final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {

        @Override
        public int compare(final JaxbBean t, final JaxbBean t1) {
            return t.value.compareTo(t1.value);
        }
    };
    final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
    final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
    t1.addAll(a);
    t2.addAll(b);
    assertEquals(t1, t2);
    final Stack<JaxbBean> s = new Stack<>();
    s.addAll(a);
    b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
    }, "application/json"), new GenericType<Stack<JaxbBean>>() {
    });
    assertEquals(s, b);
    a = new MyArrayList<>(a);
    b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
    }, "application/json"), new GenericType<MyArrayList<JaxbBean>>() {
    });
    assertEquals(a, b);
// TODO: would be nice to produce/consume a real JSON array like following
// instead of what we have now:
//        JSONArray a = r.get(JSONArray.class);
//        JSONArray b = new JSONArray().
//                put(new JSONObject().put("value", "one")).
//                put(new JSONObject().put("value", "two")).
//                put(new JSONObject().put("value", "three"));
//        assertEquals(a.toString(), b.toString());
//        JSONArray c = r.post(JSONArray.class, b);
//        assertEquals(a.toString(), c.toString());
}
Also used : GenericType(javax.ws.rs.core.GenericType) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Comparator(java.util.Comparator) Stack(java.util.Stack) GenericEntity(javax.ws.rs.core.GenericEntity) TreeSet(java.util.TreeSet) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Queue(java.util.Queue) Test(org.junit.Test)

Example 57 with Stack

use of java.util.Stack in project jersey by jersey.

the class EntityTypesTest method testJAXBListRepresentationFastInfoset.

/**
     * TODO, the unmarshalling fails.
     */
@Test
@Ignore("TODO: unignore once fi support implemented (JERSEY-1190)")
public // TODO: unignore once fi support implemented (JERSEY-1190)
void testJAXBListRepresentationFastInfoset() {
    final WebTarget target = target("JAXBListResourceFastInfoset");
    Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new LinkedList<>(a);
    b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
    }, "application/fastinfoset"), new GenericType<Queue<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new HashSet<>(a);
    b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
    }, "application/fastinfoset"), new GenericType<Set<JaxbBean>>() {
    });
    final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {

        @Override
        public int compare(final JaxbBean t, final JaxbBean t1) {
            return t.value.compareTo(t1.value);
        }
    };
    final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
    final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
    t1.addAll(a);
    t2.addAll(b);
    assertEquals(t1, t2);
    final Stack<JaxbBean> s = new Stack<>();
    s.addAll(a);
    b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
    }, "application/fastinfoset"), new GenericType<Stack<JaxbBean>>() {
    });
    assertEquals(s, b);
    a = new MyArrayList<>(a);
    b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
    }, "application/fastinfoset"), new GenericType<MyArrayList<JaxbBean>>() {
    });
    assertEquals(a, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Comparator(java.util.Comparator) Stack(java.util.Stack) GenericEntity(javax.ws.rs.core.GenericEntity) TreeSet(java.util.TreeSet) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Queue(java.util.Queue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with Stack

use of java.util.Stack in project jersey by jersey.

the class JsonMoxyTest method testJAXBListRepresentationJSONStack.

@Test
public void testJAXBListRepresentationJSONStack() throws Exception {
    final WebTarget target = target("JAXBListResourceJSON");
    final Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    final Collection<JaxbBean> b;
    final Stack<JaxbBean> s = new Stack<>();
    s.addAll(a);
    b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
    }, "application/json"), new GenericType<Stack<JaxbBean>>() {
    });
    assertEquals(s, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Stack(java.util.Stack) Test(org.junit.Test)

Example 59 with Stack

use of java.util.Stack in project darkFunction-Editor by darkFunction.

the class CommandManager method init.

private void init() {
    undoStack = new Stack();
    redoStack = new Stack();
}
Also used : Stack(java.util.Stack)

Example 60 with Stack

use of java.util.Stack in project Algorithms by pedrovgs.

the class BinaryTreeInOrder method getIterative.

/**
   * Iterative implementation of this binary tree traversal. The complexity order in time terms of
   * this algorithm is O(N) where N is the number of nodes in the tree. In space terms the
   * complexity order of this algorithm is also O(N) where N is the number of nodes we have to
   * store in the auxiliary data structure, the stack.
   */
public List<BinaryNode<Integer>> getIterative(BinaryNode<Integer> root) {
    validateBinaryNode(root);
    List<BinaryNode<Integer>> result = new LinkedList<BinaryNode<Integer>>();
    Stack<BinaryNode> stack = new Stack<BinaryNode>();
    //Define a pointer to track nodes
    BinaryNode current = root;
    while (!stack.empty() || current != null) {
        if (current != null) {
            //If it is not null, push to stack and go down the tree to left
            stack.push(current);
            current = current.getLeft();
        } else {
            //If no left child pop stack, process the node then let current point to the right
            BinaryNode node = stack.pop();
            result.add(node);
            current = node.getRight();
        }
    }
    return result;
}
Also used : BinaryNode(com.github.pedrovgs.binarytree.BinaryNode) LinkedList(java.util.LinkedList) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)300 HashSet (java.util.HashSet)50 ArrayList (java.util.ArrayList)47 File (java.io.File)29 IOException (java.io.IOException)23 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 View (android.view.View)18 Set (java.util.Set)17 List (java.util.List)16 LinkedList (java.util.LinkedList)15 ViewGroup (android.view.ViewGroup)14 Map (java.util.Map)13 Iterator (java.util.Iterator)12 Document (org.w3c.dom.Document)11 ImageView (android.widget.ImageView)10 Matcher (java.util.regex.Matcher)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9