List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:ec.tss.xml.sa.XmlSaProcessing.java
@Override public void copy(SaProcessing t) { timeStamp = new Date(); int n = t.size(); if (n > 0) { Map<ISaSpecification, String> dic = new HashMap<>(); XmlSaItem[] xitems = new XmlSaItem[n]; List<AbstractXmlSaSpecification> xdspecs = new ArrayList<>(); int i = 0; int ispec = 1; for (SaItem item : t) { XmlSaItem xitem = new XmlSaItem(); xitem.series = new XmlTs(); if (item.getMoniker().isAnonymous()) xitem.series.copy(new TsInformation(item.getTs(), TsInformationType.All)); else if (item.getStatus() == SaItem.Status.Unprocessed) xitem.series.copy(new TsInformation(item.getTs(), TsInformationType.Definition)); else/* www . j ava 2 s . co m*/ xitem.series.copy(new TsInformation(item.getTs().freeze(), TsInformationType.All)); xitem.priority = item.getPriority(); xitem.quality = item.getQuality(); xitem.policy = item.getEstimationPolicy(); xitem.status = item.getStatus(); ISaSpecification rspec = item.getPointSpecification(), dspec = item.getDomainSpecification(); if (rspec != null) xitem.spec = AbstractXmlSaSpecification.create(rspec); if (item.getEstimationSpecification() != item.getDomainSpecification()) xitem.espec = AbstractXmlSaSpecification.create(item.getEstimationSpecification()); if (dspec != null) { String name; if (!dic.containsKey(dspec)) { name = "spec" + Integer.toString(ispec++); dic.put(dspec, name); AbstractXmlSaSpecification xdspec = AbstractXmlSaSpecification.create(dspec); xdspec.name = name; xdspecs.add(xdspec); } else name = dic.get(dspec); xitem.defaultMethod = name; } xitems[i++] = xitem; } items = xitems; defaultMethods = Iterables.toArray(xdspecs, AbstractXmlSaSpecification.class); } }
From source file:org.glowroot.local.ui.AdminJsonService.java
@RequiresNonNull("instrumentation") private int reweaveInternal() throws Exception { List<InstrumentationConfig> configs = configService.getInstrumentationConfigs(); adviceCache.updateAdvisors(configs, false); Set<String> classNames = Sets.newHashSet(); for (InstrumentationConfig config : configs) { classNames.add(config.className()); }/*from w w w . j a v a 2 s .com*/ Set<Class<?>> classes = Sets.newHashSet(); List<Class<?>> possibleNewReweavableClasses = getExistingSubClasses(classNames); // need to remove these classes from AnalyzedWorld, otherwise if a subclass and its parent // class are both in the list and the subclass is re-transformed first, it will use the // old cached AnalyzedClass for its parent which will have the old AnalyzedMethod advisors List<Class<?>> existingReweavableClasses = analyzedWorld.getClassesWithReweavableAdvice(true); analyzedWorld.removeClasses(possibleNewReweavableClasses); classes.addAll(existingReweavableClasses); classes.addAll(possibleNewReweavableClasses); if (classes.isEmpty()) { return 0; } instrumentation.retransformClasses(Iterables.toArray(classes, Class.class)); List<Class<?>> updatedReweavableClasses = analyzedWorld.getClassesWithReweavableAdvice(false); // all existing reweavable classes were woven int count = existingReweavableClasses.size(); // now add newly reweavable classes for (Class<?> possibleNewReweavableClass : possibleNewReweavableClasses) { if (updatedReweavableClasses.contains(possibleNewReweavableClass) && !existingReweavableClasses.contains(possibleNewReweavableClass)) { count++; } } return count; }
From source file:org.grouplens.lenskit.eval.EvalProject.java
/** * Execute a sequence of targets.//from w w w. j a v a 2 s . c o m * @param names The targets to execute. */ @SuppressWarnings("rawtypes") public void executeTargets(List<String> names) { String[] nameArray = Iterables.toArray(names, String.class); Vector targets = antProject.topoSort(nameArray, antProject.getTargets(), false); antProject.executeSortedTargets(targets); }
From source file:com.shopzilla.hadoop.repl.HadoopREPL.java
@Override protected void evaluate(final String input) throws ExitSignal { popHistory();//from w w w . j ava 2 s .c om final Iterable<String> inputParts = ARG_SPLITTER.limit(2).split(input); if (Iterables.isEmpty(inputParts)) { // Do nothing } else { final String command = Iterables.get(inputParts, 0).toLowerCase(); if (commandMappings.containsKey(call(command))) { commandMappings.get(call(command)).execute( new CommandInvocation(command, Iterables .toArray(ARG_SPLITTER.split(Iterables.get(inputParts, 1, "")), String.class)), sessionState); } else { sessionState.output("Unknown command \"%s\"", command); } pushHistory(input); } }
From source file:org.sonarsource.sonarlint.core.container.ComponentContainer.java
/** * @since 3.5/*from w w w. ja v a2s .c o m*/ */ @Override public ComponentContainer add(Object... objects) { for (Object object : objects) { if (object instanceof ComponentAdapter) { addPicoAdapter((ComponentAdapter) object); } else if (object instanceof Iterable) { add(Iterables.toArray((Iterable) object, Object.class)); } else { addSingleton(object); } } return this; }
From source file:com.google.cloud.datastore.BaseDatastoreBatchWriter.java
@SuppressWarnings("unchecked") @Override//w ww . j a va 2s.c o m public final List<Entity> put(FullEntity<?>... entities) { validateActive(); List<IncompleteKey> incompleteKeys = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity<?> entity : entities) { IncompleteKey key = entity.getKey(); Preconditions.checkArgument(key != null, "Entity must have a key"); if (!(key instanceof Key)) { incompleteKeys.add(key); } } Iterator<Key> allocated; if (!incompleteKeys.isEmpty()) { IncompleteKey[] toAllocate = Iterables.toArray(incompleteKeys, IncompleteKey.class); allocated = getDatastore().allocateId(toAllocate).iterator(); } else { allocated = Collections.emptyIterator(); } List<Entity> answer = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity<?> entity : entities) { if (entity.getKey() instanceof Key) { putInternal((FullEntity<Key>) entity); answer.add(Entity.convert((FullEntity<Key>) entity)); } else { Entity entityWithAllocatedId = Entity.newBuilder(allocated.next(), entity).build(); putInternal(entityWithAllocatedId); answer.add(entityWithAllocatedId); } } return answer; }
From source file:org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.java
static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName, final SchemaContext schemaContext, final boolean verboseClassComments) { final StringBuilder sb = new StringBuilder(); final String nodeDescription = encodeAngleBrackets(schemaNode.getDescription()); final String formattedDescription = YangTextTemplate.formatToParagraph(nodeDescription, 0); if (!Strings.isNullOrEmpty(formattedDescription)) { sb.append(formattedDescription); sb.append(NEW_LINE);//from w ww.j a v a2 s .c o m } if (verboseClassComments) { final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode); final StringBuilder linkToBuilderClass = new StringBuilder(); final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class); final String className = namespace[namespace.length - 1]; if (hasBuilderClass(schemaNode)) { linkToBuilderClass.append(className); linkToBuilderClass.append("Builder"); } sb.append("<p>"); sb.append("This class represents the following YANG schema fragment defined in module <b>"); sb.append(module.getName()); sb.append("</b>"); sb.append(NEW_LINE); sb.append("<pre>"); sb.append(NEW_LINE); sb.append(encodeAngleBrackets(yangTemplateForNode.render(schemaNode).body())); sb.append("</pre>"); sb.append(NEW_LINE); sb.append("The schema path to identify an instance is"); sb.append(NEW_LINE); sb.append("<i>"); sb.append(YangTextTemplate.formatSchemaPath(module.getName(), schemaNode.getPath().getPathFromRoot())); sb.append("</i>"); sb.append(NEW_LINE); if (hasBuilderClass(schemaNode)) { sb.append(NEW_LINE); sb.append("<p>To create instances of this class use " + "{@link " + linkToBuilderClass + "}."); sb.append(NEW_LINE); sb.append("@see "); sb.append(linkToBuilderClass); sb.append(NEW_LINE); if (schemaNode instanceof ListSchemaNode) { final List<QName> keyDef = ((ListSchemaNode) schemaNode).getKeyDefinition(); if (keyDef != null && !keyDef.isEmpty()) { sb.append("@see "); sb.append(className); sb.append("Key"); } sb.append(NEW_LINE); } } } return replaceAllIllegalChars(sb); }
From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java
@Override public PropertyNode add(final String key, final Byte value, final Collection<Attribute> attributes) { return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class)); }
From source file:com.android.build.gradle.integration.common.fixture.BuildModel.java
/** * Returns a project model for each sub-project; * * @param connection the opened ProjectConnection * @param action the build action to gather the model * @param modelLevel whether to emulate an older IDE (studio 1.0) querying the model. *//*from w w w. ja v a2s . co m*/ @NonNull private <K, V> Map<K, V> buildModel(@NonNull ProjectConnection connection, @NonNull BuildAction<Map<K, V>> action, int modelLevel) { BuildActionExecuter<Map<K, V>> executor = connection.action(action); List<String> arguments = Lists.newArrayListWithCapacity(5); arguments.add("-P" + AndroidProject.PROPERTY_BUILD_MODEL_ONLY + "=true"); arguments.add("-P" + AndroidProject.PROPERTY_INVOKED_FROM_IDE + "=true"); switch (modelLevel) { case AndroidProject.MODEL_LEVEL_0_ORIGNAL: // nothing. break; case AndroidProject.MODEL_LEVEL_2_DEP_GRAPH: arguments.add("-P" + AndroidProject.PROPERTY_BUILD_MODEL_ONLY_VERSIONED + "=" + modelLevel); // intended fall-through case AndroidProject.MODEL_LEVEL_1_SYNC_ISSUE: arguments.add("-P" + AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED + "=true"); break; default: throw new RuntimeException("Unsupported ModelLevel"); } setJvmArguments(executor); executor.withArguments(Iterables.toArray(arguments, String.class)); executor.setStandardOutput(System.out); executor.setStandardError(System.err); return executor.run(); }
From source file:com.google.cloud.dataflow.sdk.testing.CoderProperties.java
/** * Verifies that for the given {@code Coder<Iterable<T>>}, * and value of type {@code Iterable<T>}, encoding followed by decoding yields an * equal value of type {@code Collection<T>}, in the given {@code Coder.Context}. *///from w ww. jav a 2 s . com @SuppressWarnings("unchecked") public static <T, IterableT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext( Coder<IterableT> coder, Coder.Context context, IterableT value) throws Exception { Iterable<T> result = decodeEncode(coder, context, value); // Matchers.contains() requires at least one element if (Iterables.isEmpty(value)) { assertThat(result, emptyIterable()); } else { // This is the only Matchers.contains() overload that takes literal values assertThat(result, contains((T[]) Iterables.toArray(value, Object.class))); } }