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.google.security.zynamics.binnavi.Gui.Debug.ToolbarPanel.Implementations.CSteppingHelper.java
/** * Determines the start address of a node. * * @param node Node whose address is determined. * * @return The start address of the given node or null if the node does not have an address. *///from ww w . j a v a 2s . c o m private static BreakpointAddress getAddress(final INaviViewNode node) { if (node instanceof INaviCodeNode) { final INaviCodeNode ccnode = (INaviCodeNode) node; final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null); return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress())); } else if (node instanceof INaviFunctionNode) { final INaviFunction function = ((INaviFunctionNode) node).getFunction(); final INaviModule module = function.getModule(); return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress())); } else { // Node types we can not step to return null; } }
From source file:com.zimbra.common.util.ListUtil.java
/** * Returns the first element, or {@code null} if the collection is * {@code null} or empty.//from w ww. jav a 2 s .co m */ public static <T> T getFirstElement(Iterable<T> iterable) { return iterable == null ? null : Iterables.getFirst(iterable, null); }
From source file:org.devinprogress.uniskinmod.UniSkinMod.java
/** Hijack the GameProfile in NetworkPlayerInfo & Skull renderer*/ public static GameProfile fillGameProfile(final GameProfile gameProfileIn) { if (gameProfileIn == null) return null; final String player_name = gameProfileIn.getName(); Property finalP = null;/*from w ww . ja v a 2 s . c o m*/ try { finalP = cache.get(player_name, new Callable<Property>() { @Override public Property call() throws Exception { log.info("Filling profile for player: " + player_name); Property textureProperty = (Property) Iterables .getFirst(gameProfileIn.getProperties().get("textures"), (Object) null); MojangTexturePayload payload = MojangTexturePayload.fromProperty(textureProperty); if (payload == null) payload = new MojangTexturePayload(player_name); for (String root : roots) { if (payload.isComplete()) break; UniSkinApiProfile api = UniSkinApiProfile.getProfile(player_name, root); if (api == null) continue; payload.addCape(api.getCapeURL()); payload.addSkin(api.getSkinURL(), api.getModel()); } return payload.toProperty(); } }); } catch (Exception ex) { ex.printStackTrace(); return gameProfileIn; } gameProfileIn.getProperties().removeAll("textures"); gameProfileIn.getProperties().put("textures", finalP); return gameProfileIn; }
From source file:com.facebook.buck.apple.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().setSourceTreePath( new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()))).build(); } else {//from ww w.j a v a2 s . c o m 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() .setSourcePath(new BuildTargetSourcePath(target, Paths.get(string))).build(); } }
From source file:io.bazel.rules.closure.ClosureUberAlles.java
@Override public Integer apply(Iterable<String> args) { String head = Iterables.getFirst(args, ""); Iterable<String> tail = Iterables.skip(args, 1); // TODO(jart): Include Closure Templates and Stylesheets. switch (head) { case "JsChecker": return new JsChecker.Program().apply(tail); case "JsCompiler": return new JsCompiler().apply(tail); default://from ww w . j av a 2 s. c o m System.err.println("\nERROR: First flag to ClosureUberAlles should be specific compiler to run, " + "e.g. JsChecker\n"); return 1; } }
From source file:org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler.java
private static JdbcService findJdbcService(BundleContext context) { JdbcService toReturn = null;/* w ww.jav a2 s .co m*/ try { Collection<ServiceReference<JdbcService>> references = context.getServiceReferences(JdbcService.class, "(osgi.binding=skynet.jdbc.service)"); ServiceReference<JdbcService> reference = Iterables.getFirst(references, null); if (reference != null) { toReturn = context.getService(reference); } } catch (InvalidSyntaxException ex) { throw new OseeCoreException(ex, "Error finding JdbcService reference with osgi.binding=skynet.jdbc.service"); } return toReturn; }
From source file:org.apache.metron.dataloads.nonbulk.taxii.TableInfo.java
public TableInfo(String s) { Iterable<String> i = Splitter.on(":").split(s); if (Iterables.size(i) != 2) { throw new IllegalStateException("Malformed table:cf => " + s); }//ww w. j av a 2 s.c om tableName = Iterables.getFirst(i, null); columnFamily = Iterables.getLast(i); }
From source file:com.google.gerrit.server.project.ChildProjectResource.java
public boolean isDirectChild() { ProjectState parent = Iterables.getFirst(child.getProjectState().parents(), null); return parent != null && getNameKey().equals(parent.getProject().getNameKey()); }
From source file:dropship.agent.statsd.SnitchService.java
private static String getHostname() { String defaultHostname = "localhost"; try {//from ww w . j a v a 2 s . c o m return Iterables.getFirst(Splitter.on('.').split(InetAddress.getLocalHost().getHostName()), defaultHostname); } catch (Exception e) { return defaultHostname; } }
From source file:com.example.repository.MapBackedRepository.java
public V first() { return Iterables.getFirst(service.values(), null); }