List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:org.onehippo.cms7.essentials.components.utils.SiteUtils.java
/** * For given string, comma separate it and convert to array * * @param inputString comma separated document types * @return empty array if null or empty/*from ww w . j a v a 2 s .co m*/ */ @Nonnull public static String[] parseCommaSeparatedValue(final String inputString) { if (Strings.isNullOrEmpty(inputString)) { return ArrayUtils.EMPTY_STRING_ARRAY; } final Iterable<String> iterable = Splitter.on(",").trimResults().omitEmptyStrings().split(inputString); return Iterables.toArray(iterable, String.class); }
From source file:edu.mayo.cts2.framework.plugin.service.bioportal.transform.EntityDescriptionTransform.java
/** * Transform entity definitions./*from www. j av a 2 s. c o m*/ * * @param codeSystemName the code system name * @param codeSystemVersionName the code system version name * @param node the node * @return the definition[] */ private Definition[] transformEntityDefinitions(String codeSystemName, String codeSystemVersionName, Node node) { List<Definition> returnList = new ArrayList<Definition>(); Node definitions = TransformUtils.getNamedChild(node, "definitions"); if (definitions != null) { for (Node definition : TransformUtils.getNodeList(definitions, "string")) { Definition def = new Definition(); def.setValue(ModelUtils.toTsAnyType(TransformUtils.getNodeText(definition))); def.setAssertedInCodeSystemVersion(codeSystemVersionName); returnList.add(def); } } return Iterables.toArray(returnList, Definition.class); }
From source file:com.ge.research.sadl.scoping.SadlGlobalScopeProvider.java
/** * @param publicURI A public URI//from w ww.j a va 2s. c o m * @param resourceDescriptions * @return first: resource URI for the publicURI, second: array of imported URIs */ private Pair<URI, String[]> getImportMapping(URI publicURI, Iterable<IResourceDescription> resourceDescriptions) { Pair<URI, String[]> result = null; for (IResourceDescription resourceDescription : resourceDescriptions) { // TODO: Inject file extension for SADL for (IEObjectDescription objDesc : resourceDescription .getExportedObjectsByType(SadlPackage.Literals.MODEL)) { if (resourceDescription.getURI().equals(publicURI) || objDesc.getQualifiedName().toString().equals(publicURI.toString())) { String importsAsString = objDesc.getUserData(SadlEObjectDescription.IMPORT_KEY); String[] imports = !importsAsString.isEmpty() ? Iterables.toArray(SPLITTER.split(importsAsString), String.class) : new String[0]; result = new Pair<URI, String[]>(resourceDescription.getURI(), imports); // if ("sadl".equals(resourceDescription.getURI().fileExtension())) { return result; // } } } // TODO add external URI imports, recurse if (externalURIs == null) { externalURIs = new ArrayList<URI>(); } if (!externalURIs.contains(publicURI)) { externalURIs.add(publicURI); } } return result; }
From source file:org.elasticsearch.river.mongodb.RiverMongoDBTestAbstract.java
/** Only include TOKUMX if on a supported platform */ @DataProvider(name = "allMongoExecutableTypes") public static Object[][] allMongoExecutableTypes() { return Iterables .toArray(Iterables.transform(supportedExecutableTypes(), new Function<ExecutableType, Object[]>() { @Override//w ww . j av a 2 s. com public Object[] apply(ExecutableType _) { return new Object[] { _ }; } }), Object[].class); }
From source file:eu.interedition.text.repository.JdbcStore.java
@Override public void deleteAnnotations(Iterable<Long> ids) { if (Iterables.isEmpty(ids)) { return;//w ww. java 2 s .c om } try { final Long[] idArray = Iterables.toArray(ids, Long.class); if (deleteAnnotations == null) { deleteAnnotations = connection .prepareStatement("delete from interedition_text_annotation a where a.id in " + "(select id from table(id bigint = ?) ids)"); } deleteAnnotations.setObject(1, idArray); deleteAnnotations.executeUpdate(); txLog.annotationsRemoved(idArray); } catch (SQLException e) { throw Throwables.propagate(e); } }
From source file:edu.umn.msi.tropix.persistence.service.impl.ServiceBase.java
protected <T extends TropixObject> T[] filter(final Iterable<T> objects, final Class<T> clazz, final String userId) { final Iterable<T> iter = Iterables.filter(objects, Predicates.getValidAndCanReadPredicate(securityProvider, userId)); return Iterables.toArray(iter, clazz); }
From source file:org.cloudsmith.geppetto.pp.dsl.ui.editor.findrefs.ReferenceSearchResultContentProvider.java
public void descriptionsChanged(final Event event) { Display.getDefault().asyncExec(new Runnable() { public void run() { if (rootNodes != null) { for (Delta delta : event.getDeltas()) { if (!(delta.getNew() instanceof StatefulResourceDescription)) { for (Iterator<ReferenceSearchViewTreeNode> i = rootNodes.iterator(); i.hasNext();) { ReferenceSearchViewTreeNode rootNode = i.next(); if (((IResourceDescription) rootNode.getDescription()).getURI() .equals(delta.getUri())) { if (delta.getNew() == null) { i.remove(); viewer.remove(rootNode); break; }/*www. ja va2 s . c om*/ Iterable<IReferenceDescription> newReferenceDescriptions = delta.getNew() .getReferenceDescriptions(); List<ReferenceSearchViewTreeNode> removedReferenceNodes = Lists.newArrayList(); for (ReferenceSearchViewTreeNode referenceNode : rootNode.getChildren()) { final IReferenceDescription refDesc = ((IReferenceDescription) referenceNode .getDescription()); final URI referenceSourceURI = refDesc.getSourceEObjectUri(); final URI referenceTargetURI = refDesc.getTargetEObjectUri(); if (Iterables.isEmpty(Iterables.filter(newReferenceDescriptions, new Predicate<IReferenceDescription>() { public boolean apply(IReferenceDescription input) { return input.getSourceEObjectUri() .equals(referenceSourceURI) && input.getTargetEObjectUri() .equals(referenceTargetURI); } }))) { removedReferenceNodes.add(referenceNode); } } for (ReferenceSearchViewTreeNode removedReferenceNode : removedReferenceNodes) { rootNode.removeChild(removedReferenceNode); } if (rootNode.getChildren().isEmpty()) { i.remove(); viewer.remove(rootNode); break; } viewer.remove(rootNode, Iterables.toArray(removedReferenceNodes, ReferenceSearchViewTreeNode.class)); } } } } } } }); }
From source file:org.apache.lens.cli.commands.LensFactCommands.java
/** * Gets the storage from fact.// w w w .ja va 2 s. c om * * @param tablepair the tablepair * @return the storage from fact */ @CliCommand(value = "fact get storage", help = "get storage of fact table") public String getStorageFromFact(@CliOption(key = { "", "table" }, mandatory = true, help = "<table-name> <storage-name>") String tablepair) { Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(tablepair); String[] pair = Iterables.toArray(parts, String.class); if (pair.length != 2) { return "Syntax error, please try in following " + "format. fact get storage <table> <storage>"; } try { return formatJson( mapper.writer(pp).writeValueAsString(getClient().getStorageFromFact(pair[0], pair[1]))); } catch (IOException e) { throw new IllegalArgumentException(e); } }
From source file:org.opentestsystem.shared.progman.rest.AssetGroupController.java
private AssetGroupSearchRequest buildAssetGroupSearchRequest(final String componentName, final String tenantId) { Map<String, String[]> groupSearch = ImmutableMap.of(AssetGroupSearchRequest.SEARCH_KEY_COMPONENT_NAME, Iterables.toArray(Lists.newArrayList(componentName), String.class), AssetGroupSearchRequest.SEARCH_KEY_TENANT_ID, Iterables.toArray(Lists.newArrayList(tenantId), String.class)); return new AssetGroupSearchRequest(groupSearch); }
From source file:ddf.catalog.impl.operations.UpdateOperations.java
public UpdateResponse update(UpdateStorageRequest streamUpdateRequest) throws IngestException, SourceUnavailableException { Map<String, Metacard> metacardMap = new HashMap<>(); List<ContentItem> contentItems = new ArrayList<>(streamUpdateRequest.getContentItems().size()); HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>(); UpdateResponse updateResponse = null; UpdateStorageRequest updateStorageRequest = null; UpdateStorageResponse updateStorageResponse = null; streamUpdateRequest = opsStorageSupport.prepareStorageRequest(streamUpdateRequest, streamUpdateRequest::getContentItems); // Operation populates the metacardMap, contentItems, and tmpContentPaths opsMetacardSupport.generateMetacardAndContentItems(streamUpdateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths); streamUpdateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths); streamUpdateRequest = applyAttributeOverrides(streamUpdateRequest, metacardMap); try {//w w w . ja v a2 s . c o m if (!contentItems.isEmpty()) { updateStorageRequest = new UpdateStorageRequestImpl(contentItems, streamUpdateRequest.getId(), streamUpdateRequest.getProperties()); updateStorageRequest = processPreUpdateStoragePlugins(updateStorageRequest); try { updateStorageResponse = sourceOperations.getStorage().update(updateStorageRequest); updateStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths); } catch (StorageException e) { throw new IngestException("Could not store content items. Removed created metacards.", e); } updateStorageResponse = processPostUpdateStoragePlugins(updateStorageResponse); for (ContentItem contentItem : updateStorageResponse.getUpdatedContentItems()) { if (StringUtils.isBlank(contentItem.getQualifier())) { Metacard metacard = metacardMap.get(contentItem.getId()); Metacard overrideMetacard = contentItem.getMetacard(); Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, true); updatedMetacard.setAttribute( new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(contentItem.getSize()))); metacardMap.put(contentItem.getId(), updatedMetacard); } } } UpdateRequestImpl updateRequest = new UpdateRequestImpl(Iterables.toArray( metacardMap.values().stream().map(Metacard::getId).collect(Collectors.toList()), String.class), new ArrayList<>(metacardMap.values())); updateRequest.setProperties(streamUpdateRequest.getProperties()); historian.setSkipFlag(updateRequest); updateResponse = doUpdate(updateRequest); historian.version(streamUpdateRequest, updateStorageResponse, updateResponse); } catch (Exception e) { if (updateStorageRequest != null) { try { sourceOperations.getStorage().rollback(updateStorageRequest); } catch (StorageException e1) { LOGGER.info("Unable to remove temporary content for id: {}", updateStorageRequest.getId(), e1); } } throw new IngestException("Unable to store products for request: " + streamUpdateRequest.getId(), e); } finally { opsStorageSupport.commitAndCleanup(updateStorageRequest, tmpContentPaths); } updateResponse = doPostIngest(updateResponse); return updateResponse; }