@Override protected String createKey() { return Optional.ofNullable(uniqueKeyProviderSupplier.get()) .map(provider -> provider.apply(object)) .orElse(super.createKey()); } };
private void generateTreeData(T item, JsonObject jsonObject) { Optional.ofNullable(getParentItem(item)) .ifPresent(parent -> jsonObject.put("parentUniqueKey", uniqueKeyProviderSupplier.get().apply(parent))); }
/** * 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; }
Locale locale = localeSupplier.get(); assert locale != null;
/** * 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)); } }
private void registerOwnerListener() { assert listenOnSupplier != null; listenOnComponent = listenOnSupplier.get(); if (listenOnComponent == null) { throw new IllegalStateException( String.format("Could register shortcut listener for %s. " + "%s<%s> supplied a null value.", this.toString(), SerializableSupplier.class.getSimpleName(), Component.class.getSimpleName())); } if (!(listenOnComponent instanceof UI)) { listenOnAttachListenerRegistration = new CompoundRegistration(); listenOnAttachListenerRegistration.addRegistration( listenOnComponent.addAttachListener( attachEvent -> updateHandlerListenerRegistration())); listenOnAttachListenerRegistration.addRegistration( listenOnComponent.addDetachListener( detachEvent -> removeListenerRegistration())); } // either the scope is an active UI, or the component is attached to an // active UI - in either case, we want to update dom registration if (listenOnComponent.getUI().isPresent()) { updateHandlerListenerRegistration(); } }
public void setParentRequestedRange(int start, int length, T parentItem) { String parentKey = uniqueKeyProviderSupplier.get().apply(parentItem); HierarchicalCommunicationController<T> controller = dataControllers .computeIfAbsent(parentKey, key -> new HierarchicalCommunicationController<>( parentKey, getKeyMapper(), mapper, dataGenerator, size -> arrayUpdater .startUpdate(getDataProviderSize()), (pkey, range) -> mapper.fetchChildItems( getKeyMapper().get(pkey), range))); controller.setRequestRange(start, length); requestFlush(controller); }