List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java
@ProtocolMapping(routeTo = "query", respondTo = "query", numParams = 2) private Message query(String deviceName, String command) throws Exception { Message msg = null;/*w ww . jav a2 s .c om*/ if (Objects.nonNull(deviceName) && Objects.nonNull(command)) { String uri = formUri(BASE_RESOURCE_PATH, "query", deviceName, command); RestTemplate template = new RestTemplate(); msg = template.getForObject(uri, Message.class); } return msg; }
From source file:org.kitodo.export.ExportDms.java
/** * The function startExport() performs a DMS export to a desired place. In * addition, it accepts an optional ExportDmsTask object. If that is passed * in, the progress in it will be updated during processing and occurring * errors will be passed to it to be visible in the task manager screen. * * @param process/*from w w w . ja va2 s . c om*/ * process to export * @param destination * work directory of the user who triggered the export * @param exportDmsTask * ExportDmsTask object to submit progress updates and errors * @return false if an error condition was caught, true otherwise */ public boolean startExport(Process process, URI destination, ExportDmsTask exportDmsTask) { this.exportDmsTask = exportDmsTask; try { return startExport(process, destination, ServiceManager.getProcessService().readMetadataFile(process).getDigitalDocument()); } catch (IOException | RuntimeException e) { if (Objects.nonNull(exportDmsTask)) { exportDmsTask.setException(e); logger.error(Helper.getTranslation(ERROR_EXPORT, Collections.singletonList(process.getTitle())), e); } else { Helper.setErrorMessage(ERROR_EXPORT, new Object[] { process.getTitle() }, logger, e); } return false; } }
From source file:org.kitodo.production.forms.dataeditor.StructurePanel.java
/** * Set selected logical TreeNode.//w w w . ja va2 s.co m * * @param selected * TreeNode that will be selected */ public void setSelectedLogicalNode(TreeNode selected) { if (Objects.nonNull(selected)) { this.selectedLogicalNode = selected; } }
From source file:com.mac.halendpoint.endpoints.HalSocket.java
@Override public void onError(WebSocket ws, Exception excptn) { if (Objects.nonNull(ws)) { if (ws.isOpen()) { ws.close();//from www. jav a 2s . c o m } socketManager.removeSocket(ws); } }
From source file:com.amanmehara.programming.android.activities.ProgramActivity.java
private void setLanguageDatails() { TextView name = (TextView) findViewById(R.id.language_name); name.setText(languageName);/*w ww .j a va 2s . c om*/ ImageView image = (ImageView) findViewById(R.id.language_image); if (Objects.nonNull(logoBlob)) { int imageBlobLength = logoBlob.length; Bitmap logo = BitmapFactory.decodeByteArray(logoBlob, 0, imageBlobLength); image.setImageBitmap(logo); } else { image.setImageResource(R.drawable.ic_circle_logo); } }
From source file:org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl.java
private Optional<Boolean> isNodeTypeExistInServiceTemplateHierarchy(String nodeTypeToMatch, String nodeTypeToSearch, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> analyzedImportFiles) { Map<String, NodeType> searchableNodeTypes = serviceTemplate.getNode_types(); if (!MapUtils.isEmpty(searchableNodeTypes)) { NodeType nodeType = searchableNodeTypes.get(nodeTypeToSearch); if (Objects.nonNull(nodeType)) { if (Objects.equals(nodeType.getDerived_from(), nodeTypeToMatch)) { return Optional.of(true); } else if (isNodeTypeIsToscaRoot(nodeType)) { return Optional.of(false); } else { return isNodeTypeExistInServiceTemplateHierarchy(nodeTypeToMatch, nodeType.getDerived_from(), serviceTemplate, toscaServiceModel, null); }//from ww w .j a va2s . c om } else { return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate, toscaServiceModel, analyzedImportFiles); } } return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate, toscaServiceModel, analyzedImportFiles); }
From source file:de.speexx.csv.table.app.Application.java
void adjustTableColumns(final Configuration conf, final Table table, final SimpleRowDataMetric metric) { assert Objects.nonNull(table) : "Table is null"; assert Objects.nonNull(metric) : "Metric is null"; if (conf.isVerbose()) { LOG.info("Adjust column types"); }/*w w w . j a va 2s . c o m*/ final List<EntryDescriptor> changeDescriptors = new ArrayList<>(); table.getEntryDescriptors().forEach(desc -> { final String columnName = desc.getName(); final Optional<EntryDescriptor.Type> mostSignificantType = metric .getMostSignificantTypeForName(columnName); if (mostSignificantType.isPresent()) { final EntryDescriptor.Type type = mostSignificantType.get(); if (type != EntryDescriptor.Type.STRING) { // From CSV there are only strings, so ignore that doVerboseLog(conf, " Change column '{}' to type {}", columnName, type); changeDescriptors.add(new EntryDescriptor() { @Override public EntryDescriptor.Type getType() { return type; } @Override public String getName() { return columnName; } }); } } }); doVerboseLog(conf, "Adjusting column types starting"); final long changeStart = System.currentTimeMillis(); table.changeColumnTypes(changeDescriptors.toArray(new EntryDescriptor[changeDescriptors.size()])); doVerboseLog(conf, "Adjust columns tock {}ms", System.currentTimeMillis() - changeStart); }
From source file:org.apache.zeppelin.shell.terminal.service.TerminalService.java
public void onTerminalResize(String columns, String rows) { if (Objects.nonNull(columns) && Objects.nonNull(rows)) { this.columns = Integer.valueOf(columns); this.rows = Integer.valueOf(rows); if (Objects.nonNull(process)) { process.setWinSize(new WinSize(this.columns, this.rows)); }/*from w ww . ja v a 2 s . c om*/ } }
From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java
/** * STRAIGHT FLUSH/*w ww . j a va2s . c o m*/ * * @return */ private HandRank bHandRank() { HandRank hr = eHandRank(); if (Objects.nonNull(hr)) { Card[] cards = hr.getHand(); // Arrays.sort(cards, this); if (isConsecutive(cards)) { return new SimpleHandRank(HandType.STRAIGHT_FLUSH, cards); } else { Entry<Suit, Rank[]> flush = getFlushEntry(); List<Card> wheel = new ArrayList(); int i = 0; Rank[] posWheel = Arrays.copyOf(flush.getValue(), flush.getValue().length); Arrays.sort(posWheel, rc); for (Rank r : posWheel) { if (i < 4 && Objects.nonNull(r)) { if ((i + 2) == r.value()) { wheel.add(makeCard(flush.getKey(), r)); } } i++; } int aceIndex = ArrayUtils.indexOf(posWheel, Rank.ACE); if (aceIndex >= 0) { wheel.add(makeCard(flush.getKey(), posWheel[aceIndex])); } if (wheel.size() != 5) { return null; } return new SimpleHandRank(HandType.STRAIGHT_FLUSH, wheel.toArray(new Card[5])); } } return null; }
From source file:io.github.jeddict.jpa.spec.sync.JavaClassSyncHandler.java
public void syncExistingSnippet(CompilationUnit existingSource) { Map<String, Attribute> attributes = javaClass.getAttributes().getAllAttributeMap(); Map<String, Attribute> previousAttributes = javaClass.getAttributes().getAllAttribute().stream() .filter(attr -> Objects.nonNull(attr.getPreviousName())) .collect(toMap(Attribute::getPreviousName, identity())); Map<String, ImportDeclaration> imports = existingSource.getImports().stream() .collect(toMap(importDec -> unqualify(importDec.getNameAsString()), identity())); NodeList<TypeDeclaration<?>> types = existingSource.getTypes(); for (TypeDeclaration<?> type : types) { if (type.getNameAsString().equals(javaClass.getPreviousClass()) || type.getNameAsString().equals(javaClass.getClazz())) { ClassOrInterfaceDeclaration rootClass = (ClassOrInterfaceDeclaration) type; syncHeaderJavaDoc(type);/*ww w . java 2 s . co m*/ syncTypeParameters(rootClass.getTypeParameters(), imports); syncExtendedTypes(rootClass.getExtendedTypes(), imports); syncImplementedTypes(rootClass.getImplementedTypes(), imports); syncAnnotations(rootClass.getAnnotations(), TYPE, imports); NodeList<BodyDeclaration<?>> members = rootClass.getMembers(); for (BodyDeclaration<?> member : members) { if (member instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration) member; String methodName = method.getNameAsString(); if (isBeanMethod(methodName)) { String attributeName = getFieldName(methodName); if (javaClass.getRemovedAttributes().contains(attributeName)) { continue; //ignore deleted attribute } Attribute previousAttribute = previousAttributes.get(attributeName); Attribute attribute = attributes.get(attributeName); if (previousAttribute != null) { //renamed AttributeSyncHandler.getInstance(previousAttribute) .syncExistingSnippet(attributeName, method, imports); } else if (attribute != null) { // new or non-modified AttributeSyncHandler.getInstance(attribute).syncExistingSnippet(attributeName, method, imports); } else { syncMethodSnippet(method, imports); } } else if (methodName.equals("toString") && method.getParameters().isEmpty()) { if (javaClass.getToStringMethod().getAttributes().isEmpty()) { syncMethodSnippet(method, imports); } } else if (methodName.equals("hashCode") && method.getParameters().isEmpty()) { if (javaClass.getHashCodeMethod().getAttributes().isEmpty()) { syncMethodSnippet(method, imports); } } else if (methodName.equals("equals") && method.getParameters().size() == 1 && method.getParameters().get(0).getTypeAsString().equals("Object")) { if (javaClass.getEqualsMethod().getAttributes().isEmpty()) { syncMethodSnippet(method, imports); } } else if ((methodName.startsWith("add") || methodName.startsWith("remove")) && (method.getParameters().size() == 1 || method.getParameters().size() == 2)) { // delegator/helper method String attributeName = getFieldNameFromDelegatorMethod(methodName); String attributePluralName = Inflector.getInstance().pluralize(attributeName); if (javaClass.getRemovedAttributes().contains(attributePluralName)) { continue; } Attribute previousAttribute = previousAttributes.get(attributePluralName); Attribute attribute = attributes.get(attributePluralName); if (previousAttribute == null && attribute == null) { // if helper method field name is not plural if (javaClass.getRemovedAttributes().contains(attributeName)) { continue; } previousAttribute = previousAttributes.get(attributeName); attribute = attributes.get(attributeName); } if (previousAttribute != null && previousAttribute instanceof CollectionTypeHandler && isNotBlank( ((CollectionTypeHandler) previousAttribute).getCollectionImplType())) { //renamed // skip } else if (attribute != null && attribute instanceof CollectionTypeHandler && isNotBlank(((CollectionTypeHandler) attribute).getCollectionImplType())) { // new or non-modified // skip } else { syncMethodSnippet(method, imports); } } else if (isFluentMethod(method)) { String attributeName = method.getParameter(0).getNameAsString(); Attribute previousAttribute = previousAttributes.get(attributeName); Attribute attribute = attributes.get(attributeName); if (previousAttribute == null && attribute == null) { syncMethodSnippet(method, imports); } } else { syncMethodSnippet(method, imports); } } else if (member instanceof FieldDeclaration) { FieldDeclaration field = (FieldDeclaration) member; String attributeName = field.getVariable(0).getNameAsString(); if (javaClass.getRemovedAttributes().contains(attributeName)) { continue; //ignore deleted attribute } Attribute previousAttribute = previousAttributes.get(attributeName); Attribute attribute = attributes.get(attributeName); if (previousAttribute != null) { //renamed AttributeSyncHandler.getInstance(previousAttribute).syncExistingSnippet(attributeName, field, imports); } else if (attribute != null) { // new or non-modified AttributeSyncHandler.getInstance(attribute).syncExistingSnippet(attributeName, field, imports); } else { syncFieldSnippet((FieldDeclaration) member, imports); } } else if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) { syncInnerClassOrInterfaceOrEnumSnippet(member, imports); } else if (member instanceof InitializerDeclaration) { syncInitializationBlockSnippet((InitializerDeclaration) member, imports); } else if (member instanceof ConstructorDeclaration) { syncConstructorSnippet((ConstructorDeclaration) member, imports); } else { System.out.println("member not supported"); } } } else if (type instanceof ClassOrInterfaceDeclaration || type instanceof EnumDeclaration) { syncClassOrInterfaceOrEnumSnippet(type, imports); } else { System.out.println("member not supported"); } } }