List of usage examples for java.util Objects requireNonNull
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier)
From source file:com.conwet.silbops.model.Advertise.java
/** * Create an attribute entry with the given attribute * @param attribute the new attribute to add, it doesn't insert nulls. * @return the same object to enable chaining. *//*from ww w. j a v a 2 s.c om*/ public Advertise attribute(Attribute attribute) { attributes.add(Objects.requireNonNull(attribute, "Attribute is null")); return this; }
From source file:cloudfoundry.norouter.f5.client.Pool.java
private Pool(Builder builder) { name = Objects.requireNonNull(builder.name, "name is a required parameter"); description = builder.description;/* w w w . j a v a 2 s. co m*/ monitor = builder.monitor; poolMembers = new SubCollection<>(null, builder.poolMembers); reselectTries = builder.reselectTries; }
From source file:com.cloudera.oryx.app.serving.als.model.ALSServingModelManager.java
@Override public void consume(Iterator<KeyMessage<String, String>> updateIterator, Configuration hadoopConf) throws IOException { int countdownToLogModel = 10000; while (updateIterator.hasNext()) { KeyMessage<String, String> km = updateIterator.next(); String key = km.getKey(); String message = km.getMessage(); Objects.requireNonNull(key, "Bad message: " + km); switch (key) { case "UP": if (model == null) { continue; // No model to interpret with yet, so skip it }/*www . ja v a 2 s. c o m*/ List<?> update = MAPPER.readValue(message, List.class); // Update String id = update.get(1).toString(); float[] vector = MAPPER.convertValue(update.get(2), float[].class); switch (update.get(0).toString()) { case "X": model.setUserVector(id, vector); if (update.size() > 3) { @SuppressWarnings("unchecked") Collection<String> knownItems = (Collection<String>) update.get(3); model.addKnownItems(id, knownItems); } break; case "Y": model.setItemVector(id, vector); // Right now, no equivalent knownUsers break; default: throw new IllegalArgumentException("Bad message: " + km); } if (--countdownToLogModel <= 0) { log.info("{}", model); countdownToLogModel = 10000; } break; case "MODEL": case "MODEL-REF": log.info("Loading new model"); PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf); int features = Integer.parseInt(AppPMMLUtils.getExtensionValue(pmml, "features")); boolean implicit = Boolean.valueOf(AppPMMLUtils.getExtensionValue(pmml, "implicit")); if (model == null || features != model.getFeatures()) { log.warn("No previous model, or # features has changed; creating new one"); model = new ALSServingModel(features, implicit, sampleRate, rescorerProvider); } log.info("Updating model"); // Remove users/items no longer in the model Collection<String> XIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "XIDs")); Collection<String> YIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "YIDs")); model.retainRecentAndKnownItems(XIDs, YIDs); model.retainRecentAndUserIDs(XIDs); model.retainRecentAndItemIDs(YIDs); log.info("Model updated: {}", model); break; default: throw new IllegalArgumentException("Bad message: " + km); } } }
From source file:com.codealot.textstore.FileStore.java
@Override public String storeText(final String text) throws IOException { Objects.requireNonNull(text, "No text provided"); if (text.equals("")) { return this.storeText(NO_CONTENT); }// w w w. j a v a 2s . c om // make the digester final MessageDigest digester = getDigester(); // make the hex hash final byte[] textBytes = text.getBytes(StandardCharsets.UTF_8); digester.update(textBytes); final String hash = byteToHex(digester.digest()); // store the text final Path textPath = Paths.get(this.storeRoot, hash); if (!Files.exists(textPath)) { try { Files.write(textPath, textBytes); } catch (IOException e) { // make certain the file is not left on disk Files.deleteIfExists(textPath); // now re-throw the exception throw e; } } return hash; }
From source file:it.reply.orchestrator.dto.deployment.CredentialsAwareSlaPlacementPolicy.java
public void setPassword(String password) { Objects.requireNonNull(password, "password not be null"); this.password = password; }
From source file:de.fosd.jdime.merge.Merge.java
/** * TODO: this needs high-level explanation. * * @param operation//from ww w . j a va 2 s. c o m * @param context * * @throws IOException * @throws InterruptedException */ @Override public final void merge(final MergeOperation<T> operation, final MergeContext context) throws IOException, InterruptedException { logprefix = operation.getId() + " - "; MergeTriple<T> triple = operation.getMergeTriple(); T left = triple.getLeft(); T base = triple.getBase(); T right = triple.getRight(); T target = operation.getTarget(); if (!context.isDiffOnly() && context.isQuiet()) { Objects.requireNonNull(target, "target must not be null!"); } Diff<T> diff = new Diff<>(); Matching<T> m; if (!left.matchingComputed() && !right.matchingComputed()) { if (!base.isEmptyDummy()) { // 3-way merge // diff base left m = diff.compare(base, left, Color.GREEN); if (LOG.isDebugEnabled()) { if (m.getScore() == 0) { LOG.debug(base.getId() + " and " + left.getId() + " have no matches."); } } // diff base right m = diff.compare(base, right, Color.GREEN); if (LOG.isDebugEnabled()) { if (m.getScore() == 0) { LOG.debug(base.getId() + " and " + right.getId() + " have no matches."); } } } // diff left right m = diff.compare(left, right, Color.BLUE); // TODO: compute and write diff stats if (context.isDiffOnly() && left.isRoot() && left instanceof ASTNodeArtifact) { assert (right.isRoot()); return; } if (m.getScore() == 0) { if (LOG.isDebugEnabled()) { LOG.debug(left.getId() + " and " + right.getId() + " have no matches."); } return; } } assert (left.hasMatching(right) && right.hasMatching(left)); if (target != null && target.isRoot() && !target.hasMatches()) { // hack to fix the matches for the merged root node target.cloneMatches(left); } // check if one or both the nodes have no children List<T> leftChildren = left.getChildren(); List<T> rightChildren = right.getChildren(); if (LOG.isTraceEnabled()) { LOG.trace(prefix() + "Children that need to be merged:"); LOG.trace(prefix(left) + "-> (" + leftChildren + ")"); LOG.trace(prefix(right) + "-> (" + rightChildren + ")"); } if ((base.isEmptyDummy() || base.hasChildren()) && (leftChildren.isEmpty() || rightChildren.isEmpty())) { if (leftChildren.isEmpty() && rightChildren.isEmpty()) { if (LOG.isTraceEnabled()) { LOG.trace(prefix(left) + "and [" + right.getId() + "] have no children."); } return; } else if (leftChildren.isEmpty()) { if (LOG.isTraceEnabled()) { LOG.trace(prefix(left) + "has no children."); LOG.trace(prefix(right) + "was deleted by left"); } if (right.hasChanges()) { if (LOG.isTraceEnabled()) { LOG.trace(prefix(right) + "has changes in subtree"); } for (T rightChild : right.getChildren()) { // ConflictOperation<T> conflictOp = new ConflictOperation<>( // rightChild, null, rightChild, target); // conflictOp.apply(context); AddOperation<T> addOp = new AddOperation<>(rightChild, target, false); addOp.apply(context); } return; } else { for (T rightChild : rightChildren) { DeleteOperation<T> delOp = new DeleteOperation<>(rightChild, null); delOp.apply(context); } return; } } else if (rightChildren.isEmpty()) { if (LOG.isTraceEnabled()) { LOG.trace(prefix(right) + "has no children."); LOG.trace(prefix(left) + " was deleted by right"); } if (left.hasChanges()) { if (LOG.isTraceEnabled()) { LOG.trace(prefix(left) + " has changes in subtree"); } for (T leftChild : left.getChildren()) { // ConflictOperation<T> conflictOp = new ConflictOperation<>( // leftChild, leftChild, null, target); // conflictOp.apply(context); DeleteOperation<T> delOp = new DeleteOperation<>(leftChild, target); delOp.apply(context); } return; } else { for (T leftChild : leftChildren) { DeleteOperation<T> delOp = new DeleteOperation<>(leftChild, null); delOp.apply(context); } return; } } else { throw new RuntimeException("Something is very broken."); } } // determine whether we have to respect the order of children boolean isOrdered = false; for (int i = 0; !isOrdered && i < left.getNumChildren(); i++) { if (left.getChild(i).isOrdered()) { isOrdered = true; } } for (int i = 0; !isOrdered && i < right.getNumChildren(); i++) { if (right.getChild(i).isOrdered()) { isOrdered = true; } } if (LOG.isTraceEnabled() && target != null) { LOG.trace(logprefix + "target.dumpTree() before merge:"); System.out.println(target.dumpRootTree()); } if (isOrdered) { if (orderedMerge == null) { orderedMerge = new OrderedMerge<>(); } orderedMerge.merge(operation, context); } else { if (unorderedMerge == null) { unorderedMerge = new UnorderedMerge<>(); } unorderedMerge.merge(operation, context); } return; }
From source file:org.eclipse.rdf4j.http.client.SharedHttpClientSessionManager.java
/** * @param httpClient/*from w ww.j a v a 2s. c o m*/ * The httpClient to use for remote/service calls. */ public void setHttpClient(HttpClient httpClient) { synchronized (this) { this.httpClient = Objects.requireNonNull(httpClient, "HTTP Client cannot be null"); // If they set a client, we need to check whether we need to // close any existing dependentClient CloseableHttpClient toCloseDependentClient = dependentClient; dependentClient = null; if (toCloseDependentClient != null) { HttpClientUtils.closeQuietly(toCloseDependentClient); } } }
From source file:lite.log.intercept.Modifier.java
public T newInstance(Object... initargs) throws ReflectiveOperationException { if (initargs == null) return modifiedClazz.newInstance(); Class<?>[] parameterTypes = new Class[initargs.length]; for (int i = 0; i < parameterTypes.length; i++) { parameterTypes[i] = initargs[i].getClass(); }//from ww w. j av a 2 s .c o m Constructor<T> constructor = ConstructorUtils.getMatchingAccessibleConstructor(modifiedClazz, parameterTypes); Objects.requireNonNull(constructor, modifiedClazz.getSimpleName() + " constructor not found, parameterTypes: " + Arrays.toString(parameterTypes)); return constructor.newInstance(initargs); }
From source file:de.speexx.csv.table.CsvReader.java
void init(final Reader reader) throws IOException { synchronized (this) { Objects.requireNonNull(reader, "reader is null"); this.parser = RFC4180.withFirstRecordAsHeader().parse(reader); this.headerMap = this.parser.getHeaderMap(); this.itr = this.parser.iterator(); final int headerMapSize = this.headerMap.size(); this.descriptors = new ArrayList<>(headerMapSize); for (int i = 0; i < headerMapSize; i++) { for (final Map.Entry<String, Integer> e : this.headerMap.entrySet()) { if (e.getValue() == i) { final EntryDescriptorBuilder edb = new EntryDescriptorBuilder(); edb.addName(e.getKey()); this.descriptors.add(edb.build()); }/* www . j a v a 2 s . c o m*/ } } } }
From source file:com.github.horrorho.inflatabledonkey.data.der.PublicKeyInfo.java
public PublicKeyInfo(int service, int type, byte[] key, Optional<SignatureInfo> signatureInfo, Optional<Signature> signature, Optional<ObjectSignature> extendedSignature) { this.service = service; this.type = type; this.key = Objects.requireNonNull(key, "key"); this.signatureInfo = Objects.requireNonNull(signatureInfo, "signatureInfo"); this.signature = Objects.requireNonNull(signature); this.extendedSignature = Objects.requireNonNull(extendedSignature, "extendedSignature"); }