use of java.util.Collections in project arctic-sea by 52North.
the class AbstractCapabilitiesBaseTypeDecoder method parseServiceIdentification.
private OwsServiceIdentification parseServiceIdentification(ServiceIdentification serviceIdentification) {
if (serviceIdentification == null) {
return null;
}
OwsCode serviceType = parseCode(serviceIdentification.getServiceType());
Set<String> serviceTypeVersion = Optional.ofNullable(serviceIdentification.getServiceTypeVersionArray()).map(Arrays::stream).orElseGet(Stream::empty).collect(toSet());
Set<String> fees = Optional.ofNullable(serviceIdentification.getFees()).map(Collections::singleton).orElseGet(Collections::emptySet);
Set<URI> profiles = Optional.ofNullable(serviceIdentification.getProfileArray()).map(Arrays::stream).orElseGet(Stream::empty).map(URI::create).collect(toSet());
Set<String> accessConstraints = Optional.ofNullable(serviceIdentification.getAccessConstraintsArray()).map(Arrays::stream).orElseGet(Stream::empty).collect(toSet());
MultilingualString title = new MultilingualString();
MultilingualString abstrakt = new MultilingualString();
Optional.ofNullable(serviceIdentification.getTitleArray()).map(Arrays::stream).orElseGet(Stream::empty).map(this::parseLanguageString).forEach(title::addLocalization);
Optional.ofNullable(serviceIdentification.getAbstractArray()).map(Arrays::stream).orElseGet(Stream::empty).map(this::parseLanguageString).forEach(abstrakt::addLocalization);
Set<OwsKeyword> keywords = Optional.ofNullable(serviceIdentification.getKeywordsArray()).map(Arrays::stream).orElseGet(Stream::empty).flatMap(this::parseKeyword).filter(Objects::nonNull).collect(toSet());
return new OwsServiceIdentification(serviceType, serviceTypeVersion, profiles, fees, accessConstraints, title, abstrakt, keywords);
}
use of java.util.Collections in project engine by Lumeer.
the class SuggestionFacade method keepOnlyMatchingAttributes.
private static List<Collection> keepOnlyMatchingAttributes(List<Collection> collections, String text) {
for (Collection collection : collections) {
Set<Attribute> attributes = collection.getAttributes().stream().filter(a -> a.getName().toLowerCase().contains(text)).collect(Collectors.toSet());
collection.setAttributes(attributes);
}
return collections;
}
use of java.util.Collections in project engine by Lumeer.
the class CollectionServiceIT method testGetAllCollections.
@Test
public void testGetAllCollections() {
createCollection(CODE);
createCollection(CODE2);
Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
assertThat(response).isNotNull();
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
List<JsonCollection> collections = response.readEntity(new GenericType<List<JsonCollection>>() {
});
assertThat(collections).extracting(Resource::getCode).containsOnly(CODE, CODE2);
Permissions permissions1 = collections.get(0).getPermissions();
assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
Permissions permissions2 = collections.get(1).getPermissions();
assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
use of java.util.Collections in project dspot by STAMP-project.
the class CollectionCreator method generateEmptyCollection.
static CtExpression<?> generateEmptyCollection(CtTypeReference type, String nameMethod, Class<?> typeOfCollection) {
final Factory factory = type.getFactory();
final CtType<?> collectionsType = factory.Type().get(Collections.class);
final CtTypeAccess<?> accessToCollections = factory.createTypeAccess(collectionsType.getReference());
final CtMethod<?> singletonListMethod = collectionsType.getMethodsByName(nameMethod).get(0);
final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference();
executableReference.setStatic(true);
executableReference.setSimpleName(singletonListMethod.getSimpleName());
executableReference.setDeclaringType(collectionsType.getReference());
executableReference.setType(factory.createCtTypeReference(typeOfCollection));
if (type.getActualTypeArguments().isEmpty()) {
// supporting Collections.<type>emptyList()
executableReference.addActualTypeArgument(type);
} else if (type.getActualTypeArguments().stream().noneMatch(reference -> reference instanceof CtWildcardReference)) {
// in case type is a list, we copy the Actual arguments
executableReference.setActualTypeArguments(type.getActualTypeArguments());
}
return factory.createInvocation(accessToCollections, executableReference);
}
use of java.util.Collections in project revapi by revapi.
the class Analyzer method gatherConfig.
@SuppressWarnings("unchecked")
private void gatherConfig(AnalysisContext.Builder ctxBld) throws MojoExecutionException {
if (analysisConfigurationFiles != null && analysisConfigurationFiles.length > 0) {
for (Object pathOrConfigFile : analysisConfigurationFiles) {
ConfigurationFile configFile;
if (pathOrConfigFile instanceof String) {
configFile = new ConfigurationFile();
configFile.setPath((String) pathOrConfigFile);
} else {
configFile = (ConfigurationFile) pathOrConfigFile;
}
String path = configFile.getPath();
String resource = configFile.getResource();
if (path == null && resource == null) {
throw new MojoExecutionException("Either 'path' or 'resource' has to be specified in a configurationFile definition.");
} else if (path != null && resource != null) {
throw new MojoExecutionException("Either 'path' or 'resource' has to be specified in a configurationFile definition but" + " not both.");
}
String readErrorMessage = "Error while processing the configuration file on " + (path == null ? "classpath " + resource : "path " + path);
Supplier<Iterator<InputStream>> configFileContents;
if (path != null) {
File f = new File(path);
if (!f.isAbsolute()) {
f = new File(project.getBasedir(), path);
}
if (!f.isFile() || !f.canRead()) {
String message = "Could not locate analysis configuration file '" + f.getAbsolutePath() + "'.";
if (failOnMissingConfigurationFiles) {
throw new MojoExecutionException(message);
} else {
log.debug(message);
continue;
}
}
final File ff = f;
configFileContents = () -> {
try {
return Collections.<InputStream>singletonList(new FileInputStream(ff)).iterator();
} catch (FileNotFoundException e) {
throw new MarkerException("Failed to read the configuration file '" + ff.getAbsolutePath() + "'.", e);
}
};
} else {
configFileContents = () -> {
try {
return Collections.list(getClass().getClassLoader().getResources(resource)).stream().map(url -> {
try {
return url.openStream();
} catch (IOException e) {
throw new MarkerException("Failed to read the classpath resource '" + url + "'.");
}
}).iterator();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to locate classpath resources on path '" + resource + "'.");
}
};
}
Iterator<InputStream> it = configFileContents.get();
List<Integer> nonJsonIndexes = new ArrayList<>(4);
int idx = 0;
while (it.hasNext()) {
ModelNode config;
try (InputStream in = it.next()) {
config = readJson(in);
} catch (MarkerException | IOException e) {
throw new MojoExecutionException(readErrorMessage, e.getCause());
}
if (config == null) {
nonJsonIndexes.add(idx);
continue;
}
mergeJsonConfigFile(ctxBld, configFile, config);
idx++;
}
if (!nonJsonIndexes.isEmpty()) {
idx = 0;
it = configFileContents.get();
while (it.hasNext()) {
try (Reader rdr = new InputStreamReader(it.next())) {
if (nonJsonIndexes.contains(idx)) {
mergeXmlConfigFile(ctxBld, configFile, rdr);
}
} catch (MarkerException | IOException | XmlPullParserException e) {
throw new MojoExecutionException(readErrorMessage, e.getCause());
}
idx++;
}
}
}
}
if (analysisConfiguration != null) {
String text = analysisConfiguration.getValue();
if (text == null) {
convertNewStyleConfigFromXml(ctxBld, getRevapi());
} else {
ctxBld.mergeConfigurationFromJSON(text);
}
}
}
Aggregations