List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.immutables.sequence.Sequence.java
/** * Returns the number of elements in this fluent iterable. * @return the int/*from w ww . j a v a 2 s . c om*/ */ public final int size() { return Iterables.size(iterable); }
From source file:io.druid.indexer.IndexGeneratorJob.java
public boolean run() { try {/*from ww w . j a v a2s. c o m*/ Job job = Job.getInstance(new Configuration(), String.format("%s-index-generator-%s", config.getDataSource(), config.getIntervals())); job.getConfiguration().set("io.sort.record.percent", "0.23"); JobHelper.injectSystemProperties(job); config.addJobProperties(job); job.setMapperClass(IndexGeneratorMapper.class); job.setMapOutputValueClass(BytesWritable.class); SortableBytes.useSortableBytesAsMapOutputKey(job); int numReducers = Iterables.size(config.getAllBuckets().get()); if (numReducers == 0) { throw new RuntimeException("No buckets?? seems there is no data to index."); } if (config.getSchema().getTuningConfig().getUseCombiner()) { job.setCombinerClass(IndexGeneratorCombiner.class); job.setCombinerKeyGroupingComparatorClass(BytesWritable.Comparator.class); } job.setNumReduceTasks(numReducers); job.setPartitionerClass(IndexGeneratorPartitioner.class); setReducerClass(job); job.setOutputKeyClass(BytesWritable.class); job.setOutputValueClass(Text.class); job.setOutputFormatClass(IndexGeneratorOutputFormat.class); FileOutputFormat.setOutputPath(job, config.makeIntermediatePath()); config.addInputPaths(job); // hack to get druid.processing.bitmap property passed down to hadoop job. // once IndexIO doesn't rely on globally injected properties, we can move this into the HadoopTuningConfig. final String bitmapProperty = "druid.processing.bitmap.type"; final String bitmapType = HadoopDruidIndexerConfig.properties.getProperty(bitmapProperty); if (bitmapType != null) { for (String property : new String[] { "mapreduce.reduce.java.opts", "mapreduce.map.java.opts" }) { // prepend property to allow overriding using hadoop.xxx properties by JobHelper.injectSystemProperties above String value = Strings.nullToEmpty(job.getConfiguration().get(property)); job.getConfiguration().set(property, String.format("-D%s=%s %s", bitmapProperty, bitmapType, value)); } } config.intoConfiguration(job); JobHelper.setupClasspath(JobHelper.distributedClassPath(config.getWorkingPath()), job); job.submit(); log.info("Job %s submitted, status available at %s", job.getJobName(), job.getTrackingURL()); boolean success = job.waitForCompletion(true); Counter invalidRowCount = job.getCounters() .findCounter(HadoopDruidIndexerConfig.IndexJobCounters.INVALID_ROW_COUNTER); jobStats.setInvalidRowCount(invalidRowCount.getValue()); return success; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:brooklyn.location.waratek.WaratekMachineLocation.java
public int getCurrentJvcCount() { return jvm.getCurrentSize() - Iterables.size(jvm.getAvailableJvcs()); }
From source file:org.asoem.greyfish.core.space.WalledPointSpace.java
@Override public String toString() { return "Tiled Space: dim=" + width + "x" + height + "; oc=" + Iterables.size(getObjects()); }
From source file:org.apache.hive.service.cli.session.SessionManager.java
private void registerActiveSesssionMetrics(Metrics metrics) { MetricsVariable<Integer> activeSessionCnt = new MetricsVariable<Integer>() { @Override/* w w w.ja v a 2 s .c o m*/ public Integer getValue() { Iterable<HiveSession> filtered = Iterables.filter(getSessions(), new Predicate<HiveSession>() { @Override public boolean apply(HiveSession hiveSession) { return hiveSession.getNoOperationTime() == 0L; } }); return Iterables.size(filtered); } }; MetricsVariable<Integer> activeSessionTime = new MetricsVariable<Integer>() { @Override public Integer getValue() { long sum = 0; long currentTime = System.currentTimeMillis(); for (HiveSession s : getSessions()) { if (s.getNoOperationTime() == 0L) { sum += currentTime - s.getLastAccessTime(); } } // in case of an overflow return -1 return (int) sum != sum ? -1 : (int) sum; } }; metrics.addGauge(MetricsConstant.HS2_ACTIVE_SESSIONS, activeSessionCnt); metrics.addRatio(MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, activeSessionTime, activeSessionCnt); }
From source file:edu.umn.msi.tropix.proteomics.sequest.impl.SequestJobProcessorImpl.java
@Override protected void doPostprocessing() { if (wasCompletedNormally()) { LOG.debug("postprocess called for sequest job created"); final Iterable<String> resources = getStagingDirectory().getResourceNames(null); Iterable<String> outResources = Iterables.filter(resources, StringPredicates.endsWith("out")); final Iterable<String> dtaResources = Iterables.filter(resources, StringPredicates.endsWith("dta")); final long outNum = Iterables.size(outResources), dtaNum = Iterables.size(dtaResources); if (outNum != dtaNum) { boolean failJob = false; if ((outNum + allowedDroppedFiles) < dtaNum) { failJob = true;/*from w w w . jav a2s . c o m*/ } LOG.warn("Invalid number of output files created -- expected " + dtaNum + " found " + outNum + " failing job? " + failJob); if (failJob) { throw new IllegalStateException("Failed to produce the correct number of files."); } } if (includeDta) { outResources = Iterables.concat(outResources, dtaResources); } if (includeParams) { outResources = Iterables.concat(outResources, Arrays.asList(PARAMS_PATH)); } final Iterable<InputContext> inputContexts = Iterables.transform(outResources, new Function<String, InputContext>() { public InputContext apply(final String resource) { return getStagingDirectory().getInputContext(resource); } }); final OutputStream resultsStream = getResourceTracker().newStream(); try { zipUtils.zipContextsToStream(inputContexts, outResources, resultsStream); } finally { IO_UTILS.closeQuietly(resultsStream); } } }
From source file:org.jclouds.ec2.compute.options.EC2TemplateOptions.java
/** * Specifies the security groups to be used for nodes with this template *//*from ww w . j av a 2 s . co m*/ public EC2TemplateOptions securityGroups(Iterable<String> groupNames) { checkArgument(Iterables.size(groupNames) > 0, "you must specify at least one security group"); for (String groupId : groupNames) checkNotNull(emptyToNull(groupId), "all security groups must be non-empty"); this.groupNames = ImmutableSet.copyOf(groupNames); return this; }
From source file:com.synflow.cx.internal.validation.StructuralValidator.java
@Check public void checkDuplicateDeclarations(Variable variable) { if (variable.getName() == null) { // name is null when the variable declaration is incomplete return;//from w w w. ja v a 2 s .co m } EObject context = variable.eContainer(); QualifiedName name; if (context instanceof StatementVariable) { // local variable name = QualifiedName.create(variable.getName()); } else { // not a local variable context = EcoreUtil2.getContainerOfType(variable, Module.class); name = nameProvider.getFullyQualifiedName(variable); } IScope scope = scopeProvider.getScope(context, Literals.VAR_REF__VARIABLE); Iterable<IEObjectDescription> it = scope.getElements(name); int n = Iterables.size(it); if (n > 1) { error("Duplicate variable declaration '" + variable.getName() + "'", variable, Literals.VARIABLE__NAME, ERR_DUPLICATE_DECLARATIONS); } }
From source file:org.apache.directory.server.dhcp.messages.HardwareAddress.java
/** * Parses a string representation of a hardware address. * Valid: 1/11:22:33:44:55:66 (toString()) * Valid: Ethernet/11:22:33:44:55:66//from w ww . j ava 2 s . c om * Valid: 11:22:33:44:55:66 (defaults to Ethernet) * * @param text * @return HardwareAddress */ @Nonnull public static HardwareAddress fromString(@Nonnull String text) { int idx = text.indexOf('/'); HardwareAddressType hardwareAddressType = HardwareAddressType.Ethernet; if (idx != -1) { String hardwareAddressTypeText = text.substring(0, idx); try { int hardwareAddressTypeCode = Integer.parseInt(hardwareAddressTypeText); hardwareAddressType = HardwareAddressType.forCode(hardwareAddressTypeCode); } catch (NumberFormatException e) { // This will throw IllegalArgumentException, which is roughly what we want. hardwareAddressType = HardwareAddressType.valueOf(hardwareAddressTypeText); } text = text.substring(idx + 1); } CharMatcher separator = CharMatcher.BREAKING_WHITESPACE.or(CharMatcher.anyOf(":-")); Iterable<String> parts = Splitter.on(separator).omitEmptyStrings().trimResults().split(text); int i = 0; byte[] out = new byte[Iterables.size(parts)]; for (String part : parts) out[i++] = (byte) Integer.parseInt(part, 16); return new HardwareAddress(hardwareAddressType.getCode(), (short) out.length, out); }
From source file:brooklyn.location.waratek.WaratekMachineLocation.java
public int getAvailableJvcCount() { return Iterables.size(jvm.getAvailableJvcs()) + (getMaxSize() - jvm.getCurrentSize()); }