@Nullable private static String getStringInternal(@NotNull Tree tree, @NotNull String propertyName, @NotNull Type<String> type) { PropertyState property = tree.getProperty(propertyName); if (property != null && !property.isArray()) { return property.getValue(type); } else { return null; } }
public static long getLong(@NotNull Tree tree, @NotNull String name, long defaultValue) { PropertyState property = tree.getProperty(name); if (property != null && !property.isArray()) { return property.getValue(LONG); } else { return defaultValue; } }
private Map<String, String> collectProperties(NodeState node) { Map<String, String> properties = Maps.newHashMap(); for (String name : propertyNames) { PropertyState p = node.getProperty(name); if (p != null && !p.isArray()) { properties.put(name, p.getValue(Type.STRING)); } } return properties; }
private Object createValue(PropertyState property) { if (property.isArray()) { List<Value> values = valueFactory.createValues(property); return values.toArray(new Value[values.size()]); } else { return valueFactory.createValue(property); } }
@Nonnull public PropertyState getSingleState() throws InvalidItemStateException, ValueFormatException { PropertyState p = getPropertyState(); if (p.isArray()) { throw new ValueFormatException(p + " is multi-valued."); } return p; }
@NotNull public PropertyState getSingleState() throws InvalidItemStateException, ValueFormatException { PropertyState p = getPropertyState(); if (p.isArray()) { throw new ValueFormatException(p + " is multi-valued."); } return p; }
public void render(PropertyState property, HttpServletResponse response) throws IOException { PrintWriter writer = startResponse(response); if (property.isArray()) { for (String value : property.getValue(Type.STRINGS)) { writer.print(value); writer.print('\n'); } } else { writer.print(property.getValue(STRING)); } }
private Iterable<String> getStringValuesFor(String propertyName) { Iterable<String> values = null; PropertyState property = definition.getProperty(propertyName); if (property != null && property.isArray()) { values = property.getValue(Type.STRINGS); } return values; }
public static boolean isIndexNodeType(NodeState state, String typeIn) { if (!isIndexNodeType(state)) { return false; } PropertyState type = state.getProperty(TYPE_PROPERTY_NAME); return type != null && !type.isArray() && type.getValue(Type.STRING).equals(typeIn); }
public static Iterable<String> getStrings(NodeState node, String propertyName) { if (!node.hasProperty(propertyName)) { return null; } PropertyState s = node.getProperty(propertyName); if (s.isArray()) { return node.getStrings(propertyName); } return Collections.singleton(node.getString(propertyName)); }
public static Iterable<String> getStrings(NodeState node, String propertyName) { if (!node.hasProperty(propertyName)) { return null; } PropertyState s = node.getProperty(propertyName); if (s.isArray()) { return node.getStrings(propertyName); } return Collections.singleton(node.getString(propertyName)); }
private static PropertyState clone(String newName, PropertyState currentAsyncState) { PropertyState clonedState; if (currentAsyncState.isArray()) { clonedState = PropertyStates.createProperty(newName, currentAsyncState.getValue(Type.STRINGS), Type.STRINGS); } else { clonedState = PropertyStates.createProperty(newName, currentAsyncState.getValue(Type.STRING), Type.STRING); } return clonedState; } }
public long getLong(String name, long defaultValue) { PropertyState property = tree.getProperty(name); if (property != null && !property.isArray()) { return property.getValue(LONG); } else { return defaultValue; } }
private void assertPropertyOnTheNewStore(PropertyState property) throws IOException { if (property.isArray()) { for (Blob blob : property.getValue(Type.BINARIES)) { assertPropertyOnTheNewStore(blob); } } else { assertPropertyOnTheNewStore(property.getValue(Type.BINARY)); } }
@Test public void testAsPropertyStateSingleList() throws Exception { PropInfo propInfo = new PropInfo("strings", PropertyType.STRING, ImmutableList.of(mockTextValue("a", PropertyType.STRING)), PropInfo.MultipleStatus.MULTIPLE); PropertyState ps = propInfo.asPropertyState(mockPropDef(PropertyType.STRING, true)); assertTrue(ps.isArray()); assertEquals(1, ps.count()); }
private void assertPropertyExists(PropertyState property) { if (property.isArray()) { for (Blob blob : property.getValue(Type.BINARIES)) { assertEquals(LENGTH, blob.length()); } } else { assertEquals(LENGTH, property.getValue(Type.BINARY).length()); } }
@Test public void testAsPropertyStateMultiples() throws Exception { PropInfo propInfo = new PropInfo("strings", PropertyType.STRING, ImmutableList.of(mockTextValue("a", PropertyType.STRING), mockTextValue("b", PropertyType.STRING))); PropertyState ps = propInfo.asPropertyState(mockPropDef(PropertyType.STRING, true)); assertTrue(ps.isArray()); assertEquals(2, ps.count()); }
@Test public void testCreateMvRestriction2() throws Exception { Restriction r = restrictionProvider.createRestriction(testPath, REP_NT_NAMES, nameValues); assertNotNull(r); assertEquals(REP_NT_NAMES, r.getDefinition().getName()); assertEquals(Type.NAMES, r.getDefinition().getRequiredType()); PropertyState ps = r.getProperty(); assertTrue(ps.isArray()); assertEquals(Type.NAMES, ps.getType()); List<Value> vs = valueFactory.createValues(ps); assertArrayEquals(nameValues, vs.toArray(new Value[0])); }
@Test public void getProperty() { Tree tree = root.getTree("/"); PropertyState propertyState = tree.getProperty("any"); assertNull(propertyState); propertyState = tree.getProperty("a"); assertNotNull(propertyState); assertFalse(propertyState.isArray()); assertEquals(LONG, propertyState.getType()); assertEquals(1, (long) propertyState.getValue(LONG)); }
@Test public void testCreateEmptyMvRestriction() throws Exception { Restriction r = restrictionProvider.createRestriction(testPath, REP_NT_NAMES); assertNotNull(r); assertEquals(REP_NT_NAMES, r.getDefinition().getName()); assertEquals(Type.NAMES, r.getDefinition().getRequiredType()); assertTrue(r.getProperty().isArray()); assertEquals(Type.NAMES, r.getProperty().getType()); List<Value> vs = valueFactory.createValues(r.getProperty()); assertNotNull(vs); assertEquals(0, vs.size()); }