List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:de.azapps.mirakel.settings.model_settings.special_list.dialogfragments.editfragments.ConjunctionFragment.java
private static SpecialListsConjunctionList getRootProperty( @NonNull final Optional<SpecialListsBaseProperty> where, @NonNull final List<Integer> backStack) { if (where.isPresent()) { if (where.get() instanceof SpecialListsConjunctionList) { SpecialListsConjunctionList currentProperty = (SpecialListsConjunctionList) where.get(); for (int i = 0; i < backStack.size(); i++) { if (backStack.get(i) == NEW_PROPERTY) { final SpecialListsConjunctionList newList = new SpecialListsConjunctionList( (currentProperty.getConjunction() == SpecialListsConjunctionList.CONJUNCTION.AND) ? SpecialListsConjunctionList.CONJUNCTION.OR : SpecialListsConjunctionList.CONJUNCTION.AND, new ArrayList<SpecialListsBaseProperty>()); backStack.set(i, currentProperty.getChilds().size()); currentProperty.getChilds().add(newList); return newList; }// w w w . j a v a 2 s . co m if (currentProperty.getChilds().get(backStack.get(i)) instanceof SpecialListsConjunctionList) { currentProperty = (SpecialListsConjunctionList) currentProperty.getChilds() .get(backStack.get(i)); } else { final List<SpecialListsBaseProperty> childs = new ArrayList<>(1); childs.add(currentProperty.getChilds().get(backStack.get(i))); currentProperty = new SpecialListsConjunctionList( (currentProperty.getConjunction() == SpecialListsConjunctionList.CONJUNCTION.AND) ? SpecialListsConjunctionList.CONJUNCTION.OR : SpecialListsConjunctionList.CONJUNCTION.AND, childs); break; } } return currentProperty; } } return new SpecialListsConjunctionList(SpecialListsConjunctionList.CONJUNCTION.AND, new ArrayList<SpecialListsBaseProperty>(0)); }
From source file:jcomposition.processor.utils.AnnotationUtils.java
public static TypeElement getBindClassType(TypeElement element, ProcessingEnvironment env) { Optional<AnnotationValue> value = getParameterFrom(element, Bind.class, "value", env); if (value.isPresent()) { TypeElement typeElement = MoreTypes.asTypeElement((Type) value.get().getValue()); AnnotationMirror bindMirror = MoreElements.getAnnotationMirror(typeElement, Bind.class).orNull(); if (!typeElement.getKind().isClass()) { env.getMessager().printMessage(Diagnostic.Kind.ERROR, "Bind's annotation value must be class", element, bindMirror, value.get()); return null; }//from w w w .j a va2 s .c o m /** * Bind annotation is not valid if Bind's class value isn't implements element interface */ javax.lang.model.util.Types types = env.getTypeUtils(); if (!types.isAssignable(types.getDeclaredType(typeElement), types.getDeclaredType(element)) && !types.isAssignable(typeElement.getSuperclass(), element.asType())) { env.getMessager().printMessage(Diagnostic.Kind.ERROR, "Bind's annotation value class must implement " + element.getSimpleName() + " interface", element, bindMirror, value.get()); return null; } return typeElement; } return null; }
From source file:springfox.bean.validators.plugins.Validators.java
public static <T extends Annotation> Optional<T> annotationFromBean(ModelPropertyContext context, Class<T> annotationType) { Optional<BeanPropertyDefinition> propertyDefinition = context.getBeanPropertyDefinition(); Optional<T> notNull = Optional.absent(); if (propertyDefinition.isPresent()) { Optional<Method> getter = extractGetterFromPropertyDefinition(propertyDefinition.get()); Optional<Field> field = extractFieldFromPropertyDefinition(propertyDefinition.get()); notNull = findAnnotation(getter, annotationType).or(findAnnotation(field, annotationType)); }/* ww w . j a v a2 s . c o m*/ return notNull; }
From source file:com.facebook.buck.apple.xcode.FrameworkPath.java
public static FrameworkPath fromString(BuildTarget target, String string) { Path path = Paths.get(string); String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString(); if (firstElement.startsWith("$")) { // NOPMD - length() > 0 && charAt(0) == '$' is ridiculous Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement); if (sourceTree.isPresent()) { return ImmutableFrameworkPath.builder() .sourceTreePath(new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()))) .build();/* w w w.j av a 2s.co m*/ } else { throw new HumanReadableException(String.format( "Unknown SourceTree: %s in target: %s. Should be one of: %s", firstElement, target, Joiner.on(',') .join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()), new Function<PBXReference.SourceTree, String>() { @Override public String apply(PBXReference.SourceTree input) { return "$" + input.toString(); } })))); } } else { return ImmutableFrameworkPath.builder().sourcePath(new BuildTargetSourcePath(target, Paths.get(string))) .build(); } }
From source file:org.anhonesteffort.flock.sync.SyncWorkerUtil.java
protected static <T> HashMap<String, Optional<String>> handleFilterUidsChangedRemotely( AbstractLocalComponentCollection<T> localCollection, HashMap<String, String> remoteUidETagMap) throws RemoteException { HashMap<String, Optional<String>> localUidETagMap = new HashMap<String, Optional<String>>(); for (java.util.Map.Entry<String, String> remoteETagEntry : remoteUidETagMap.entrySet()) { Optional<String> localETag = localCollection.getETagForUid(remoteETagEntry.getKey()); if (!localETag.isPresent() || !localETag.get().equals(remoteETagEntry.getValue())) localUidETagMap.put(remoteETagEntry.getKey(), localETag); }//from ww w . j a v a 2 s .co m return localUidETagMap; }
From source file:org.opendaylight.netconf.util.messages.NetconfHelloMessage.java
public static NetconfHelloMessage createClientHello(Iterable<String> capabilities, Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException { Document doc = createHelloMessageDoc(capabilities); return additionalHeaderOptional.isPresent() ? new NetconfHelloMessage(doc, additionalHeaderOptional.get()) : new NetconfHelloMessage(doc); }
From source file:org.apache.brooklyn.entity.nosql.redis.RedisStoreImpl.java
/** * Create a {@link Function} to retrieve a particular field value from a {@code redis-cli info} * command.// www . jav a 2 s. c om * * @param field the info field to retrieve and convert * @return a new function that converts a {@link SshPollValue} to an {@link Integer} */ private static Function<SshPollValue, Integer> infoFunction(final String field) { return Functions.compose(new Function<String, Integer>() { @Override public Integer apply(@Nullable String input) { Optional<String> line = Iterables.tryFind(Splitter.on('\n').split(input), Predicates.containsPattern(field + ":")); if (line.isPresent()) { String data = line.get().trim(); int colon = data.indexOf(":"); return Integer.parseInt(data.substring(colon + 1)); } else { throw new IllegalStateException("Data for field " + field + " not found: " + input); } } }, SshValueFunctions.stdout()); }
From source file:org.dswarm.graph.batch.rdf.pnx.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }// w w w .jav a2 s. com final NodeType nodeType; final Node node = optionalNode.get(); if (node instanceof Resource) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else if (node instanceof BNode) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node instanceof Literal) { nodeType = NodeType.Literal; } else { nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:org.pau.assetmanager.business.ClientsBusiness.java
/** * This method removes a client from the database * /*ww w . j a v a 2 s . c o m*/ * @param selectedClient client to remove * * @return the client removed */ public static Client removeClient(Client selectedClient) { String queryBooks = "select book from Book book where book.client=:client"; List<Book> books = DaoFunction.<Book>querySimpleListFunction("client", selectedClient).apply(queryBooks); for (Book book : books) { BooksBusiness.removeBook(book); } String queryClients = "select client from Client client where client=:client"; Optional<Client> optionalClient = DaoFunction.<Client>querySimpleUniqueFunction("client", selectedClient) .apply(queryClients); if (optionalClient.isPresent()) { Client client = optionalClient.get(); DaoFunction.deleteDetachedFunction().apply(client); return client; } else { String message = "Client '" + selectedClient.toString() + "' not found in the database"; logger.error(message); throw new AssetManagerRuntimeException(message); } }
From source file:org.dswarm.graph.rdf.nx.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }/* w ww .j a v a 2 s . c om*/ final NodeType nodeType; final Node node = optionalNode.get(); if (node instanceof BNode) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node instanceof Literal) { nodeType = NodeType.Literal; } else if (node instanceof Resource) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else { nodeType = null; } return Optional.fromNullable(nodeType); }