@Override public Result<M> convertToModel(P value, ValueContext context) { return toModel.apply(value); }
/** * Sets the data provider for this listing. The data provider is queried for * displayed items as needed. * * @param dataProvider * the data provider, not <code>null</code> */ default void setDataProvider(DataProvider<T, F> dataProvider) { setDataProvider(dataProvider, SerializableFunction.identity()); }
/** * Returns the error message for the given value. * * @param value * an invalid value * @return the formatted error message */ protected String getMessage(T value) { return messageProvider.apply(value); }
@Override public P convertToPresentation(M value, ValueContext context) { return toPresentation.apply(value); } };
/** * Creates a new field that uses a property value with the given stateless * converters for producing a model value. * <p> * The property type must be one of the types that can be written as an * element property value: String, Integer, Double or Boolean. * * @param propertyName * the name of the element property to use * @param defaultValue * the default value to use if the property isn't defined * @param elementPropertyType * the type of the element property * @param presentationToModel * a function that converts a property value to a model value * @param modelToPresentation * a function that converts a model value to a property value * @param <P> * the property type */ public <P> AbstractSinglePropertyField(String propertyName, T defaultValue, Class<P> elementPropertyType, SerializableFunction<P, T> presentationToModel, SerializableFunction<T, P> modelToPresentation) { this(propertyName, defaultValue, elementPropertyType, (ignore, value) -> presentationToModel.apply(value), (ignore, value) -> modelToPresentation.apply(value)); }
/** * Gets the minimum date in the date picker. Dates before that will be * disabled in the popup. * * @return the minimum date that is allowed to be selected, or * <code>null</code> if there's no minimum */ public LocalDate getMin() { return PARSER.apply(getMinAsStringString()); }
/** * Date which should be visible when there is no value selected. * <p> * The same date formats as for the {@code value} property are supported. * </p> * * @param initialPosition * the LocalDate value to set */ public void setInitialPosition(LocalDate initialPosition) { setInitialPosition(FORMATTER.apply(initialPosition)); }
@Override @SuppressWarnings("unchecked") public <S> Result<S> flatMap(SerializableFunction<R, Result<S>> mapper) { Objects.requireNonNull(mapper, "mapper cannot be null"); if (isError()) { // Safe cast; valueless return (Result<S>) this; } else { return mapper.apply(value); } }
/** * Get the visible date when there is no value selected. * <p> * The same date formats as for the {@code value} property are supported. * <p> * This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. * </p> * * @return the {@code initialPosition} property from the datepicker */ public LocalDate getInitialPosition() { return PARSER.apply(getInitialPositionString()); }
/** * Sets the minimum date in the date picker. Dates before that will be * disabled in the popup. * * @param min * the minimum date that is allowed to be selected, or * <code>null</code> to remove any minimum constraints */ public void setMin(LocalDate min) { setMinAsString(FORMATTER.apply(min)); }
@Override public <X extends Throwable> R getOrThrow( SerializableFunction<String, ? extends X> exceptionSupplier) throws X { Objects.requireNonNull(exceptionSupplier, "Exception supplier cannot be null"); if (isError()) { throw exceptionSupplier.apply(message); } else { return value; } }
/** * Sets the maximum date in the date picker. Dates after that will be * disabled in the popup. * * @param max * the maximum date that is allowed to be selected, or * <code>null</code> to remove any maximum constraints */ public void setMax(LocalDate max) { setMaxAsString(FORMATTER.apply(max)); }
/** * Gets the maximum date in the date picker. Dates after that will be * disabled in the popup. * * @return the maximum date that is allowed to be selected, or * <code>null</code> if there's no maximum */ public LocalDate getMax() { return PARSER.apply(getMaxAsStringString()); }
/** * Creates a feature of the given type for a node. * * @param nodeFeatureType * the type of the feature to create * @param node * the node for which the feature should be created * @return a newly created feature */ public static NodeFeature create( Class<? extends NodeFeature> nodeFeatureType, StateNode node) { assert node != null; return getData(nodeFeatureType).factory.apply(node); }
/** * Returns a list mappings between chart attributes(keys) and values. For * example: x->1, x->2, y->2, y->3 for linear chart * * @return */ public List<Map<String, Optional<Object>>> getValues() { return dataProvider.fetch(new Query<>()) .map((item) -> chartAttributeToCallback.entrySet().stream() .collect(toMap(Entry::getKey, entry -> (entry.getValue() != null) ? Optional.ofNullable( entry.getValue().apply(item)) : Optional.empty()))) .collect(toList()); }
Collection<T> dependencies = dependencyParser.apply(node);
/** * If this Result has a value, returns a Result of applying the given * function to the value. Otherwise, returns a Result bearing the same error * as this one. Note that any exceptions thrown by the mapping function are * not wrapped but allowed to propagate. * * @param <S> * the type of the mapped value * @param mapper * the mapping function * @return the mapped result */ default <S> Result<S> map(SerializableFunction<R, S> mapper) { return flatMap(value -> ok(mapper.apply(value))); }
/** * Creates a component for a given object model item. Subclasses can * override this method to provide specific behavior. * * @param item * the model item, possibly <code>null</code> * @return a component instance representing the provided item */ public COMPONENT createComponent(SOURCE item) { if (componentFunction != null) { return componentFunction.apply(item); } COMPONENT component = componentSupplier.get(); if (itemConsumer != null) { itemConsumer.accept(component, item); } return component; }
/** * Returns a Result representing the result of invoking the given supplier. * If the supplier returns a value, returns a {@code Result.ok} of the * value; if an exception is thrown, returns the message in a * {@code Result.error}. * * @param <R> * the result value type * @param supplier * the supplier to run * @param onError * the function to provide the error message * @return the result of invoking the supplier */ static <R> Result<R> of(SerializableSupplier<R> supplier, SerializableFunction<Exception, String> onError) { Objects.requireNonNull(supplier, "supplier cannot be null"); Objects.requireNonNull(onError, "onError cannot be null"); try { return ok(supplier.get()); } catch (Exception e) { return error(onError.apply(e)); } }
@Override public Component createComponent(ITEM item) { Component icon = iconGenerator.apply(item); if (icon == null) { throw new IllegalStateException(String.format( "Got 'null' as an icon for the item '%s'. " + "Icon generator instance may not return 'null' values", item)); } String text = itemLabelGenerator.apply(item); if (text == null) { throw new IllegalStateException(String.format( "Got 'null' as a label value for the item '%s'. " + "'%s' instance may not return 'null' values", item, ItemLabelGenerator.class.getSimpleName())); } IconComponent component = new IconComponent(); component.add(icon); component.add(new IconComponent(text)); return component; } }