List of usage examples for com.google.common.collect Iterables contains
public static boolean contains(Iterable<?> iterable, @Nullable Object element)
From source file:org.immutables.mongo.fixture.MongoContext.java
private MongoContext(final MongoClient client) { Preconditions.checkNotNull(client, "client"); // allows to cleanup resources after each test final Closer closer = Closer.create(); closer.register(new Closeable() { @Override//from w ww . java 2 s . co m public void close() throws IOException { client.close(); } }); // drop database if exists (to have a clean test) if (Iterables.contains(client.listDatabaseNames(), DBNAME)) { client.getDatabase(DBNAME).drop(); } this.database = client.getDatabase(DBNAME); closer.register(new Closeable() { @Override public void close() throws IOException { database.drop(); } }); final ListeningExecutorService executor = MoreExecutors .listeningDecorator(Executors.newSingleThreadExecutor()); closer.register(new Closeable() { @Override public void close() throws IOException { MoreExecutors.shutdownAndAwaitTermination(executor, 100, TimeUnit.MILLISECONDS); } }); this.setup = RepositorySetup.builder().gson(createGson()).executor(executor).database(database).build(); this.closer = closer; }
From source file:com.bennavetta.aeneas.mesos.slave.docker.Daemon.java
private static void mountFilesystems() throws IOException { Path cgroup = Paths.get("/sys/fs/cgroup"); if (!Files.isDirectory(cgroup)) Files.createDirectory(cgroup); LOG.debug("Creating '{}' tmpfs", cgroup); if (!isMountpoint(cgroup)) { try {/* www . java 2 s . c o m*/ mount(cgroup, "cgroup", "tmpfs", "uid=0,gid=0,mode=0755", false); } catch (IOException e) { throw new IOException("Could not make a tmpfs mount. Was the --privileged flag used?", e); } } Path security = Paths.get("/sys/kernel/security"); LOG.debug("Creating security file system in '{}'", security); if (Files.isDirectory(security) && !isMountpoint(security)) { try { mount(security, "none", "securityfs", null, true); } catch (IOException e) { LOG.warn("Could not mount {}. AppArmor detection and --privileged mode might break.", security); } } String cgroupsText = new String(Files.readAllBytes(Paths.get("/proc/1/cgroup"))); List<String> cgroups = StreamSupport.stream(Splitter.on('\n').split(cgroupsText).spliterator(), false) .filter(s -> !s.trim().isEmpty()).map(s -> Splitter.on(':').split(s)).map(i -> Iterables.get(i, 1)) .collect(Collectors.toList()); for (String subsystem : cgroups) { LOG.debug("Creating '{}' cgroup", subsystem); Path subsysPath = cgroup.resolve(subsystem); if (!Files.isDirectory(subsysPath)) Files.createDirectory(subsysPath); if (!isMountpoint(subsysPath)) { mount(subsysPath, "cgroup", "cgroup", subsystem, false); } /* * Address some bugs * See https://github.com/jpetazzo/dind/blob/master/wrapdocker */ if (subsystem.startsWith("name=")) { String name = subsystem.substring(6); Files.createSymbolicLink(cgroup.resolve(name), Paths.get(subsystem)); } if (subsystem.equals("cpuacct,cpu")) { Files.createSymbolicLink(cgroup.resolve("cpu,cpuacct"), Paths.get(subsystem)); } } if (!cgroupsText.contains(":devices:")) { LOG.warn("The 'devices' cgroup should be in its own hierarchy."); } if (!Iterables.contains(Splitter.on(CharMatcher.BREAKING_WHITESPACE).split(cgroupsText), "devices")) { LOG.warn("The 'devices' cgroup does not appear to be mounted."); } }
From source file:org.apache.brooklyn.core.sensor.password.CreatePasswordSensor.java
@Override public void apply(EntityLocal entity) { super.apply(entity); boolean isCharacterGroupsPresent = characterGroups != null && characterGroups.size() > 0; boolean isCharacterGroupsValid = isCharacterGroupsPresent && !Iterables.contains(characterGroups, Predicates.isNull()) && !Iterables.contains(characterGroups, Predicates.equalTo("")); boolean isAcceptableCharsPresentAndValid = acceptableChars != null && !acceptableChars.isEmpty(); Preconditions.checkArgument(!isCharacterGroupsPresent || isCharacterGroupsValid, "password.character.groups config key was given but does not contain any valid groups"); Preconditions.checkArgument(!(isCharacterGroupsPresent && isAcceptableCharsPresentAndValid), "password.chars and password.character.groups both provided - please provide only ONE of them"); Preconditions.checkArgument(!isCharacterGroupsValid || characterGroups.size() <= passwordLength, "password.length must be longer than the number of entries in password.character.groups"); String password;//ww w .j a v a 2 s .c o m if (isCharacterGroupsValid) { password = Identifiers.makeRandomPassword(passwordLength, characterGroups.toArray(new String[0])); } else if (isAcceptableCharsPresentAndValid) { password = Identifiers.makeRandomPassword(passwordLength, acceptableChars); } else { password = Identifiers.makeRandomPassword(passwordLength); } entity.sensors().set(sensor, password); }
From source file:org.eclipse.sirius.diagram.tools.internal.validation.description.constraints.EdgeMappingCycleConstraint.java
/** * Detects cycles from current {@link EdgeMapping} recurcively. * //from ww w . j a va 2 s.co m * @param edgeMapping * the current {@link EdgeMapping} * @param processedEdgeMappings * {@link Set} of already investigated {@link EdgeMapping} * @param edgeMappingsToProcess * {@link Set} of {@link EdgeMapping} to investigate * * @return if a cycle is detected from the current {@link EdgeMapping} */ private boolean hasCycle(EdgeMapping edgeMapping, Set<EdgeMapping> processedEdgeMappings, Set<EdgeMapping> edgeMappingsToProcess) { boolean hasCycle = false; if (Iterables.contains(edgeMappingsToProcess, edgeMapping)) { // Investigation lead to the first EdgeMapping : A cycle is // detected. hasCycle = true; } else if (edgeMappingsToProcess.isEmpty() || processedEdgeMappings.containsAll(edgeMappingsToProcess)) { // No more EdgeMapping to investigate : No cycle detected. hasCycle = false; } else { // Recursively investigate source/target EdgeMapping of the // edgeMappingsToProcess Set. LinkedHashSet<EdgeMapping> newEdgeMappingsToProcess = Sets.<EdgeMapping>newLinkedHashSet(); for (EdgeMapping edgeMappingToProcess : edgeMappingsToProcess) { newEdgeMappingsToProcess.addAll(Sets.newLinkedHashSet(Iterables.concat( Iterables.filter(edgeMappingToProcess.getSourceMapping(), EdgeMapping.class), Iterables.filter(edgeMappingToProcess.getTargetMapping(), EdgeMapping.class)))); } hasCycle = hasCycle(edgeMapping, Sets.newLinkedHashSet(Iterables.concat(processedEdgeMappings, edgeMappingsToProcess)), newEdgeMappingsToProcess); } return hasCycle; }
From source file:org.sosy_lab.cpachecker.cpa.invariants.InvariantsMergeOperator.java
private static InvariantsState reduceToGivenVariables(InvariantsState pState, Iterable<? extends String> pVariables) { InvariantsState result = pState;/*from w w w .ja va2 s. c om*/ for (String variableName : pState.getEnvironment().keySet()) { if (!Iterables.contains(pVariables, variableName)) { result = result.clear(variableName); } } return result; }
From source file:de.iteratec.iteraplan.presentation.problemreports.ApplicationProblemReportPart.java
static ApplicationProblemReportPart generateApplicationReport(String filename) { ApplicationProblemReportPart reportPart = new ApplicationProblemReportPart(filename); GuiContext currentGuiContext = GuiContext.getCurrentGuiContext(); IteraplanProperties properties = IteraplanProperties.getProperties(); PrintWriter appWriter = reportPart.getWriter(); appWriter.println("Active Dialog: " + currentGuiContext.getActiveDialogName()); appWriter.println("-"); Collection<Object> allPropertyKeys = properties.getAllPropertyKeys(); List<String> sortedPropertyKeys = Lists.newArrayList(); for (Object key : allPropertyKeys) { if (!Iterables.contains(EXCLUDED_PROPERTIES, key)) { sortedPropertyKeys.add(String.valueOf(key)); }//from w ww . j a v a 2s. c om } Collections.sort(sortedPropertyKeys); appWriter.println("APPLICATION PROPERTIES:"); for (String key : sortedPropertyKeys) { if (!Iterables.contains(EXCLUDED_PROPERTIES, key)) { appWriter.println(" " + Strings.padEnd(key, 64, PAD_CHAR) + "=" + PAD_CHAR + properties.getProperty(String.valueOf(key))); } } appWriter.println("-"); appWriter.println("LOGGER/ APPENDER:"); @SuppressWarnings("rawtypes") Enumeration currentLoggers = LogManager.getCurrentLoggers(); while (currentLoggers.hasMoreElements()) { Object loggerElement = currentLoggers.nextElement(); if (loggerElement instanceof Logger) { Logger logger = (Logger) loggerElement; String loggerName = logger.getName(); @SuppressWarnings("rawtypes") Enumeration allAppenders = logger.getAllAppenders(); while (allAppenders.hasMoreElements()) { Object appenderElement = allAppenders.nextElement(); if (appenderElement instanceof FileAppender) { FileAppender fileAppender = (FileAppender) appenderElement; appWriter.println("Appender: " + fileAppender.getName() + " for Logger: " + loggerName + " with Logfile: " + fileAppender.getFile()); } } } } appWriter.close(); return reportPart; }
From source file:org.jclouds.vcloud.director.v1_5.predicates.EntityPredicates.java
/** * Matches {@link EntityType entities} with names in the given collection. * * @param T type of the entity, for example {@link Vm} * @param names collection of values for the name attribute of the entity * @return predicate that will match entities with names starting with the given prefix *//* ww w .j a v a 2 s . com*/ public static <T extends Entity> Predicate<T> nameIn(final Iterable<String> names) { checkNotNull(names, "names must be defined"); return new Predicate<T>() { @Override public boolean apply(T entity) { String name = entity.getName(); return Iterables.contains(names, name); } @Override public String toString() { return "nameIn(" + Iterables.toString(names) + ")"; } }; }
From source file:com.forerunnergames.tools.common.Arguments.java
/** * Checks if the specified Iterable has any null elements. The check will pass if the Iterable itself is null. * * @param iterable/*w w w .j ava 2 s . co m*/ * The Iterable to check, may be null. * @param iterableName * The name of the Iterable to check, must not be null. * * @throws IllegalArgumentException * If the Iterable has any null elements. */ public static void checkHasNoNullElements(final Iterable<?> iterable, final String iterableName) { if (iterable != null && Iterables.contains(iterable, null)) { illegalArgument(iterableName, ArgumentStatus.NULL_ELEMENTS); } }
From source file:dynamite.zafroshops.app.adapter.ZopServiceAdapter.java
@Override public View getView(final int position, View convertView, final ViewGroup parent) { ViewHolder viewHolder;//w w w . ja v a 2 s.c om if (convertView == null) { Context context = this.getContext(); LayoutInflater la = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = la.inflate(R.layout.service_item, null); viewHolder = new ViewHolder(); viewHolder.checkbox = (CheckBox) convertView.findViewById(R.id.serviceCheckBox); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } if (objects != null) { final ZopServiceType item = this.getItem(position); viewHolder.checkbox.setText(item.toString()); viewHolder.checkbox.setChecked(Iterables.contains(selection, item)); viewHolder.checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CheckBox checkBox = (CheckBox) view; if (checkBox.isChecked()) { selection.add(item); } else { selection.remove(item); } } }); } return convertView; }
From source file:edu.umn.msi.tropix.webgui.server.security.impl.GuestAuthenticationProviderImpl.java
@Inject public void setModules(@Named("modulesIterable") final Iterable<String> modules) { this.allowGuestLogin = Iterables.contains(modules, Module.GUEST.toString()); }