use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class CSVSerializerTest method testQuotedQuoteWriteObject.
@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedQuoteWriteObject() throws IOException {
List<Object> items = new ArrayList<>();
items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", "\"b\""), new Dictionary.Pair<String, Object>("C", "c")));
StringWriter writer = new StringWriter();
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
serializer.writeObject(items, writer);
assertEquals("a,\"\"\"b\"\"\",c\r\n", writer.toString());
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class CSVSerializerTest method testQuotedCommaWriteObject.
@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedCommaWriteObject() throws IOException {
List<Object> items = new ArrayList<>();
items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", ",b,"), new Dictionary.Pair<String, Object>("C", "c")));
StringWriter writer = new StringWriter();
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
serializer.writeObject(items, writer);
assertEquals("a,\",b,\",c\r\n", writer.toString());
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TextPaneDemo method applyStyle.
private void applyStyle(Document document, Span selectionSpan, StyleApplicator styleApplicator) {
// I can't apply the styles while iterating over the tree, because I
// need to update the tree.
// So first collect a list of all the nodes in the tree.
List<Node> nodeList = new ArrayList<>();
collectNodes(document, nodeList);
final int selectionStart = textPane.getSelectionStart();
final int selectionLength = textPane.getSelectionLength();
for (Node node : nodeList) {
if (node instanceof TextSpan) {
TextSpan span = (TextSpan) node;
int documentOffset = node.getDocumentOffset();
int characterCount = node.getCharacterCount();
Span textSpan = new Span(documentOffset, documentOffset + characterCount - 1);
if (selectionSpan.intersects(textSpan)) {
applyStyleToSpanNode(selectionSpan, styleApplicator, span, characterCount, textSpan);
}
}
if (node instanceof org.apache.pivot.wtk.text.TextNode) {
org.apache.pivot.wtk.text.TextNode textNode = (org.apache.pivot.wtk.text.TextNode) node;
int documentOffset = node.getDocumentOffset();
int characterCount = node.getCharacterCount();
Span textSpan = new Span(documentOffset, documentOffset + characterCount - 1);
if (selectionSpan.intersects(textSpan)) {
applyStyleToTextNode(selectionSpan, styleApplicator, textNode, characterCount, textSpan);
}
}
}
// maintain the selected range
textPane.setSelection(selectionStart, selectionLength);
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class XMLViewer method updateProperties.
public void updateProperties() {
Node node = (Node) treeView.getSelectedNode();
if (node == null) {
// no selection, but it's ok
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
textArea.setText(textNode.getText());
propertiesCardPane.setSelectedIndex(1);
} else if (node instanceof Element) {
Element element = (Element) node;
// Populate the namespaces table
ArrayList<HashMap<String, String>> namespacesTableData = new ArrayList<>();
String defaultNamespaceURI = element.getDefaultNamespaceURI();
if (defaultNamespaceURI != null) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", "(default)");
row.put("uri", defaultNamespaceURI);
namespacesTableData.add(row);
}
Element.NamespaceDictionary namespaceDictionary = element.getNamespaces();
for (String prefix : namespaceDictionary) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", prefix);
row.put("uri", namespaceDictionary.get(prefix));
namespacesTableData.add(row);
}
namespacesTableView.setTableData(namespacesTableData);
// Populate the attributes table
ArrayList<HashMap<String, String>> attributesTableData = new ArrayList<>();
for (Element.Attribute attribute : element.getAttributes()) {
HashMap<String, String> row = new HashMap<>();
String attributeName = attribute.getName();
row.put("name", attributeName);
row.put("value", element.getElementDictionary().get(attributeName));
attributesTableData.add(row);
}
attributesTableView.setTableData(attributesTableData);
propertiesCardPane.setSelectedIndex(0);
} else {
throw new IllegalStateException();
}
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class VoteResultTest method test1.
@Test
public void test1() {
ArrayList<Vote> votes = new ArrayList<>();
votes.add(Vote.APPROVE);
votes.add(Vote.DEFER);
votes.add(Vote.DENY);
// These are the expected results as each vote is tallied
ArrayList<Vote> results = new ArrayList<>();
results.add(Vote.APPROVE);
results.add(Vote.DEFER);
results.add(Vote.DENY);
VoteResult result = new VoteResult();
Iterator<Vote> resultIter = results.iterator();
for (Vote vote : votes) {
result.tally(vote);
assertEquals(result.get(), resultIter.next());
}
}
Aggregations