ValuePattern { public static Iterable<String> getStrings(NodeBuilder node, String propertyName) { if (!node.hasProperty(propertyName)) { return null; } PropertyState s = node.getProperty(propertyName); if (s.isArray()) { return node.getProperty(propertyName).getValue(Type.STRINGS); } return Collections.singleton(node.getString(propertyName)); } ValuePattern(NodeBuilder node);  ValuePattern(NodeState node);  ValuePattern();  ValuePattern(String pattern, 
            Iterable<String> includePrefixes, Iterable<String> excludePrefixes); boolean matches(String v); boolean matchesAll(); static Iterable<String> getStrings(NodeBuilder node, String propertyName); static Iterable<String> getStrings(NodeState node, String propertyName); boolean matchesAll(Set<String> values); boolean matchesPrefix(String prefix); final static ValuePattern MATCH_ALL; }
@Test public void getStringsBuilder() { NodeBuilder b = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); assertNull(ValuePattern.getStrings(b, "x")); b.setProperty("x", ""); assertEquals("[]", ValuePattern.getStrings(b, "x").toString()); b.setProperty("x", "test"); assertEquals("[test]", ValuePattern.getStrings(b, "x").toString()); PropertyState ps = PropertyStates.createProperty( "x", Arrays.asList("hello"), Type.STRINGS); b.setProperty(ps); assertEquals("[hello]", ValuePattern.getStrings(b, "x").toString()); ps = PropertyStates.createProperty( "x", Arrays.asList(), Type.STRINGS); b.setProperty(ps); assertEquals("[]", ValuePattern.getStrings(b, "x").toString()); ps = PropertyStates.createProperty( "x", Arrays.asList("a", "b"), Type.STRINGS); b.setProperty(ps); assertEquals("[a, b]", ValuePattern.getStrings(b, "x").toString()); }
@Test public void getStringsState() { NodeBuilder b = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); assertNull(ValuePattern.getStrings(b.getNodeState(), "x")); b.setProperty("x", ""); assertEquals("[]", ValuePattern.getStrings(b.getNodeState(), "x").toString()); b.setProperty("x", "test"); assertEquals("[test]", ValuePattern.getStrings(b.getNodeState(), "x").toString()); PropertyState ps = PropertyStates.createProperty( "x", Arrays.asList("hello"), Type.STRINGS); b.setProperty(ps); assertEquals("[hello]", ValuePattern.getStrings(b.getNodeState(), "x").toString()); ps = PropertyStates.createProperty( "x", Arrays.asList(), Type.STRINGS); b.setProperty(ps); assertEquals("[]", ValuePattern.getStrings(b.getNodeState(), "x").toString()); ps = PropertyStates.createProperty( "x", Arrays.asList("a", "b"), Type.STRINGS); b.setProperty(ps); assertEquals("[a, b]", ValuePattern.getStrings(b.getNodeState(), "x").toString()); }