@NotNull public static PropertyValue newLong(@NotNull Long value) { return new PropertyStateValue(LongPropertyState.createLongProperty("", value)); }
/** * Create a {@code PropertyState} from a long. * @param name The name of the property state * @param value The value of the property state * @return The new property state of type {@link Type#LONG} */ public static PropertyState createLongProperty( @NotNull String name, long value) { return new LongPropertyState(name, value); }
@Override public Value createValue(long value) { return newValue(LongPropertyState.createLongProperty("", value), namePathMapper); }
/** * Create a {@code PropertyState} from a long. * @param name The name of the property state * @param value The value of the property state * @return The new property state of type {@link Type#LONG} */ public static PropertyState createLongProperty( @Nonnull String name, long value) { return new LongPropertyState(name, value); }
@Nonnull public static PropertyValue newLong(@Nonnull Long value) { return new PropertyStateValue(LongPropertyState.createLongProperty("", value)); }
String number = reader.getToken(); try { return new LongPropertyState(name, Long.parseLong(number)); } catch (NumberFormatException e) { return new DoublePropertyState(name, Double.parseDouble(number));
@NotNull public Value createValue(long value) { return newValue(LongPropertyState.createLongProperty("", value), namePathMapper, getBlobAccessProvider()); }
String number = reader.getToken(); try { return new LongPropertyState(name, Long.parseLong(number)); } catch (NumberFormatException e) { return new DoublePropertyState(name, Double.parseDouble(number));
/** * check whether the provided builder has to be consolidated or not. A node has to be * consolidate if the sum of all the hidden counter does not match the exposed one. It could * happen that some other nodes previously saw our change and already consolidated it. * * @param b the builde to check. Canno be null. * @return true if the sum of the hidden counters does not match the exposed one. */ static boolean isConsolidate(@NotNull NodeBuilder b) { checkNotNull(b); PropertyState counter = b.getProperty(PROP_COUNTER); if (counter == null) { counter = LongPropertyState.createLongProperty(PROP_COUNTER, 0); } long hiddensum = 0; for (PropertyState p : b.getProperties()) { if (p.getName().startsWith(PREFIX_PROP_COUNTER)) { hiddensum += p.getValue(LONG).longValue(); } } return counter.getValue(LONG).longValue() != hiddensum; }
String number = reader.getToken(); try { return new LongPropertyState(name, Long.parseLong(number)); } catch (NumberFormatException e) { return new DoublePropertyState(name, Double.parseDouble(number));
/** * check whether the provided builder has to be consolidated or not. A node has to be * consolidate if the sum of all the hidden counter does not match the exposed one. It could * happen that some other nodes previously saw our change and already consolidated it. * * @param b the builde to check. Canno be null. * @return true if the sum of the hidden counters does not match the exposed one. */ static boolean isConsolidate(@NotNull NodeBuilder b) { checkNotNull(b); PropertyState counter = b.getProperty(PROP_COUNTER); if (counter == null) { counter = LongPropertyState.createLongProperty(PROP_COUNTER, 0); } long hiddensum = 0; for (PropertyState p : b.getProperties()) { if (p.getName().startsWith(PREFIX_PROP_COUNTER)) { hiddensum += p.getValue(LONG).longValue(); } } return counter.getValue(LONG).longValue() != hiddensum; }
String number = reader.getToken(); try { return new LongPropertyState(name, Long.parseLong(number)); } catch (NumberFormatException e) { return new DoublePropertyState(name, Double.parseDouble(number));
/** * check whether the provided builder has to be consolidated or not. A node has to be * consolidate if the sum of all the hidden counter does not match the exposed one. It could * happen that some other nodes previously saw our change and already consolidated it. * * @param b the builde to check. Canno be null. * @return true if the sum of the hidden counters does not match the exposed one. */ static boolean isConsolidate(@Nonnull NodeBuilder b) { checkNotNull(b); PropertyState counter = b.getProperty(PROP_COUNTER); if (counter == null) { counter = LongPropertyState.createLongProperty(PROP_COUNTER, 0); } long hiddensum = 0; for (PropertyState p : b.getProperties()) { if (p.getName().startsWith(PREFIX_PROP_COUNTER)) { hiddensum += p.getValue(LONG).longValue(); } } return counter.getValue(LONG).longValue() != hiddensum; }
return BinaryPropertyState.binaryProperty(name, (byte[]) value); } else if (value instanceof Long) { return LongPropertyState.createLongProperty(name, (Long) value); } else if (value instanceof Integer) { return LongPropertyState.createLongProperty(name, (long) (Integer) value); } else if (value instanceof Double) { return DoublePropertyState.doubleProperty(name, (Double) value);
return BinaryPropertyState.binaryProperty(name, (byte[]) value); } else if (value instanceof Long) { return LongPropertyState.createLongProperty(name, (Long) value); } else if (value instanceof Integer) { return LongPropertyState.createLongProperty(name, (long) (Integer) value); } else if (value instanceof Double) { return DoublePropertyState.doubleProperty(name, (Double) value);
@Test public void getProperties() { Tree tree = root.getTree("/"); Set<PropertyState> expectedProperties = Sets.newHashSet( LongPropertyState.createLongProperty("a", 1L), LongPropertyState.createLongProperty("b", 2L), LongPropertyState.createLongProperty("c", 3L)); Iterable<? extends PropertyState> properties = tree.getProperties(); for (PropertyState property : properties) { assertTrue(expectedProperties.remove(property)); } assertTrue(expectedProperties.isEmpty()); assertEquals(3, tree.getPropertyCount()); }
counter = LongPropertyState.createLongProperty(PROP_COUNTER, 0); hidden1 = LongPropertyState.createLongProperty(hidden1Name, 1); b.setProperty(counter); b.setProperty(hidden1); assertTrue(AtomicCounterEditor.isConsolidate(b)); counter = LongPropertyState.createLongProperty(PROP_COUNTER, 1); hidden1 = LongPropertyState.createLongProperty(hidden1Name, 1); hidden2 = LongPropertyState.createLongProperty(hidden2Name, 1); b.setProperty(counter); b.setProperty(hidden1); assertTrue(AtomicCounterEditor.isConsolidate(b)); counter = LongPropertyState.createLongProperty(PROP_COUNTER, 2); hidden1 = LongPropertyState.createLongProperty(hidden1Name, 1); hidden2 = LongPropertyState.createLongProperty(hidden2Name, 1); b.setProperty(counter); b.setProperty(hidden1);
return BinaryPropertyState.binaryProperty(name, (Blob) value); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, (Long) value); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, (Double) value);
@Test public void checkRevision() { NodeBuilder b = EMPTY_NODE.builder(); PropertyState r = LongPropertyState.createLongProperty("r", 10L); assertTrue(AtomicCounterEditor.checkRevision(b, null)); assertFalse(AtomicCounterEditor.checkRevision(b, r)); b.setProperty(LongPropertyState.createLongProperty(r.getName(), 1L)); assertFalse(AtomicCounterEditor.checkRevision(b, r)); b.setProperty(LongPropertyState.createLongProperty(r.getName(), 10L)); assertTrue(AtomicCounterEditor.checkRevision(b, r)); b.setProperty(LongPropertyState.createLongProperty(r.getName(), 20L)); assertTrue(AtomicCounterEditor.checkRevision(b, r)); }
return BinaryPropertyState.binaryProperty(name, (Blob) value); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, (Long) value); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, (Double) value);