/** * Create a new instance for building scalar {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the * given {@code name}. * Equivalent to * <pre> * MemoryPropertyBuilder.create(type).setName(name); * </pre> * @param type type of the {@code PropertyState} instances to be built. * @param name initial name * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> scalar(Type<T> type, String name) { return scalar(type).setName(name); }
/** * Create a new instance for building scalar {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the * given {@code name}. * Equivalent to * <pre> * MemoryPropertyBuilder.create(type).setName(name); * </pre> * @param type type of the {@code PropertyState} instances to be built. * @param name initial name * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> scalar(Type<T> type, String name) { return scalar(type).setName(name); }
/** * Create a new instance for building {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the name and * the values of {@code property}. * Equivalent to * <pre> * PropertyBuilder.scalar(type).assignFrom(property); * </pre> * * @param type type of the {@code PropertyState} instances to be built. * @param property initial name and values * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> copy(Type<T> type, PropertyState property) { return scalar(type).assignFrom(property); }
/** * Create a new instance for building {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the name and * the values of {@code property}. * Equivalent to * <pre> * PropertyBuilder.scalar(type).assignFrom(property); * </pre> * * @param type type of the {@code PropertyState} instances to be built. * @param property initial name and values * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> copy(Type<T> type, PropertyState property) { return scalar(type).assignFrom(property); }
/** * Create a new instance for building array {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the * given {@code name}. * Equivalent to * <pre> * MemoryPropertyBuilder.create(type).setName(name).setArray(); * </pre> * @param type type of the {@code PropertyState} instances to be built. * @param name initial name * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> array(Type<T> type, String name) { return scalar(type).setName(name).setArray(); }
/** * Create a new instance for building array {@code PropertyState} instances * of the given {@code type}. The builder is initialised with the * given {@code name}. * Equivalent to * <pre> * MemoryPropertyBuilder.create(type).setName(name).setArray(); * </pre> * @param type type of the {@code PropertyState} instances to be built. * @param name initial name * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> array(Type<T> type, String name) { return scalar(type).setName(name).setArray(); }
@Test(expected = NumberFormatException.class) public void testAssignFromStringNumberFormatException() { PropertyState source = StringPropertyState.stringProperty("foo", "bar"); PropertyBuilder builder = PropertyBuilder.scalar(Type.LONG); builder.assignFrom(source); }
@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 testAssignFromDates() { String date1 = "1970-01-01T00:00:00.000Z"; String date2 = "1971-01-01T00:00:00.000Z"; PropertyState source = MultiGenericPropertyState.dateProperty("foo", Arrays.asList(date1, date2)); PropertyBuilder builder = PropertyBuilder.scalar(Type.DATE); builder.assignFrom(source); assertEquals(source, 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()); }
@Test public void testAssignFromDate() { String date = "1970-01-01T00:00:00.000Z"; PropertyState source = GenericPropertyState.dateProperty("foo", date); PropertyBuilder builder = PropertyBuilder.scalar(Type.DATE); builder.assignFrom(source); assertEquals(source, builder.getPropertyState()); }
@Test public void testAssignFromString() { PropertyState source = StringPropertyState.stringProperty("foo", "42"); PropertyBuilder builder = PropertyBuilder.scalar(Type.LONG); builder.assignFrom(source); assertEquals(LongPropertyState.createLongProperty("foo", 42L), builder.getPropertyState()); }
@Test public void testAssignFromLong() { PropertyState source = LongPropertyState.createLongProperty("foo", 42L); PropertyBuilder builder = PropertyBuilder.scalar(Type.STRING); builder.assignFrom(source); assertEquals(StringPropertyState.stringProperty("foo", "42"), builder.getPropertyState()); }
@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 testLongProperty() { PropertyBuilder builder = PropertyBuilder.scalar(Type.LONG); builder.setName("foo").setValue(42L); Assert.assertEquals(LongPropertyState.createLongProperty("foo", 42L), builder.getPropertyState()); builder.setArray(); Assert.assertEquals(MultiLongPropertyState.createLongProperty("foo", Arrays.asList(42L)), builder.getPropertyState()); }
@Test public void testCreateHiddenProperty3() { Tree a = root.getTree("/a"); try { PropertyState propertyState = PropertyBuilder.scalar(STRING) .setName(":hiddenProperty") .setValue("val") .getPropertyState(); a.setProperty(propertyState); root.commit(); fail(); } catch (Exception e) { // success } } }