List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:eu.interedition.text.repository.JdbcStore.java
@Override public <R> R annotations(AnnotationsCallback<R> cb, Iterable<Long> ids) { try {/*w ww . j a va 2s . co m*/ if (selectAnnotations == null) { selectAnnotations = connection.prepareStatement("select " + "a.id, a.anno_data, at.text_id, at.range_start, at.range_end " + "from table(id bigint = ?) ai " + "join interedition_text_annotation a on ai.id = a.id " + "left join interedition_text_annotation_target at on a.id = at.annotation_id " + "order by a.id asc, at.text_id asc, at.range_start asc, at.range_end desc"); } selectAnnotations.setObject(1, Iterables.toArray(ids, Long.class)); return withAnnotationQuery(selectAnnotations, cb); } catch (SQLException e) { throw Throwables.propagate(e); } }
From source file:it.f2informatica.webapp.controller.ConsultantController.java
@RequestMapping(value = "/save-languages", method = POST) public String saveLanguages(@ModelAttribute("consultantModel") ConsultantModel consultantModel, @ModelAttribute("consultantId") String consultantId) { LanguageModel[] languages = Iterables.toArray(consultantModel.getLanguages(), LanguageModel.class); consultantService.addLanguages(languages, consultantId); return "redirect:/consultant/profile"; }
From source file:com.inmobi.grill.cli.commands.GrillFactCommands.java
@CliCommand(value = "fact list partitions", help = "get all partitions associated with fact") public String getAllPartitionsOfFact(@CliOption(key = { "", "table" }, mandatory = true, help = "<table> <storageName> [<list>]") String specPair) { Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair); String[] pair = Iterables.toArray(parts, String.class); if (pair.length == 2) { List<XPartition> partitions = client.getAllPartitionsOfFact(pair[0], pair[1]); return FormatUtils.formatPartitions(partitions); }/*w w w . j a v a 2 s . c om*/ if (pair.length == 3) { List<XPartition> partitions = client.getAllPartitionsOfFact(pair[0], pair[1], pair[3]); return FormatUtils.formatPartitions(partitions); } return "Syntax error, please try in following " + "format. fact list partitions <table> <storage> [partition values]"; }
From source file:com.b2international.commons.TokenReplacer.java
protected String[] extractArgs(final String tokenName, final String args) { if (args.isEmpty()) { return EMPTY_STRING_ARRAY; }//from w w w.j a v a 2 s.c o m checkArgumentsAreValid(tokenName, args); String[] argsResult = Iterables.toArray(Splitter.on(argsSep).trimResults().split(args), String.class); return argsResult; }
From source file:org.openqa.selenium.remote.ErrorHandler.java
private Throwable rebuildServerError(Map<String, Object> rawErrorData, int responseStatus) { if (!rawErrorData.containsKey(CLASS) && !rawErrorData.containsKey(STACK_TRACE)) { // Not enough information for us to try to rebuild an error. return null; }/*ww w .j av a2 s .co m*/ Throwable toReturn = null; String message = (String) rawErrorData.get(MESSAGE); Class<?> clazz = null; // First: allow Remote Driver to specify the Selenium Server internal exception if (rawErrorData.containsKey(CLASS)) { String className = (String) rawErrorData.get(CLASS); try { clazz = Class.forName(className); } catch (ClassNotFoundException ignored) { // Ok, fall-through } } // If the above fails, map Response Status to Exception class if (null == clazz) { clazz = errorCodes.getExceptionType(responseStatus); } if (clazz.equals(UnhandledAlertException.class)) { toReturn = createUnhandledAlertException(rawErrorData); } else if (Throwable.class.isAssignableFrom(clazz)) { @SuppressWarnings({ "unchecked" }) Class<? extends Throwable> throwableType = (Class<? extends Throwable>) clazz; toReturn = createThrowable(throwableType, new Class<?>[] { String.class }, new Object[] { message }); } if (toReturn == null) { toReturn = new UnknownServerException(message); } // Note: if we have a class name above, we should always have a stack trace. // The inverse is not always true. StackTraceElement[] stackTrace = new StackTraceElement[0]; if (rawErrorData.containsKey(STACK_TRACE)) { @SuppressWarnings({ "unchecked" }) List<Map<String, Object>> stackTraceInfo = (List<Map<String, Object>>) rawErrorData.get(STACK_TRACE); Iterable<StackTraceElement> stackFrames = Iterables.transform(stackTraceInfo, new FrameInfoToStackFrame()); stackFrames = Iterables.filter(stackFrames, Predicates.notNull()); stackTrace = Iterables.toArray(stackFrames, StackTraceElement.class); } toReturn.setStackTrace(stackTrace); return toReturn; }
From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java
@Override public PropertyNode add(final String key, final Collection<Object> value, final Collection<Attribute> attributes) { return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class)); }
From source file:com.b2international.index.es.EsDocumentSearcher.java
private <T> boolean applySourceFiltering(List<String> fields, boolean isDocIdOnly, final DocumentMapping mapping, final SearchSourceBuilder reqSource) { // No specific fields requested? Use _source to retrieve all of them if (fields.isEmpty()) { reqSource.fetchSource(null, EXCLUDED_SOURCE_FIELDS); return true; }/*from www. ja v a 2 s . com*/ // Only IDs required? _source is not needed at all if (isDocIdOnly) { reqSource.fetchSource(false); return false; } // Any field requested that can only retrieved from _source? Use source filtering if (requiresDocumentSourceField(mapping, fields)) { reqSource.fetchSource(Iterables.toArray(fields, String.class), EXCLUDED_SOURCE_FIELDS); return true; } // Use docValues otherwise for field retrieval fields.stream().forEach(field -> reqSource.docValueField(field, "use_field_mapping")); reqSource.fetchSource(false); return false; }
From source file:org.obiba.magma.beans.BeanVariableValueSourceFactory.java
protected Variable doBuildVariable(Class<?> propertyType, String name) { ValueType type = ValueType.Factory.forClass(propertyType); Variable.Builder builder = Variable.Builder.newVariable(name, type, entityType); if (propertyType.isEnum()) { Enum<?>[] constants = (Enum<?>[]) propertyType.getEnumConstants(); String[] names = Iterables.toArray( Iterables.transform(Arrays.asList(constants), Functions.toStringFunction()), String.class); builder.addCategories(names);//from w w w .j av a 2s. c om } if (occurrenceGroup != null) { builder.repeatable().occurrenceGroup(occurrenceGroup); } builder.accept(variableBuilderVisitors); // Allow extended classes to contribute to the builder return buildVariable(builder).build(); }
From source file:org.opendaylight.sxp.controller.core.DatastoreAccess.java
/** * @param identifier InstanceIdentifier that will be checked * @param datastoreType Datastore type where datastore will be checked * @param <T> Any type extending DataObject * @return If All parents of provided path exists *//*from www . j a va2 s .c om*/ private <T extends DataObject> boolean checkParentExist(final InstanceIdentifier<T> identifier, final LogicalDatastoreType datastoreType) { final InstanceIdentifier.PathArgument[] arguments = Iterables.toArray(identifier.getPathArguments(), InstanceIdentifier.PathArgument.class); return arguments.length < 2 || readSynchronous(identifier.firstIdentifierOf(arguments[arguments.length - 2].getType()), datastoreType) != null; }
From source file:ec.ui.ATsCollectionView.java
protected Ts[] retainTsCollection(Ts[] tss) { List<Ts> tmp = Lists.newArrayList(tss); tmp.retainAll(Arrays.asList(collection.toArray())); return Iterables.toArray(tmp, Ts.class); }