public final String asQuotedString(SerializationContext context) { // If possible, make a node and use that as the formatted output. if ( node == null ) node = asNode() ; if ( node != null ) return FmtUtils.stringForNode(node, context) ; return toString() ; }
@Test public void testNodeSortKey2() { final String[] unordered = {"Broager", "Åkirkeby", "Børkop", "Ærøskøbing", "Brædstrup", "Wandsbek"}; final String[] ordered = {"'Broager'", "'Brædstrup'", "'Børkop'", "'Wandsbek'", "'Ærøskøbing'", "'Åkirkeby'"}; // tests collation sort order for Danish final String collation = "da"; List<NodeValue> nodeValues = new LinkedList<>(); for (String string : unordered) { nodeValues.add(NodeValue.makeSortKey(string, collation)); } nodeValues.sort(new Comparator<NodeValue>() { @Override public int compare(NodeValue o1, NodeValue o2) { return NodeValue.compare(o1, o2); } }); List<String> result = new LinkedList<>(); for (NodeValue nv : nodeValues) { String s = nv.toString(); result.add(s); } assertArrayEquals(ordered, result.toArray(new String[0])); }
@Test public void testNodeSortKey3() { final String[] unordered = new String[] {"Broager", "Åkirkeby", "Børkop", "Ærøskøbing", "Brædstrup", "Wandsbek"}; final String[] ordered = new String[] {"'Ærøskøbing'", "'Åkirkeby'", "'Brædstrup'", "'Broager'", "'Børkop'", "'Wandsbek'"}; // tests collation sort order with Danish words, but New Zealand English collation rules final String collation = "en-NZ"; List<NodeValue> nodeValues = new LinkedList<>(); for (String string : unordered) { nodeValues.add(NodeValue.makeSortKey(string, collation)); } nodeValues.sort(new Comparator<NodeValue>() { @Override public int compare(NodeValue o1, NodeValue o2) { return NodeValue.compare(o1, o2); } }); List<String> result = new LinkedList<>(); for (NodeValue nv : nodeValues) { String s = nv.toString(); result.add(s); } assertArrayEquals(ordered, result.toArray(new String[0])); }
@Test public void testFunctionCollationExec() { collation function = new collation(); NodeValue collation = NodeValue.makeString("fi"); final String[] unordered = new String[] {"tšekin kieli", "tulun kieli", "töyhtöhyyppä", "tsahurin kieli", "tsahurin kieli", "tulun kieli"}; String[] ordered = new String[] {"'tsahurin kieli'", "'tsahurin kieli'", "'tšekin kieli'", "'tulun kieli'", "'tulun kieli'", "'töyhtöhyyppä'"}; // tests collation sort order with Danish words, but New Zealand English collation rules List<NodeValue> nodeValues = new LinkedList<>(); for (String string : unordered) { nodeValues.add(function.exec(collation, NodeValue.makeString(string))); } nodeValues.sort((NodeValue o1, NodeValue o2) -> NodeValue.compare(o1, o2) ); List<String> result = new LinkedList<>(); for (NodeValue nv : nodeValues) { String s = nv.toString(); result.add(s); } assertArrayEquals(ordered, result.toArray(new String[0])); } }
private static void test_exprSprintf_tz_exact(String nodeStr) { String exprStr = "afn:sprintf('%1$tm %1$te,%1$tY', "+NodeValue.makeDateTime(nodeStr).toString()+")" ; Expr expr = ExprUtils.parse(exprStr) ; NodeValue r = expr.eval(null, LibTestExpr.createTest()) ; assertTrue(r.isString()) ; String s = r.getString() ; // Parse the date String dtFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"; SimpleDateFormat sdtFormat = new SimpleDateFormat(dtFormat); Date dtDate = null; try { dtDate = sdtFormat.parse(nodeStr); } catch (ParseException e) { assertFalse("Cannot parse the input date string. Message:"+e.getMessage(),false); } // print the date based on the current timeZone. SimpleDateFormat stdFormatOut = new SimpleDateFormat("MM dd,yyyy"); stdFormatOut.setTimeZone(TimeZone.getDefault()); String outDate = stdFormatOut.format(dtDate); assertEquals(s,outDate); }
private static void test_exprSprintf_tz_possibilites(String nodeStr, String... possible) { String exprStr = "afn:sprintf('%1$tm %1$te,%1$tY', "+NodeValue.makeDateTime(nodeStr).toString()+")" ; Expr expr = ExprUtils.parse(exprStr) ; NodeValue r = expr.eval(null, LibTestExpr.createTest()) ; assertTrue(r.isString()) ; String s = r.getString() ; // Timezones! The locale data can be -1, 0, +1 from the Z day. boolean b = false ; for (String poss : possible ) { if ( poss.equals(s) ) b = true ; } assertTrue(b) ; }