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());
}
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);
}
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);
}
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();
}
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;
}
Aggregations