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:com.eviware.loadui.integration.LoadUIUtils.java
public static List<SceneItem> getTestCases(WorkspaceProvider workspaceProvider) { Collection<? extends ProjectItem> projectList = workspaceProvider.getWorkspace().getProjects(); if (!projectList.isEmpty()) { ProjectItem projectItem = Iterables.getFirst(projectList, null); return Lists.newArrayList(projectItem.getChildren()); }/*from w ww . jav a 2s . c om*/ return Lists.newArrayList(); }
From source file:org.dishevelled.bio.range.entrytree.CenteredRangeTree.java
/** * Create and return a new node for the specified range entries. * * @param entries range entries// w w w . j a va2 s . co m * @return a new node for the specified range entries */ private Node createNode(final Iterable<Entry<C, V>> entries) { Entry<C, V> first = Iterables.getFirst(entries, null); if (first == null) { return null; } Range<C> span = first.getRange(); for (Entry<C, V> entry : entries) { Range<C> range = entry.getRange(); span = range.span(span); } if (span.isEmpty()) { return null; } C center = Ranges.center(span); List<Entry<C, V>> left = Lists.newArrayList(); List<Entry<C, V>> right = Lists.newArrayList(); List<Entry<C, V>> overlap = Lists.newArrayList(); for (Entry<C, V> entry : entries) { Range<C> range = entry.getRange(); if (Ranges.isLessThan(range, center)) { left.add(entry); } else if (Ranges.isGreaterThan(range, center)) { right.add(entry); } else { overlap.add(entry); } } return new Node(center, createNode(left), createNode(right), overlap); }
From source file:com.yahoo.yqlplus.engine.internal.source.ExportModuleAdapter.java
@Override public OperatorNode<PhysicalExprOperator> callInRowContext(Location location, ContextPlanner context, String name, List<OperatorNode<ExpressionOperator>> arguments, OperatorNode<PhysicalExprOperator> row) { Collection<ObjectBuilder.MethodBuilder> targets = methods.get(name); if (targets.isEmpty()) { throw new ProgramCompileException(location, "Method '%s' not found on module %s", name, moduleName); }/*from ww w .j av a 2s .c o m*/ @SuppressWarnings("ConstantConditions") GambitCreator.Invocable firstInvocable = Iterables.getFirst(targets, null).invoker(); TypeWidget outputType = firstInvocable.getReturnType(); DynamicExpressionEvaluator eval = row == null ? new DynamicExpressionEvaluator(context) : new DynamicExpressionEvaluator(context, row); List<OperatorNode<PhysicalExprOperator>> callArgs = Lists.newArrayList(); callArgs.add(getModule(location, context)); callArgs.add(context.getContextExpr()); if (targets.size() > 1) { callArgs.addAll(eval.applyAll(arguments)); for (ObjectBuilder.MethodBuilder candidate : targets) { outputType = context.getValueTypeAdapter().unifyTypes(outputType, candidate.invoker().getReturnType()); } return OperatorNode.create(location, PhysicalExprOperator.CALL, outputType, name, callArgs); } else { Iterator<TypeWidget> args = firstInvocable.getArgumentTypes().iterator(); args.next(); args.next(); // consume the module & context Iterator<OperatorNode<ExpressionOperator>> e = arguments.iterator(); while (args.hasNext()) { if (!e.hasNext()) { throw new ProgramCompileException(location, "Argument length mismatch in call to %s (expects %d arguments)", name, firstInvocable.getArgumentTypes().size()); } callArgs.add(OperatorNode.create(location, PhysicalExprOperator.CAST, args.next(), eval.apply(e.next()))); } if (e.hasNext()) { throw new ProgramCompileException(location, "Argument length mismatch in call to %s (expects %d arguments)", name, firstInvocable.getArgumentTypes().size()); } return OperatorNode.create(location, PhysicalExprOperator.INVOKE, firstInvocable, callArgs); } }
From source file:org.dcache.pool.nearline.filesystem.FileSystemNearlineStorage.java
@Override protected Set<Checksum> stage(StageRequest request) throws CacheException, IOException { FileAttributes fileAttributes = request.getFileAttributes(); URI location = Iterables.getFirst(getLocations(fileAttributes), null); if (location == null) { throw new CacheException(CacheException.BROKEN_ON_TAPE, "File not on nearline storage: " + fileAttributes.getPnfsId()); }/*from w ww . j a v a 2 s . com*/ String path = location.getPath(); if (path == null) { throw new InvalidMessageCacheException("Invalid nearline storage URI: " + location); } stage(getExternalPath(path.substring(1)), request.getFile().toPath()); return Collections.emptySet(); }
From source file:nextmethod.web.razor.parser.syntaxtree.Block.java
@Override public SourceLocation getStart() { final SyntaxTreeNode child = Iterables.getFirst(this.children, null); if (child == null) { return SourceLocation.Zero; }// w ww . ja v a2 s. c o m return child.getStart(); }
From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java
@Override public ProposalBranch forkBranch(final ProposalBranch fork, final long branchToForkId) { Assert.notNull(fork, "No ProposalBag supplied !"); Assert.isNull(fork.getId(), "Id should not be set for creation !"); // Duplicate the branch to Fork new TxCallback(this.getEmf()) { @Override/*from www .j a v a 2s . com*/ @SuppressWarnings("unchecked") protected void executeInTransaction(final EntityManager em) { final Query loadFullBranchQuery = em.createNamedQuery(ProposalBranch.LOAD_FULL_BRANCH); loadFullBranchQuery.setParameter("branchId", branchToForkId); final ProposalBranch branchToFork = Iterables.getFirst(loadFullBranchQuery.getResultList(), null); if (branchToFork == null) { throw new ProposalBranchNotFoundException(); } fork.setBags(branchToFork.getBags()); em.persist(fork); } }; return fork; }
From source file:com.facebook.buck.testutil.ZipArchive.java
/** * Open the zip file for reading and/or writing. Note that this constructor will create {@code * zip} if {@code forWriting} is true and the file does not exist. * * @param zip The zip file to operate on. The name must end with ".zip" or ".jar". * @param forWriting Whether the zip file should be opened for writing or not. * @throws IOException Should something terrible occur. *//*from w w w .j a v a 2 s .co m*/ public ZipArchive(Path zip, boolean forWriting) throws IOException { String extension = MorePaths.getFileExtension(zip); assertTrue("zip name must end with .zip for file type detection to work", "zip".equals(extension) || "jar".equals(extension)); URI uri = URI.create("jar:" + zip.toUri()); fs = FileSystems.newFileSystem(uri, ImmutableMap.of("create", String.valueOf(forWriting))); root = Iterables.getFirst(fs.getRootDirectories(), null); assertNotNull("Unable to determine root of file system: " + fs, root); }
From source file:com.dmdirc.config.profiles.ProfileManager.java
/** * Returns the default profile if no custom profiles have been set. * * @return Default profile/*from ww w. j av a 2 s . c o m*/ */ public Profile getDefault() { return Iterables.getFirst(profiles, defaultProfile); }
From source file:org.yakindu.base.expressions.linking.OperationOverloadingLinkingService.java
public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) { final EClass requiredType = ref.getEReferenceType(); if (requiredType == null) { return Collections.<EObject>emptyList(); }//from w w w .j a va2s . co m final String crossRefString = getCrossRefNodeAsString(node); if (crossRefString == null || crossRefString.equals("")) { return Collections.<EObject>emptyList(); } final IScope scope = getScope(context, ref); final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString); // Adoption to super class implementation here to return multi elements final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName); int size = Iterables.size(eObjectDescription); if (size == 0) return Collections.emptyList(); if (size == 1) return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy()); // Two operation with same name found here List<IEObjectDescription> candidates = new ArrayList<>(); for (IEObjectDescription currentDescription : eObjectDescription) { if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) { candidates.add(currentDescription); } } Optional<Operation> operation = operationsLinker.linkOperation(candidates, context); if (operation.isPresent()) { return Collections.singletonList(operation.get()); } //Link to first operation to get parameter errors instead of linking errors return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy()); }
From source file:io.helixservice.feature.restservice.controller.Request.java
/** * Gets the first value found for the given query parameter * * @param parameterName Query parameter name * @param defaultValue Default value if the parameter does not exist * @return The first parameter value found, or the default value *///from w w w .java2 s.c o m public String getParam(String parameterName, String defaultValue) { return Iterables.getFirst(params.get(parameterName), defaultValue); }