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.apache.metron.enrichment.bolt.HBaseBolt.java
public static String zkConnectStringToHosts(String connString) { Iterable<String> hostPortPairs = Splitter.on(',').split(connString); return Joiner.on(',').join(Iterables.transform(hostPortPairs, new Function<String, String>() { @Override/*from w w w.jav a2 s . co m*/ public String apply(String hostPortPair) { return Iterables.getFirst(Splitter.on(':').split(hostPortPair), ""); } })); }
From source file:brooklyn.example.ExampleForwardingEntityImpl.java
@Override protected void preStart() { super.preStart(); Entity originEntity = getConfig(ORIGIN_ENTITY_FORWARDED); AttributeSensor<Integer> originPortAttribute = getConfig(ORIGIN_PORT_ATTRIBUTE_FORWARDED); try {//from ww w . j a va2 s . co m // wait for the target DB to be available String url = Tasks.resolveValue( DependentConfiguration.attributeWhenReady(originEntity, Attributes.SERVICE_UP), String.class, getExecutionContext()); log.info("burst node " + this + " detected target DB available at " + url); Integer originPort = originEntity.getAttribute(originPortAttribute); SshMachineLocation fakeDb = (SshMachineLocation) getMachineOrNull(); SshMachineLocation realDb = (SshMachineLocation) Iterables .getFirst(((EntityLocal) originEntity).getLocations(), null); String originPublicKeyData = originEntity.getAttribute(PUBLIC_KEY_DATA); if (originPublicKeyData == null) { synchronized (realDb) { originPublicKeyData = SshTunnelling.generateRsaKey(realDb); ((EntityLocal) originEntity).setAttribute(PUBLIC_KEY_DATA, originPublicKeyData); } } SshTunnelling.authorizePublicKey(fakeDb, originPublicKeyData); SshTunnelling.openRemoteForwardingTunnel(realDb, fakeDb, // on real (initiator/host) side "localhost", originPort, // on fake (target/new) side "localhost", originPort); } catch (Exception e) { log.warn("Unable to start DB forwarding from " + originEntity + " to " + this + ": " + e); log.debug("Unable to start DB forwarding from " + originEntity + " to " + this + ": " + e, e); Exceptions.propagateIfFatal(e); } // after this method (preStart) it otherwise acts as normal... }
From source file:org.obm.dbcp.MultiNodeDatabaseDriverConfigurationProvider.java
@Inject @VisibleForTesting//from ww w. ja v a2 s . c om MultiNodeDatabaseDriverConfigurationProvider(Set<DatabaseDriverConfiguration> drivers, MultiNodeDatabaseConfiguration databaseConfigurations) { super(drivers, Iterables.getFirst(databaseConfigurations.getDatabaseConfigurations().values(), null)); }
From source file:fr.mtlx.odm.model.Person.java
public String getFirstTelephoneNumber() { if (telephoneNumber != null) return Iterables.getFirst(telephoneNumber, null); return null; }
From source file:net.freifunk.autodeploy.firmware.FirmwareServiceImpl.java
@Override public Firmware findSupportedFirmware(final String firmwareString) { final Iterable<Firmware> matches = Iterables.filter(_configurators.keySet(), new Predicate<Firmware>() { @Override// ww w .j a v a 2s .c om public boolean apply(final Firmware firmware) { return firmware != null && firmware.getName().equals(firmwareString); } }); if (Iterables.size(matches) > 1) { throw new IllegalStateException("More than one firmware found: " + firmwareString); } return Iterables.getFirst(matches, null); }
From source file:io.jenkins.blueocean.service.embedded.UserStatePreloader.java
/** * {@inheritDoc}//from www . j a va 2 s . com */ @Override public String getStateJson() { BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null); try { User currentUser = User.current(); if (currentUser != null && organization != null) { return Export.toJson(new UserImpl(organization, currentUser)); } else { return ANONYMOUS; } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Unexpected error serializing active User object and adding to page preload state."); return ANONYMOUS; } }
From source file:com.google.devtools.build.lib.skyframe.PackageProgressReceiver.java
/** * Return the ordered pair of a consistent snapshot of the state, consisting of a human-readable * description of the progress achieved so far and a human readable description of the currently * running activities. The later always include the oldest loading package not finished loading. *//* w ww . j a v a 2s . co m*/ public synchronized Pair<String, String> progressState() { String progress = "" + packagesCompleted + " packages loaded"; StringBuffer activity = new StringBuffer(); if (pendingSet.size() > 0) { activity.append("currently loading: ").append(Iterables.getFirst(pendingSet, null).toString()); if (pendingSet.size() > 1) { activity.append(" ... (" + pendingSet.size() + " packages)"); } } return new Pair<String, String>(progress, activity.toString()); }
From source file:org.gradle.integtests.fixtures.AvailableJavaHomes.java
public static JavaInfo getAvailableJdk(final Spec<? super JvmInstallation> filter) { return Iterables.getFirst(getAvailableJdks(filter), null); }
From source file:com.google.idea.blaze.base.run.rulefinder.RuleFinder.java
@Nullable private RuleIdeInfo findRule(Project project, Predicate<RuleIdeInfo> predicate) { List<RuleIdeInfo> results = findRules(project, predicate); assert results.size() <= 1; return Iterables.getFirst(results, null); }
From source file:com.google.devtools.build.lib.server.RPCService.java
/** * Executes the request; returns Unix like return codes (0 means success). May * also throw arbitrary exceptions./*w w w.j a v a 2 s . c o m*/ */ public int executeRequest(List<String> request, OutErr outErr, long firstContactTime) throws Exception { if (shutdown != ShutdownMethod.NONE) { throw new IllegalStateException("Received request after shutdown."); } String command = Iterables.getFirst(request, ""); if (appCommand != null && command.equals("blaze")) { // an application request // Blocking is done in the client for AF_UNIX communications, so if blockForLock would block, // something went wrong int result = appCommand.exec(request.subList(1, request.size()), outErr, LockingMode.ERROR_OUT, "AF_UNIX client", firstContactTime); ShutdownMethod commandShutdown = appCommand.shutdown(); if (commandShutdown != ShutdownMethod.NONE) { // an application shutdown request shutdown(commandShutdown); } return result; } else { throw new UnknownCommandException(command); } }