@CheckForNull public String resolveUUID(String uuid) { return resolveUUID(StringPropertyState.stringProperty("", uuid)); }
@Nullable public String resolveUUID(String uuid) { return resolveUUID(StringPropertyState.stringProperty("", uuid)); }
@Nonnull public static PropertyValue newString(@Nonnull String value) { return new PropertyStateValue(StringPropertyState.stringProperty("", value)); }
@NotNull public static PropertyValue newString(@NotNull String value) { return new PropertyStateValue(StringPropertyState.stringProperty("", value)); }
@Nullable public String resolveUUID(String uuid) { return resolveUUID(StringPropertyState.stringProperty("", uuid)); }
@Override public Value createValue(String value) { return newValue(StringPropertyState.stringProperty("", value), namePathMapper); }
@NotNull public Value createValue(@NotNull String value) { return newValue(StringPropertyState.stringProperty("", value), namePathMapper, getBlobAccessProvider()); }
public static <T> PropertyState createProperty(String name, T value) { if (value instanceof String) { return StringPropertyState.stringProperty(name, (String) value); } else if (value instanceof Blob) { return BinaryPropertyState.binaryProperty(name, (Blob) value);
public static <T> PropertyState createProperty(String name, T value) { if (value instanceof String) { return StringPropertyState.stringProperty(name, (String) value); } else if (value instanceof Blob) { return BinaryPropertyState.binaryProperty(name, (Blob) value);
@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 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()); }
/** * Create a {@code PropertyState} based on a {@link Value}. The * {@link Type} of the property state is determined by the * type of the value. * @param name The name of the property state * @param value The value of the property state * @return The new property state * @throws RepositoryException forwarded from {@code value} */ @NotNull public static PropertyState createProperty(String name, Value value) throws RepositoryException { int type = value.getType(); switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, getString(value, type)); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, value); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, value.getLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, value.getDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, value.getBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, value.getDecimal()); default: return new GenericPropertyState(name, getString(value, type), Type.fromTag(type, false)); } }
/** * Create a {@code PropertyState} based on a {@link Value}. The * {@link Type} of the property state is determined by the * type of the value. * @param name The name of the property state * @param value The value of the property state * @return The new property state * @throws RepositoryException forwarded from {@code value} */ @Nonnull public static PropertyState createProperty(String name, Value value) throws RepositoryException { int type = value.getType(); switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, getString(value, type)); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, value); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, value.getLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, value.getDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, value.getBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, value.getDecimal()); default: return new GenericPropertyState(name, getString(value, type), Type.fromTag(type, false)); } }
@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()); }
/** * Create a {@code PropertyState} from a string. * @param name The name of the property state * @param value The value of the property state * @param type The type of the property state * @return The new property state */ @Nonnull public static PropertyState createProperty(String name, String value, int type) { switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, value); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, Conversions.convert(value).toBinary()); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, Conversions.convert(value).toLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, Conversions.convert(value).toDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, Conversions.convert(value).toBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, Conversions.convert(value).toDecimal()); default: return new GenericPropertyState(name, value, Type.fromTag(type, false)); } }
/** * Create a {@code PropertyState} from a string. * @param name The name of the property state * @param value The value of the property state * @param type The type of the property state * @return The new property state */ @NotNull public static PropertyState createProperty(String name, String value, int type) { switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, value); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, Conversions.convert(value).toBinary()); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, Conversions.convert(value).toLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, Conversions.convert(value).toDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, Conversions.convert(value).toBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, Conversions.convert(value).toDecimal()); default: return new GenericPropertyState(name, value, Type.fromTag(type, false)); } }
@Test public void testPropertyChanges() { JsopDiff diff; PropertyState before = StringPropertyState.stringProperty("foo", "bar"); diff = new JsopDiff(); diff.propertyAdded(before); assertEquals("^\"/foo\":\"bar\"", diff.toString()); diff = new JsopDiff(); diff.propertyChanged(before, LongPropertyState.createLongProperty("foo", 123L)); assertEquals("^\"/foo\":123", diff.toString()); diff = new JsopDiff(); diff.propertyChanged(before, DoublePropertyState.doubleProperty("foo", 1.23)); assertEquals("^\"/foo\":1.23", diff.toString()); diff = new JsopDiff(); diff.propertyChanged(before, BooleanPropertyState.booleanProperty("foo", true)); assertEquals("^\"/foo\":true", diff.toString()); diff = new JsopDiff(); diff.propertyDeleted(before); assertEquals("^\"/foo\":null", diff.toString()); }
@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()); }
return StringPropertyState.stringProperty(name, jsonString);