List of usage examples for java.util Objects requireNonNull
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier)
From source file:Main.java
/** * Transform the source collection using the mapping function to convert the elements to the output type. The result * is written to a list.//from w w w. ja va 2 s . c om * * @param <T> * the source type type * @param <R> * the result type * @param source * the source * @param mapping * the mapping used for the value transformation * @return the list */ public static <T, R> List<R> transformToList(Collection<T> source, Function<T, R> mapping) { Objects.requireNonNull(mapping, "Mapping functions is required!"); if (isEmpty(source)) { return new LinkedList<>(); } List<R> result = new LinkedList<>(); for (T item : source) { result.add(mapping.apply(item)); } return result; }
From source file:Main.java
public static Element addChildElement(Node parent, String elementName) { Document ownerDocument = parent.getOwnerDocument(); Objects.requireNonNull(ownerDocument, "nodes ownerDocument " + parent); Element element = ownerDocument.createElement(elementName); parent.appendChild(element);/* ww w . ja v a 2 s. c o m*/ return element; }
From source file:me.ferrybig.javacoding.webmapper.util.JsonArrayCollection.java
public JsonArrayCollection(JSONArray arr) { this.arr = Objects.requireNonNull(arr, "arr == null"); }
From source file:edu.usu.sdl.openstorefront.core.util.EntityUtil.java
/** * This will set default on the fields that are marked with a default and * are null// w w w . j ava 2 s .c o m * * @param entity */ public static void setDefaultsOnFields(Object entity) { Objects.requireNonNull(entity, "Entity must not be NULL"); List<Field> fields = getAllFields(entity.getClass()); for (Field field : fields) { DefaultFieldValue defaultFieldValue = field.getAnnotation(DefaultFieldValue.class); if (defaultFieldValue != null) { field.setAccessible(true); try { if (field.get(entity) == null) { String value = defaultFieldValue.value(); Class fieldClass = field.getType(); if (fieldClass.getSimpleName().equalsIgnoreCase(String.class.getSimpleName())) { field.set(entity, value); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Long.class.getSimpleName())) { field.set(entity, value); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Integer.class.getSimpleName())) { field.set(entity, Integer.parseInt(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Boolean.class.getSimpleName())) { field.set(entity, Convert.toBoolean(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Double.class.getSimpleName())) { field.set(entity, Double.parseDouble(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Float.class.getSimpleName())) { field.set(entity, Float.parseFloat(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigDecimal.class.getSimpleName())) { field.set(entity, Convert.toBigDecimal(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(Date.class.getSimpleName())) { field.set(entity, TimeUtil.fromString(value)); } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigInteger.class.getSimpleName())) { field.set(entity, new BigInteger(value)); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new OpenStorefrontRuntimeException( "Unable to get value on " + entity.getClass().getName(), "Check entity passed in."); } } } }
From source file:com.conwet.silbops.model.basic.Type.java
/** * Deserialize from a JSON representation * /*from w ww . j av a 2 s . co m*/ * @param json JSON representation * @return A new value type * @throws IllegalArgumentException if the given string doesn't match any type. */ public static Type fromJSON(String json) { return Objects.requireNonNull(JSON_MAP.get(json), "Malformed object: " + json); }
From source file:Main.java
/** * Converts the given iterator to collection created via the provided {@link Supplier}. * <p>/*from w w w.j av a 2 s . co m*/ * Example use: <code>List<String> list = CollectionUtils.toCollection(iterator, LinkedList::new);</code> * * @param <T> * the generic type * @param <C> * the generic type * @param iterator * the iterator * @param newInstance * the new instance * @return the c */ public static <T, C extends Collection<T>> C toCollection(Iterator<T> iterator, Supplier<C> newInstance) { Objects.requireNonNull(iterator, "The iterator is required"); Objects.requireNonNull(newInstance, "New Instance supplier is required"); C list = newInstance.get(); iterator.forEachRemaining(list::add); return list; }
From source file:io.apiman.gateway.platforms.vertx3.api.auth.KeycloakOAuthFactory.java
public static AuthHandler create(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject authConfig) {//from www .j a va 2 s. c o m OAuth2FlowType flowType = toEnum(authConfig.getString("flowType")); String role = authConfig.getString("requiredRole"); Objects.requireNonNull(flowType, String.format("flowType must be specified and valid. Flows: %s.", Arrays.asList(OAuth2FlowType.values()))); Objects.requireNonNull(role, "requiredRole must be non-null."); if (flowType != OAuth2FlowType.AUTH_CODE) { return directGrant(vertx, apimanConfig, authConfig, flowType, role); } else { return standardAuth(vertx, router, apimanConfig, authConfig, flowType); } }
From source file:kishida.cnn.layers.ImageNeuralLayer.java
public void setPreLayer(NeuralLayer preLayer) { Objects.requireNonNull(preLayer, "need preLayer"); if (!(preLayer instanceof ImageNeuralLayer)) { throw new IllegalArgumentException("Need ImageNeuralLayer instead of " + preLayer.getClass()); }//from www . ja v a 2s .c o m this.preLayer = preLayer; ImageNeuralLayer imageLayer = (ImageNeuralLayer) preLayer; this.inputChannels = imageLayer.outputChannels; this.inputWidth = imageLayer.outputWidth; this.inputHeight = imageLayer.outputHeight; }
From source file:com.fizzed.blaze.util.Streamables.java
static public StreamableInput input(InputStream stream, String name) { Objects.requireNonNull(stream, "stream cannot be null"); return new StreamableInput(stream, (name != null ? name : "<stream"), null, null); }
From source file:cn.edu.zjnu.acm.judge.config.FilterLocaleResolver.java
public FilterLocaleResolver(LocaleResolver parent, Locale defaultLocale, Predicate<Locale> predicate) { this.parent = Objects.requireNonNull(parent, "parent"); this.defaultLocale = Objects.requireNonNull(defaultLocale, "defaultLocale"); this.predicate = Objects.requireNonNull(predicate, "predicate"); }