List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.jclouds.cloudstack.functions.CreateFirewallRulesForIP.java
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<FirewallRule>of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallClient().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response);//www . j a va2 s . co m } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule>apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.StructBase.java
@Override public int size() { return Iterables.size(getFieldNames()); }
From source file:net.freifunk.autodeploy.selenium.HeadlessDriver.java
@Override protected void get(final URL url) { final String userInfo = url.getUserInfo(); if (userInfo != null) { final Iterable<String> parts = Splitter.on(':').split(userInfo); Preconditions.checkState(Iterables.size(parts) == 2, "Expecting format user:password for userinfo."); final String username = Iterables.get(parts, 0); final String password = Iterables.getLast(parts); _headlessDriverCredentialsProvider.set(username, password); } else {/*w w w .j av a 2 s . c o m*/ _headlessDriverCredentialsProvider.reset(); } super.get(url); }
From source file:org.calrissian.mango.collect.FluentCloseableIterable.java
/** * Returns the number of elements in this fluent iterable. */// ww w. j av a2 s .c o m public final int size() { return Iterables.size(this); }
From source file:org.jboss.hal.client.deployment.ContentParser.java
private ContentEntry contentEntry(ModelNode node) { String path = node.get(PATH).asString(); Iterable<String> segments = Splitter.on('/').omitEmptyStrings().split(path); ContentEntry contentEntry = new ContentEntry(); contentEntry.name = Iterables.getLast(segments); contentEntry.path = path;/*from w w w . j a v a2 s . c om*/ contentEntry.depth = Iterables.size(segments); contentEntry.directory = node.hasDefined(DIRECTORY) && node.get(DIRECTORY).asBoolean(); contentEntry.fileSize = node.hasDefined(FILE_SIZE) ? node.get(FILE_SIZE).asLong() : 0; return contentEntry; }
From source file:univ.bigdata.course.pagerank.JavaPageRank.java
public static void calculatePageRank(JavaRDD<String> rdd, int iteration_number) throws Exception { // Loads in input file. It should be in format of: // URL neighbor URL // URL neighbor URL // URL neighbor URL // ...//from w w w.ja v a2s .c o m JavaRDD<String> lines = rdd; // Loads all URLs from input file and initialize their neighbors. JavaPairRDD<String, Iterable<String>> links = lines.mapToPair(new PairFunction<String, String, String>() { @Override public Tuple2<String, String> call(String s) { String[] parts = SPACES.split(s); return new Tuple2<>(parts[0], parts[1]); } }).distinct().groupByKey().cache(); // Loads all URLs with other URL(s) link to from input file and initialize ranks of them to one. JavaPairRDD<String, Double> ranks = links.mapValues(new Function<Iterable<String>, Double>() { @Override public Double call(Iterable<String> rs) { return 1.0; } }); // Calculates and updates URL ranks continuously using PageRank algorithm. for (int current = 0; current < iteration_number; current++) { // Calculates URL contributions to the rank of other URLs. JavaPairRDD<String, Double> contribs = links.join(ranks).values() .flatMapToPair(new PairFlatMapFunction<Tuple2<Iterable<String>, Double>, String, Double>() { @Override public Iterable<Tuple2<String, Double>> call(Tuple2<Iterable<String>, Double> s) { int urlCount = Iterables.size(s._1); List<Tuple2<String, Double>> results = new ArrayList<>(); for (String n : s._1) { results.add(new Tuple2<>(n, s._2() / urlCount)); } return results; } }); // Re-calculates URL ranks based on neighbor contributions. ranks = contribs.reduceByKey(new Sum()).mapValues(new Function<Double, Double>() { @Override public Double call(Double sum) { return 0.15 + sum * 0.85; } }); } JavaPairRDD<Double, String> sortedRanks = ranks .mapToPair(new PairFunction<Tuple2<String, Double>, Double, String>() { @Override public Tuple2<Double, String> call(Tuple2<String, Double> t) { return new Tuple2<Double, String>(t._2, t._1); } }).sortByKey(false); // Collects all URL ranks and dump them to console. List<Tuple2<Double, String>> output = sortedRanks.takeOrdered(100, PageRankComperator.VALUE_COMP); for (Tuple2<?, ?> tuple : output) { System.out.println(tuple._2() + " has rank: " + tuple._1() + "."); } }
From source file:org.jclouds.aws.ec2.compute.suppliers.CallForImages.java
public Iterable<Image> call() { logger.debug(">> providing images"); Builder<String, DescribeImagesOptions> builder = ImmutableMap.builder(); for (String region : regions) builder.put(region, filters(filter)); Iterable<Entry<String, DescribeImagesOptions>> queries = builder.build().entrySet(); Iterable<Image> returnVal = filter(transform(describer.apply(queries), parser), Predicates.notNull()); if (logger.isDebugEnabled()) logger.debug("<< images(%s)", Iterables.size(returnVal)); return returnVal; }
From source file:org.jclouds.examples.rackspace.clouddns.DeleteRecords.java
private void deleteRecords(Domain domain) throws TimeoutException { System.out.format("Delete Records%n"); Set<RecordDetail> recordDetails = dnsApi.getRecordApi(domain.getId()).listByType("TXT").concat().toSet(); Iterable<String> recordIds = Iterables.transform(recordDetails, GET_RECORD_ID); awaitComplete(dnsApi, dnsApi.getRecordApi(domain.getId()).delete(recordIds)); System.out.format(" Deleted %s records", Iterables.size(recordDetails)); }
From source file:msi.gaml.descriptions.ValidationContext.java
public boolean hasInternalErrors() { return !isEmpty() && Iterables.size(getInternalErrors()) > 0; }
From source file:com.cognifide.aet.job.common.comparators.accessibility.report.AccessibilityReportGenerator.java
private int filterAndCount(boolean filter, IssueType type) { int result = 0; Iterable<AccessibilityIssue> issues = Iterables.filter(nonExcludedIssues, new IssueTypePredicate(type)); if (filter) { Iterables.removeAll(nonExcludedIssues, Lists.newArrayList(issues)); Iterable<AccessibilityIssue> excluded = Iterables.filter(excludedIssues, new IssueTypePredicate(type)); Iterables.removeAll(excludedIssues, Lists.newArrayList(excluded)); } else {/* ww w . j a va 2 s. c o m*/ result = Iterables.size(issues); } return result; }