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:brooklyn.networking.vclouddirector.PortForwarderVcloudDirector.java
@Override public HostAndPort openPortForwarding(HasNetworkAddresses targetVm, int targetPort, Optional<Integer> optionalPublicPort, Protocol protocol, Cidr accessingCidr) { String targetIp = Iterables .getFirst(Iterables.concat(targetVm.getPrivateAddresses(), targetVm.getPublicAddresses()), null); if (targetIp == null) { throw new IllegalStateException("Failed to open port-forwarding for machine " + targetVm + " because its " + "location has no target ip: " + targetVm); }//w ww . j a va2 s .c o m HostAndPort targetSide = HostAndPort.fromParts(targetIp, targetPort); return openPortForwarding(targetSide, optionalPublicPort, protocol, accessingCidr); }
From source file:com.googlecode.blaisemath.graph.mod.layout.StaticSpringLayout.java
/** * Add leaf nodes that are adjacent to the given positions. * @param og the graph//from ww w .j a va2 s. c o m * @param pos current positions * @param distScale distance between noddes * @param <C> graph node type */ public static <C> void addLeafNodes(OptimizedGraph<C> og, Map<C, Point2D.Double> pos, double distScale) { double nomSz = distScale / 2; Set<C> leafs = og.getLeafNodes(); int n = leafs.size(); if (n > 0) { Rectangle2D bounds = Points.boundingBox(pos.values(), distScale); if (bounds == null) { // no points exist, so must be all pairs double sqSide = nomSz * Math.sqrt(n); Rectangle2D pairRegion = new Rectangle2D.Double(-sqSide, -sqSide, 2 * sqSide, 2 * sqSide); Set orderedLeafs = orderByAdjacency(leafs, og); addPointsToBox(orderedLeafs, pairRegion, pos, nomSz, true); } else { // add close to their neighboring point Set<C> cores = Sets.newHashSet(); Set<C> pairs = Sets.newHashSet(); for (C o : leafs) { C nbr = og.getNeighborOfLeaf(o); if (leafs.contains(nbr)) { pairs.add(o); pairs.add(nbr); } else { cores.add(nbr); } } for (C o : cores) { Set<C> leaves = og.getLeavesAdjacentTo(o); Point2D.Double ctr = pos.get(o); double r = nomSz; double theta = Math.atan2(ctr.y, ctr.x); if (leaves.size() == 1) { pos.put(Iterables.getFirst(leaves, null), new Point2D.Double( ctr.getX() + r * Math.cos(theta), ctr.getY() + r * Math.sin(theta))); } else { double th0 = theta - Math.PI / 3; double dth = (2 * Math.PI / 3) / (leaves.size() - 1); for (C l : leaves) { pos.put(l, new Point2D.Double(ctr.getX() + r * Math.cos(th0), ctr.getY() + r * Math.sin(th0))); th0 += dth; } } } // put the pairs to the right side double area = n * nomSz * nomSz; double ht = Math.min(bounds.getHeight(), 2 * Math.sqrt(area)); double wid = area / ht; Rectangle2D pairRegion = new Rectangle2D.Double(bounds.getMaxX() + .1 * bounds.getWidth(), bounds.getCenterY() - ht / 2, wid, ht); Set orderedPairs = orderByAdjacency(pairs, og); addPointsToBox(orderedPairs, pairRegion, pos, nomSz, true); } } }
From source file:ratpack.launch.LaunchConfigFactory.java
/** * Delegates to {@link #createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)}, after trying to find the config properties file. <p> The {@code * overrideProperties} are queried for the {@link #CONFIG_RESOURCE_PROPERTY} (defaulting to {@link #CONFIG_RESOURCE_DEFAULT}). The {@code classLoader} is asked for the classpath resource with this * name. <p> If the resource DOES NOT exist, {@link #createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)} is called with the current JVM user dir as * the {@code baseDir} and {@code null} as the {@code configFile}. <p> If the resource DOES exist, {@link #createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)} is called with that file resource as the {@code configFile}, and its parent directory as the {@code baseDir}. * * @param classLoader The classloader to use to find the properties file * @param overrideProperties The properties that provide the path to the config file resource, and any overrides * @param defaultProperties The default properties to use when a property is omitted * @return A launch config/* w ww . j a va 2s . c o m*/ */ public static LaunchConfig createFromProperties(ClassLoader classLoader, Properties overrideProperties, Properties defaultProperties) { String configResourceValue = overrideProperties.getProperty(CONFIG_RESOURCE_PROPERTY, CONFIG_RESOURCE_DEFAULT); URL configResourceUrl = classLoader.getResource(configResourceValue); Path configPath; Path baseDir; if (configResourceUrl == null) { configPath = Paths.get(configResourceValue); if (!configPath.isAbsolute()) { configPath = Paths.get(System.getProperty("user.dir"), configResourceValue); } baseDir = configPath.getParent(); } else { configPath = resourceToPath(configResourceUrl); baseDir = configPath.getParent(); if (baseDir == null && configPath.getFileSystem().provider() instanceof ZipFileSystemProvider) { baseDir = Iterables.getFirst(configPath.getFileSystem().getRootDirectories(), null); } if (baseDir == null) { throw new LaunchException("Cannot determine base dir given config resource: " + configPath); } } return createFromFile(classLoader, baseDir, configPath, overrideProperties, defaultProperties); }
From source file:gov.nih.nci.firebird.test.data.AnnualRegistrationBuilder.java
protected AnnualRegistrationBuilder(TargetGridResources gridResources, TestDataLoader dataLoader, FirebirdUser investigator, AnnualRegistrationConfiguration configuration) { super(gridResources, dataLoader); this.profile = Iterables.getFirst(investigator.getActiveProfiles(), null); registration.setProfile(profile);/*from ww w . jav a 2 s. c o m*/ registration.setConfiguration(configuration); registration.configureForms(); withStatus(RegistrationStatus.IN_PROGRESS); withType(AnnualRegistrationType.INITIAL); withStatusDate(new Date()); }
From source file:com.google.gerrit.util.http.testutil.FakeHttpServletResponse.java
@Override public String getHeader(String name) { return Iterables.getFirst(headers.get(checkNotNull(name.toLowerCase())), null); }
From source file:com.eucalyptus.objectstorage.pipeline.ObjectStorageRESTPipeline.java
/** * Is ObjectSTorage domainname a subdomain of the host header host. If so, then it is likely a bucket prefix. * Includes checksd for Walrus domain (walrus.myserver.com) for legacy support * But, since S3 buckets can include '.' can't just parse on '.'s * @param fullHostHeader//from ww w . j av a 2s .co m * @return */ private boolean maybeBucketHostedStyle(String fullHostHeader) { try { return DomainNames .absolute( Name.fromString(Iterables.getFirst(hostSplitter.split(fullHostHeader), fullHostHeader))) .subdomain(DomainNames.externalSubdomain(ObjectStorage.class)) || DomainNames .absolute(Name.fromString( Iterables.getFirst(hostSplitter.split(fullHostHeader), fullHostHeader))) .subdomain(Name.fromString("walrus." + DomainNames.externalSubdomain().toString())); } catch (Exception e) { LOG.error("Error parsing domain name from hostname: " + fullHostHeader, e); return false; } }
From source file:eu.interedition.collatex.medite.Matches.java
public SortedSet<SortedSet<VertexMatch.WithTokenIndex>> findMaximalUniqueMatches() { final List<SortedSet<VertexMatch.WithTokenIndex>> allMatches = Lists.newArrayList(this); final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> maximalUniqueMatches = Sets .newTreeSet(VertexMatch.<VertexMatch.WithTokenIndex>setComparator()); while (true) { SortedSet<VertexMatch.WithTokenIndex> nextMum = null; SortedSet<VertexMatch.WithTokenIndex> candidate = null; for (SortedSet<VertexMatch.WithTokenIndex> successor : allMatches) { if (candidate == null) { continue; }//from ww w . j ava 2s .co m if (candidate.size() > successor.size() || candidate.first().token == successor.first().token) { nextMum = candidate; break; } candidate = successor; } if (nextMum == null) { nextMum = Iterables.getFirst(allMatches, null); } if (nextMum == null) { break; } Preconditions.checkState(maximalUniqueMatches.add(nextMum), "Duplicate MUM"); Iterables.removeIf(allMatches, VertexMatch.filter( new IntegerRangeSet( Range.closed(nextMum.first().vertexRank, nextMum.last().vertexRank)), new IntegerRangeSet(Range.closed(nextMum.first().token, nextMum.last().token)))); } return maximalUniqueMatches; }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationConfigurationServiceBean.java
@SuppressWarnings("unchecked") @Override//from w ww .ja va 2 s . c o m public AnnualRegistrationConfiguration getCurrentConfiguration() { return (AnnualRegistrationConfiguration) Iterables.getFirst(getSession() .createCriteria(AnnualRegistrationConfiguration.class).addOrder(Order.desc("timestamp")).list(), null); }
From source file:eu.interedition.collatex.nmerge.mvd.Variant.java
/** * Is this variant entirely contained within another variant? * We just check if we are within the bounds of the other variant. * No need to compare the text of the two variants - the versions * must be the same, so within the bounds means that the same text * will occur./* w w w. j a v a 2 s . co m*/ * * @param other the other variant to compare it to * @return true if we are within other, false otherwise */ public boolean isWithin(Variant<T> other) { // these tests will mostly fail // so we can avoid the main computation if (length < other.length && startIndex >= other.startIndex && endIndex <= other.endIndex && this.versions.equals(other.versions)) { // another quick test to shortcut the computation if (startIndex == other.startIndex && (startOffset < other.startOffset || (startOffset - other.startOffset) + length > other.length)) { return false; } else { // OK, we have some work to do ... // find the start of this variant in other int offset = other.startOffset; int index = other.startIndex; Match<T> p = collation.getMatches().get(index); int i = 0; Witness followV = Iterables.getFirst(versions, null); while (i < other.length) { if (offset == p.length()) { index = collation.next(index + 1, followV); p = collation.getMatches().get(index); offset = 0; } else { offset++; i++; } // found start? if (index == startIndex && offset == startOffset) { return other.length - i >= length; } } } } return false; }
From source file:com.blackducksoftware.bdio.model.ExternalIdentifier.java
@Nullable public String getSuiteComponentId() { return Iterables.getFirst(getBdSuiteId(), null); }