@NotNull public static PropertyValue newString(@NotNull Iterable<String> value) { return new PropertyStateValue(MultiStringPropertyState.stringProperty("", value)); }
/** * Create a multi valued {@code PropertyState} from a list of strings. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#STRINGS} */ public static PropertyState stringProperty(String name, Iterable<String> values) { return new MultiStringPropertyState(name, values); }
@Nonnull public static PropertyValue newString(@Nonnull Iterable<String> value) { return new PropertyStateValue(MultiStringPropertyState.stringProperty("", value)); }
/** * Create a multi valued {@code PropertyState} from a list of strings. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#STRINGS} */ public static PropertyState stringProperty(String name, Iterable<String> values) { return new MultiStringPropertyState(name, values); }
private void insert(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, 1); NodeBuilder k = index.child(key); ArrayList<String> list = new ArrayList<String>(); list.add(value); if (k.hasProperty("entry")) { // duplicate key (to detect duplicate entries) // this is just set temporarily, // while trying to add a duplicate entry PropertyState s = k.getProperty("entry"); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!list.contains(r)) { list.add(r); } } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); k.setProperty(s2); insertCallback.accept(k); }
parent.child("child-moved").setProperty("foo", "value"); parent.child("child-moved").setProperty( new MultiStringPropertyState("bar", Arrays.asList("value"))); store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY); parent = root.child("parent"); parent.setProperty("foo", "value"); parent.setProperty(new MultiStringPropertyState( "bar", Arrays.asList("value"))); store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
private void insert(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, 1); NodeBuilder k = index.child(key); ArrayList<String> list = new ArrayList<String>(); list.add(value); if (k.hasProperty("entry")) { // duplicate key (to detect duplicate entries) // this is just set temporarily, // while trying to add a duplicate entry PropertyState s = k.getProperty("entry"); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!list.contains(r)) { list.add(r); } } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); k.setProperty(s2); insertCallback.accept(k); }
private void insert(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, 1); NodeBuilder k = index.child(key); ArrayList<String> list = new ArrayList<String>(); list.add(value); if (k.hasProperty("entry")) { // duplicate key (to detect duplicate entries) // this is just set temporarily, // while trying to add a duplicate entry PropertyState s = k.getProperty("entry"); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!list.contains(r)) { list.add(r); } } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); k.setProperty(s2); insertCallback.accept(k); }
strings.add(getString(value, type)); return MultiStringPropertyState.stringProperty(name, strings); case PropertyType.BINARY: List<Blob> blobs = Lists.newArrayList();
strings.add(getString(value, type)); return MultiStringPropertyState.stringProperty(name, strings); case PropertyType.BINARY: List<Blob> blobs = Lists.newArrayList();
private static void remove(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, -1); NodeBuilder builder = index.getChildNode(key); if (builder.exists()) { // there could be (temporarily) multiple entries // we need to remove the right one PropertyState s = builder.getProperty("entry"); if (s.count() == 1) { builder.remove(); } else { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!r.equals(value)) { list.add(r); } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); builder.setProperty(s2); } } }
private static void remove(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, -1); NodeBuilder builder = index.getChildNode(key); if (builder.exists()) { // there could be (temporarily) multiple entries // we need to remove the right one PropertyState s = builder.getProperty("entry"); if (s.count() == 1) { builder.remove(); } else { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!r.equals(value)) { list.add(r); } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); builder.setProperty(s2); } } }
private static void remove(NodeBuilder index, String key, String value) { ApproximateCounter.adjustCountSync(index, -1); NodeBuilder builder = index.getChildNode(key); if (builder.exists()) { // there could be (temporarily) multiple entries // we need to remove the right one PropertyState s = builder.getProperty("entry"); if (s.count() == 1) { builder.remove(); } else { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < s.count(); i++) { String r = s.getValue(Type.STRING, i); if (!r.equals(value)) { list.add(r); } } PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list); builder.setProperty(s2); } } }
@Test public void testAssignFromStrings() { PropertyState source = MultiStringPropertyState.stringProperty("foo", Arrays.asList("1", "2", "3")); PropertyBuilder builder = PropertyBuilder.scalar(Type.LONG); builder.assignFrom(source); assertEquals(MultiLongPropertyState.createLongProperty("foo", Arrays.asList(1L, 2L, 3L)), builder.getPropertyState()); }
@Test public void testAssignFromLongs() { PropertyState source = MultiLongPropertyState.createLongProperty("foo", Arrays.asList(1L, 2L, 3L)); PropertyBuilder builder = PropertyBuilder.scalar(Type.STRING); builder.assignFrom(source); assertEquals(MultiStringPropertyState.stringProperty("foo", Arrays.asList("1", "2", "3")), builder.getPropertyState()); }
@Test public void testAssignInvariant() { PropertyState source = MultiStringPropertyState.stringProperty("source", Arrays.asList("1", "2", "3")); PropertyBuilder builder = PropertyBuilder.scalar(Type.STRING); builder.assignFrom(source); assertEquals(source, builder.getPropertyState()); }
switch (type.tag()) { case PropertyType.STRING: return MultiStringPropertyState.stringProperty(name, (Iterable<String>) values); case PropertyType.BINARY: return MultiBinaryPropertyState.binaryPropertyFromBlob(name, (Iterable<Blob>) values);
switch (type.tag()) { case PropertyType.STRING: return MultiStringPropertyState.stringProperty(name, (Iterable<String>) values); case PropertyType.BINARY: return MultiBinaryPropertyState.binaryPropertyFromBlob(name, (Iterable<Blob>) values);
@Test public void testStringProperty() { PropertyBuilder builder = PropertyBuilder.scalar(Type.STRING); builder.setName("foo").setValue("bar"); Assert.assertEquals(StringPropertyState.stringProperty("foo", "bar"), builder.getPropertyState()); builder.setArray(); Assert.assertEquals(MultiStringPropertyState.stringProperty("foo", Arrays.asList("bar")), builder.getPropertyState()); }
@Test public void testStringsProperty() { PropertyBuilder builder = PropertyBuilder.array(Type.STRING); builder.setName("foo") .addValue("one") .addValue("two"); assertEquals(MultiStringPropertyState.stringProperty("foo", Arrays.asList("one", "two")), builder.getPropertyState()); builder.setScalar(); try { builder.getPropertyState(); } catch (IllegalStateException expected) { // success } builder.removeValue("one"); assertEquals(StringPropertyState.stringProperty("foo", "two"), builder.getPropertyState()); }