List of usage examples for com.google.common.collect Iterables getFirst
@Nullable public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:org.opendaylight.yangtools.restconf.utils.RestconfUtils.java
private static Module filterLatestModule(final Iterable<Module> modules) { Module latestModule = Iterables.getFirst(modules, null); for (final Module module : modules) { Date revision = module.getRevision(); Date latestModuleRevision = latestModule.getRevision(); if (revision.after(latestModuleRevision)) { latestModule = module;/*w w w .j ava 2 s.c o m*/ } } return latestModule; }
From source file:org.polymap.core.data.operations.NewFeatureOperation.java
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { try {/*from ww w. j a v a2 s . co m*/ // display and monitor Display display = Polymap.getSessionDisplay(); log.debug("### Display: " + display); monitor.subTask(getLabel()); // FeatureStore for layer if (fs == null) { fs = PipelineFeatureSource.forLayer(layer, true); } SimpleFeatureType schema = (SimpleFeatureType) fs.getSchema(); // create feature SimpleFeature newFeature; if (jsonParam != null) { newFeature = parseJSON(schema, jsonParam); } else { SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema); newFeature = fb.buildFeature(null); } // add feature FeatureCollection<SimpleFeatureType, SimpleFeature> features = FeatureCollections.newCollection(); features.add(newFeature); fids = new FidSet(fs.addFeatures(features)); log.info("### Feature created: " + fids); monitor.worked(1); // update UI display.asyncExec(new Runnable() { public void run() { try { // hover event LayerFeatureSelectionManager fsm = LayerFeatureSelectionManager.forLayer(layer); fsm.setHovered(Iterables.getFirst(fids, null).getID()); } catch (Exception e) { PolymapWorkbench.handleError(DataPlugin.PLUGIN_ID, this, e.getMessage(), e); } } }); return Status.OK_STATUS; } catch (Exception e) { throw new ExecutionException(Messages.get("NewFeatureOperation_errorMsg"), e); } }
From source file:org.eclipse.osee.orcs.core.internal.script.impl.JsonOutputHandler.java
@Override public void onLoadDescription(LoadDescription data) throws OseeCoreException { super.onLoadDescription(data); first = Iterables.getFirst(data.getObjectDescription().getDynamicData(), null); wasStarted = false;/*from w w w . jav a2 s . c o m*/ if (debugInfo != null) { debugInfo.addDescription(data); } }
From source file:exm.stc.common.lang.ForeignFunctions.java
/** * Find an implementation of the special operation * @param special//from ww w .j av a 2 s.co m * @return */ public FnID findSpecialImpl(SpecialFunction special) { Collection<FnID> impls = specialImpls.getByValue(special); return Iterables.getFirst(impls, null); }
From source file:com.davidbracewell.text.morphology.EnglishLemmatizer.java
@Override public String lemmatize(String string, POS partOfSpeech) { return Iterables.getFirst(getBaseForms(string, partOfSpeech), string); }
From source file:com.eucalyptus.ws.server.FilteredPipeline.java
protected boolean resolvesByHost(@Nullable final String host) { boolean match = false; if (host != null) try {/*from ww w . j a v a 2 s.com*/ final Name hostName = Name.fromString(Iterables.getFirst(hostSplitter.split(host), host)); match = nameSupplier.get().contains(DomainNames.absolute(hostName)); } catch (TextParseException e) { Logs.exhaust().error("Invalid host: " + host, e); } return match; }
From source file:org.eclipse.elk.tree.p3place.NodePlacer.java
/** * In this first postorder walk, every node of the tree is assigned a preliminary x-coordinate * (held in property PRELIM). In addition, internal nodes are given modifiers, which will be * used to move their offspring to the right (held in property MODIFIER). * //from w ww . java 2 s.c o m * @param cN * the root level of the tree * @param level * the index of the passed level */ private void firstWalk(final TNode cN, final int level) { cN.setProperty(Properties.MODIFIER, 0d); TNode lS = cN.getProperty(Properties.LEFTSIBLING); if (cN.isLeaf()) { if (lS != null) { /** * Determine the preliminary x-coordinate based on: the preliminary x-coordinate of * the left sibling, the separation between sibling nodes, and tHe mean size of left * sibling and current node. */ double p = lS.getProperty(Properties.PRELIM) + spacing + meanNodeWidth(lS, cN); cN.setProperty(Properties.PRELIM, p); } else { /** No sibling on the left to worry about. */ cN.setProperty(Properties.PRELIM, 0d); } } else { /** * This Node is not a leaf, so call this procedure recursively for each of its * offspring. */ for (TNode child : cN.getChildren()) { firstWalk(child, level + 1); } /** * Set the prelim and modifer for this node by determine the midpoint of its offsprings * and the middle node size of the node and its left sibling */ TNode lM = Iterables.getFirst(cN.getChildren(), null); TNode rM = Iterables.getLast(cN.getChildren(), null); double midPoint = (rM.getProperty(Properties.PRELIM) + lM.getProperty(Properties.PRELIM)) / 2f; if (lS != null) { /** This Node has a left sibling so its offsprings must be shifted to the right */ double p = lS.getProperty(Properties.PRELIM) + spacing + meanNodeWidth(lS, cN); cN.setProperty(Properties.PRELIM, p); cN.setProperty(Properties.MODIFIER, cN.getProperty(Properties.PRELIM) - midPoint); /** shift the offsprings of this node to the right */ apportion(cN, level); } else { /** No sibling on the left to worry about. */ cN.setProperty(Properties.PRELIM, midPoint); } } }
From source file:com.smbtec.xo.orientdb.impl.OrientDbVertexManager.java
private String getDiscriminator(Set<String> discriminators) { return Iterables.getFirst(discriminators, null); }
From source file:org.apache.metron.indexing.dao.InMemoryDao.java
private static boolean isMatch(String query, Map<String, Object> doc) { if (query == null) { return false; }/*from w w w . j a v a2 s . co m*/ if (query.equals("*")) { return true; } if (query.contains(":")) { Iterable<String> splits = Splitter.on(":").split(query.trim()); String field = Iterables.getFirst(splits, ""); String val = Iterables.getLast(splits, ""); // Immediately quit if there's no value ot find if (val == null) { return false; } // Check if we're looking into a nested field. The '|' is arbitrarily chosen. String nestingField = null; if (field.contains("|")) { Iterable<String> fieldSplits = Splitter.on('|').split(field); nestingField = Iterables.getFirst(fieldSplits, null); field = Iterables.getLast(fieldSplits, null); } if (nestingField == null) { // Just grab directly Object o = doc.get(field); return val.equals(o); } else { // We need to look into a nested field for the value @SuppressWarnings("unchecked") List<Map<String, Object>> nestedList = (List<Map<String, Object>>) doc.get(nestingField); if (nestedList == null) { return false; } else { for (Map<String, Object> nestedEntry : nestedList) { if (val.equals(nestedEntry.get(field))) { return true; } } } } } return false; }
From source file:org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper.java
@Override public Response toResponse(final RestconfDocumentedException exception) { LOG.debug("In toResponse: {}", exception.getMessage()); final List<MediaType> accepts = headers.getAcceptableMediaTypes(); accepts.remove(MediaType.WILDCARD_TYPE); LOG.debug("Accept headers: {}", accepts); final MediaType mediaType; if (accepts != null && accepts.size() > 0) { mediaType = accepts.get(0); // just pick the first one } else {//from w w w .j a va 2 s .c o m // Default to the content type if there's no Accept header mediaType = MediaType.APPLICATION_JSON_TYPE; } LOG.debug("Using MediaType: {}", mediaType); final List<RestconfError> errors = exception.getErrors(); if (errors.isEmpty()) { // We don't actually want to send any content but, if we don't set any content here, // the tomcat front-end will send back an html error report. To prevent that, set a // single space char in the entity. return Response.status(exception.getStatus()).type(MediaType.TEXT_PLAIN_TYPE).entity(" ").build(); } final int status = errors.iterator().next().getErrorTag().getStatusCode(); final ControllerContext context = ControllerContext.getInstance(); final DataNodeContainer errorsSchemaNode = (DataNodeContainer) context.getRestconfModuleErrorsSchemaNode(); if (errorsSchemaNode == null) { return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build(); } Preconditions.checkState(errorsSchemaNode instanceof ContainerSchemaNode, "Found Errors SchemaNode isn't ContainerNode"); final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> errContBuild = Builders .containerBuilder((ContainerSchemaNode) errorsSchemaNode); final List<DataSchemaNode> schemaList = ControllerContext.findInstanceDataChildrenByName(errorsSchemaNode, Draft02.RestConfModule.ERROR_LIST_SCHEMA_NODE); final DataSchemaNode errListSchemaNode = Iterables.getFirst(schemaList, null); Preconditions.checkState(errListSchemaNode instanceof ListSchemaNode, "Found Error SchemaNode isn't ListSchemaNode"); final CollectionNodeBuilder<MapEntryNode, MapNode> listErorsBuilder = Builders .mapBuilder((ListSchemaNode) errListSchemaNode); for (final RestconfError error : errors) { listErorsBuilder.withChild(toErrorEntryNode(error, errListSchemaNode)); } errContBuild.withChild(listErorsBuilder.build()); final NormalizedNodeContext errContext = new NormalizedNodeContext( new InstanceIdentifierContext<DataSchemaNode>(null, (DataSchemaNode) errorsSchemaNode, null, context.getGlobalSchema()), errContBuild.build()); Object responseBody; if (mediaType.getSubtype().endsWith("json")) { responseBody = toJsonResponseBody(errContext, errorsSchemaNode); } else { responseBody = toXMLResponseBody(errContext, errorsSchemaNode); } return Response.status(status).type(mediaType).entity(responseBody).build(); }