List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl.java
@Override public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, ToscaServiceModel toscaServiceModel) { Map<String, NodeTemplate> nodeTemplates = new HashMap<>(); if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils.isNotEmpty(serviceTemplate.getTopology_template().getNode_templates())) { for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template() .getNode_templates().entrySet()) { if (isTypeOf(nodeTemplateEntry.getValue(), nodeType, serviceTemplate, toscaServiceModel)) { nodeTemplates.put(nodeTemplateEntry.getKey(), nodeTemplateEntry.getValue()); }/*from w w w . j a va 2s . c o m*/ } } return nodeTemplates; }
From source file:org.opentestsystem.ap.ivs.service.ValidationUtility.java
public Path mapStimulusToValidationStructure(ItemContext stimulusContext, Path validationRootChild) { return Objects.nonNull(stimulusContext) ? mapToValidationStructure(stimulusContext, validationRootChild.resolve(STIMULI_DIR), mapStimFolderName(stimulusContext.getItemId())) : null;//from w w w . ja va2 s.co m }
From source file:com.github.yongchristophertang.engine.web.response.JsonResultTransformer.java
/** * Transform the json result to an instance of T. * * @param clazz the type class of transformed object *//* ww w . java 2 s. c o m*/ public <T> ResultTransform<T> object(Class<T> clazz) { return result -> { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); try { return expression == null ? mapper.readValue(result.getResponseStringContent(), clazz) : mapper.readValue( JsonPath.compile(expression).read(result.getResponseStringContent()).toString(), clazz); } catch (JsonParseException e) { Objects.nonNull(expression); return clazz.cast(JsonPath.compile(expression).read(result.getResponseStringContent())); } }; }
From source file:org.jnosql.diana.orientdb.document.OrientDBDocumentCollectionManager.java
@Override public DocumentEntity insert(DocumentEntity entity) throws NullPointerException { Objects.toString(entity, "Entity is required"); try (ODatabaseDocumentTx tx = pool.acquire()) { ODocument document = new ODocument(entity.getName()); Map<String, Object> entityValues = toMap(entity); entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k))); ODocument save = null;/*from www . j a v a 2 s . com*/ try { save = tx.save(document); } catch (ONeedRetryException e) { save = tx.reload(document); } if (Objects.nonNull(save)) { ORecordId ridField = save.field("@rid"); if (Objects.nonNull(ridField)) { entity.add(Document.of(RID_FIELD, ridField.toString())); } } return entity; } }
From source file:org.kitodo.config.OPACConfig.java
/** * Retrieve the configuration for the passed catalog name from config file. * @param catalogName String identifying the catalog by attribute "title" * @return HierarchicalConfiguration for single catalog *//* w w w .ja va 2 s .c om*/ public static HierarchicalConfiguration getCatalog(String catalogName) { XMLConfiguration conf = getConfig(); int countCatalogues = conf.getMaxIndex("catalogue"); HierarchicalConfiguration catalog = null; for (int i = 0; i <= countCatalogues; i++) { String title = conf.getString("catalogue(" + i + ")[@title]"); if (title.equals(catalogName)) { catalog = conf.configurationAt("catalogue(" + i + ")"); } } if (Objects.nonNull(catalog)) { return catalog; } else { throw new ConfigException(catalogName); } }
From source file:com.mac.halendpoint.endpoints.HalSocket.java
@Override public void onMessage(WebSocket ws, String message) { Logger.getLogger(HalSocket.class.getName()).log(Level.INFO, message, message); if (Objects.nonNull(message) && !message.isEmpty()) { try {//www . ja v a 2 s . c o m if (message.contains("save")) { } else if (message.contains("message")) { Protocol protocol = new Protocol(); protocol.setIsModified(true); protocol.setRespondTo("update"); protocol.setResponse(message); deviceManager.updateState(protocol); } else { System.out.println("MESSAGE BEFORE CONVERSION: " + message); Protocol protocol = (Protocol) JsonConverter.fromJsonString(message, Protocol.class); Protocol returnedProtocol = router.router(protocol); if (returnedProtocol.getRoutedTo().equalsIgnoreCase("device") && returnedProtocol.getRespondTo().equalsIgnoreCase("device")) { String device = returnedProtocol.getResponse(); Device dev = (Device) JsonConverter.fromJsonString(device, Device.class); ((DeviceStateRectifier) deviceManager).manageDevice(dev); } String stringProto = JsonConverter.toJsonString(returnedProtocol); socketManager.sendMessageToAllBrowserSockets(stringProto); } } catch (IOException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(HalSocket.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.amanmehara.programming.android.adapters.LanguageAdapter.java
@Override public void onBindViewHolder(LanguageAdapter.ViewHolder viewHolder, int i) { try {/*from w ww.j av a2 s .com*/ JSONObject language = languages.getJSONObject(i); String languageName = mapLanguageName(language.getString("name")); viewHolder.languageNameView.setText(languageName); String url = language.getString("url"); String response = sharedPreferences.getString(url, null); if (Objects.nonNull(response)) { getProgramsResponseCallback(url, true, languageName, viewHolder).accept(response); } else { new GithubAPIClient(activity, getProgramsResponseCallback(url, false, languageName, viewHolder)) .execute(withAccessToken(url)); } } catch (JSONException e) { Log.e(TAG, e.getMessage()); } }
From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java
public List<T> findByNamedQuery(Class<T> entity, String name, Map<String, ? extends Object> parameters) { NamedQueries nq = entity.getAnnotation(NamedQueries.class); NamedQuery[] nqs = nq.value();//from w w w. j a v a 2 s . co m String queryName = null; for (NamedQuery qn : nqs) { String qname = qn.name(); if (qname.contains(name)) { queryName = qname; break; } } List<T> results = new ArrayList(1); if (Objects.nonNull(queryName)) { TypedQuery<T> query = em.createNamedQuery(queryName, entityClass); if (Objects.nonNull(parameters) && !parameters.isEmpty()) { parameters.entrySet().stream().forEach((entry) -> { query.setParameter((String) entry.getKey(), entry.getValue()); }); } results = query.getResultList(); } return results; }
From source file:org.kitodo.filemanagement.locking.ImmutableReadFileManagement.java
/** * Checks if the copy in question can be disposed of, and if so, does it. A * copy can be discarded if it isnt noted by any user more than his or her * visible version of this file. To find this out, the entire map must be * searched below the original URI. This process can be parallelized very * well. If the copy can be disposed of, it must first be removed from the * map of up-to-date copies so that it will not be reissued during the * deletion, and then deleted. If the file cannot be deleted, a warning is * written to the logfile. System administrators should be on the lookout * for such alerts, because if they occur frequently, this could signal that * the partiton is filling up with temporary files. This can be a problem * especially on Windows, because the Java virtual machine occasionally has * problems deleting files here./*from www . ja va 2 s . c o m*/ * * @param copyInQuestion * URI of the file that may be deleted * @param originUri * URI of the file of which the file in question is a copy. Since * the maps storing the temporary file information use the URI of * the source file as a key, they are much more efficient to use * if it is known. (It would work without, but then you would * have to chew through the whole map every time.) */ private void cleanUp(URI copyInQuestion, URI originUri) { UserMapForURI userMapForURI = urisGivenToUsers.get(originUri); if (Objects.isNull(userMapForURI) || userMapForURI.entrySet().parallelStream() .map(userMapForUriEntry -> userMapForUriEntry.getValue().getKey()) .noneMatch(readCopy -> readCopy.equals(copyInQuestion))) { URI upToDateCopy = upToDateCopies.get(originUri); if (Objects.nonNull(upToDateCopy) && upToDateCopy.equals(copyInQuestion)) { upToDateCopies.remove(originUri); } File fileToDelete = new File(copyInQuestion.getPath()); if (FileUtils.deleteQuietly(fileToDelete)) { logger.debug("the temporary read copy {} was deleted", fileToDelete); } else { logger.warn("The temporary read file {} could not be deleted.", fileToDelete); } } }
From source file:org.kitodo.production.process.ProcessValidator.java
/** * Checks if process title is available. If yes, return true, if no, return * false./*from w w w. j ava 2 s .c o m*/ * * @param title * of process for checking availability * @return true if process title is not used, false if otherwise or title is * null */ public static boolean isProcessTitleAvailable(String title) { if (Objects.nonNull(title)) { long amount; try { amount = ServiceManager.getProcessService().findNumberOfProcessesWithTitle(title); } catch (DataException e) { Helper.setErrorMessage(ERROR_READ, new Object[] { ObjectType.PROCESS.getTranslationSingular() }, logger, e); return false; } if (amount > 0) { Helper.setErrorMessage(INCOMPLETE_DATA, "processTitleAlreadyInUse"); return false; } return true; } return false; }