/** * @param supplier supplier for the property's default value * @param description description of the default value * @return the updated builder instance */ public Builder setDefaultSupplier(Supplier<Object> supplier, String description) { mDefaultSupplier = new DefaultSupplier(supplier, description); return this; }
/** * @param name String of this property */ private PropertyKey(String name) { this(name, null, new DefaultSupplier(() -> null, "null"), null, false, false, ConsistencyCheckLevel.IGNORE, Scope.ALL, DisplayType.DEFAULT, true); }
/** * Creates the property key without registering it with default property list. * * @return the created property key instance */ public PropertyKey buildUnregistered() { DefaultSupplier defaultSupplier = mDefaultSupplier; if (defaultSupplier == null) { String defaultString = String.valueOf(mDefaultValue); defaultSupplier = (mDefaultValue == null) ? new DefaultSupplier(() -> null, "null") : new DefaultSupplier(() -> defaultString, defaultString); } PropertyKey key = new PropertyKey(mName, mDescription, defaultSupplier, mAlias, mIgnoredSiteProperty, mIsHidden, mConsistencyCheckLevel, mScope, mDisplayType, mIsBuiltIn); return key; }
@Test public void getRuntimeDefault() throws Exception { AtomicInteger x = new AtomicInteger(100); PropertyKey key = new PropertyKey.Builder("testKey") .setDefaultSupplier(new DefaultSupplier(() -> x.get(), "finds x")) .build(); assertEquals(100, mConfiguration.getInt(key)); x.set(20); assertEquals(20, mConfiguration.getInt(key)); }
@Test public void defaultSupplier() throws Exception { AtomicInteger x = new AtomicInteger(100); PropertyKey key = new Builder("test") .setDefaultSupplier(new DefaultSupplier(() -> x.get(), "test description")) .build(); assertEquals("100", key.getDefaultValue()); x.set(20); assertEquals("20", key.getDefaultValue()); assertEquals("test description", key.getDefaultSupplier().getDescription()); }
/** * @param name String of this property */ private PropertyKey(String name) { this(name, null, new DefaultSupplier(() -> null, "null"), null, false, false, ConsistencyCheckLevel.IGNORE, Scope.ALL, DisplayType.DEFAULT, true); }
/** * @param supplier supplier for the property's default value * @param description description of the default value * @return the updated builder instance */ public Builder setDefaultSupplier(Supplier<Object> supplier, String description) { mDefaultSupplier = new DefaultSupplier(supplier, description); return this; }
/** * Creates the property key without registering it with default property list. * * @return the created property key instance */ public PropertyKey buildUnregistered() { DefaultSupplier defaultSupplier = mDefaultSupplier; if (defaultSupplier == null) { String defaultString = String.valueOf(mDefaultValue); defaultSupplier = (mDefaultValue == null) ? new DefaultSupplier(() -> null, "null") : new DefaultSupplier(() -> defaultString, defaultString); } PropertyKey key = new PropertyKey(mName, mDescription, defaultSupplier, mAlias, mIgnoredSiteProperty, mIsHidden, mConsistencyCheckLevel, mScope, mDisplayType, mIsBuiltIn); return key; }