Java Code Examples for java.util.Collections#unmodifiableCollection()

The following examples show how to use java.util.Collections#unmodifiableCollection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Multimaps.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns an unmodifiable view of the specified collection, preserving the
 * interface for instances of {@code SortedSet}, {@code Set}, {@code List} and
 * {@code Collection}, in that order of preference.
 *
 * @param collection the collection for which to return an unmodifiable view
 * @return an unmodifiable view of the collection
 */

private static <V> Collection<V> unmodifiableValueCollection(Collection<V> collection) {
  if (collection instanceof SortedSet) {
    return Collections.unmodifiableSortedSet((SortedSet<V>) collection);
  } else if (collection instanceof Set) {
    return Collections.unmodifiableSet((Set<V>) collection);
  } else if (collection instanceof List) {
    return Collections.unmodifiableList((List<V>) collection);
  }
  return Collections.unmodifiableCollection(collection);
}
 
Example 2
Source File: WhereTest.java    From linq with Apache License 2.0 5 votes vote down vote up
@Test
void Where_IReadOnlyCollection_ReturnsExpectedValues_True() {
    Collection<Integer> source = Collections.unmodifiableCollection(Arrays.asList(1, 2, 3, 4, 5));
    Predicate1<Integer> truePredicate = (value) -> true;

    IEnumerable<Integer> result = Linq.of(source).where(truePredicate);

    assertEquals(source.size(), result.count());
    for (int i = 0; i < source.size(); i++) {
        assertEquals(Linq.of(source).elementAt(i), result.elementAt(i));
    }
}
 
Example 3
Source File: Paths.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
Collection<File> otherSearchPath() {
    if (otherSearchPath == null) {
        lazy();
        Path userClassPath = getPathForLocation(CLASS_PATH);
        Path sourcePath = getPathForLocation(SOURCE_PATH);
        if (sourcePath == null)
            otherSearchPath = userClassPath;
        else {
            otherSearchPath = new Path();
            otherSearchPath.addAll(userClassPath);
            otherSearchPath.addAll(sourcePath);
        }
    }
    return Collections.unmodifiableCollection(otherSearchPath);
}
 
Example 4
Source File: RoleImpl.java    From Javacord with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<User> getUsers() {
    if (isEveryoneRole()) {
        return getServer().getMembers();
    }

    userHashSetLock.readLock().lock();
    try {
        return Collections.unmodifiableCollection(new ArrayList<>(users));
    } finally {
        userHashSetLock.readLock().unlock();
    }
}
 
Example 5
Source File: ConnectionDirectory.java    From guacamole-client with Apache License 2.0 4 votes vote down vote up
@Override
@Transactional
public Collection<Connection> getAll(Collection<String> identifiers) throws GuacamoleException {
    Collection<ModeledConnection> objects = connectionService.retrieveObjects(getCurrentUser(), identifiers);
    return Collections.<Connection>unmodifiableCollection(objects);
}
 
Example 6
Source File: TestingSchedulingTopology.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<TestingSchedulingExecutionVertex> getVertices() {
	return Collections.unmodifiableCollection(schedulingExecutionVertices.values());
}
 
Example 7
Source File: TypeHandlerRegistry.java    From mybatis with Apache License 2.0 4 votes vote down vote up
/**
 * @since 3.2.2
 */
public Collection<TypeHandler<?>> getTypeHandlers() {
  return Collections.unmodifiableCollection(ALL_TYPE_HANDLERS_MAP.values());
}
 
Example 8
Source File: JdkCompiler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
Collection<JavaFileObject> files() {
    return Collections.unmodifiableCollection(classes.values());
}
 
Example 9
Source File: ServerChangeServerFeaturesEventImpl.java    From Javacord with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<ServerFeature> getOldServerFeatures() {
    return Collections.unmodifiableCollection(new HashSet<>(oldServerFeature));
}
 
Example 10
Source File: CustomItemContainer.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
public Collection<String> getGroups() {
	return Collections.unmodifiableCollection(_customItemsByGroup.keySet());
}
 
Example 11
Source File: ParameterType.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public Collection<ParameterCondition> getConditions() {
	return Collections.unmodifiableCollection(conditions);
}
 
Example 12
Source File: SimpleLinkStore.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<Link> getLinks() {
    return Collections.unmodifiableCollection(links.values());
}
 
Example 13
Source File: ConfigurationFieldModel.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public Collection<String> getFieldValues() {
    if (fieldValues != null) {
        return Collections.unmodifiableCollection(fieldValues);
    }
    return Collections.emptySet();
}
 
Example 14
Source File: LoopOnlyKeywordsUnhandledError.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Collection<VerificationError> getErrors() {
    return Collections.unmodifiableCollection(errors);
}
 
Example 15
Source File: AppIdentityCredential.java    From google-api-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an instance of a new builder.
 *
 * @param scopes OAuth scopes
 * @since 1.15
 */
public Builder(Collection<String> scopes) {
  this.scopes = Collections.unmodifiableCollection(scopes);
}
 
Example 16
Source File: Highlights.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the collection of host highlights.
 *
 * @return host highlights
 */
public Collection<HostHighlight> hosts() {
    return Collections.unmodifiableCollection(hosts.values());
}
 
Example 17
Source File: AISValidationResults.java    From sql-layer with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Gets all failures, if there were any.
 *
 * The collection will be unmodifiable and immutable; if it is not empty, subsequent invocations of this method
 * may all return same collection instance, but only as long as no additional failures are reported. If new
 * failures are reported, they and the previous will be in a new collection instance.
 * @return an unmodifiable, immutable collection of failures; will be empty if all validations passed.
 */
public Collection<AISValidationFailure> failures() {
    return Collections.unmodifiableCollection(failureList);
}
 
Example 18
Source File: Sketch.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Accessor for the set of views on this sketch.
 * 
 * @return Collection of the views on this sketch
 */
@Override
public Collection<ViewNode> getViews() {
	return Collections.unmodifiableCollection(_views.values());
}
 
Example 19
Source File: IntroActivity.java    From SlidingIntroScreen with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an unmodifiable Collection containing the pages.
 *
 * @return the pages of this activity
 */
public final Collection<Fragment> getPages() {
	return Collections.unmodifiableCollection(pages);
}
 
Example 20
Source File: Options.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the option templates for all the valid option supported.
 *
 * @return a collection of OptionTemplate objects.
 */
public static Collection<OptionTemplate> getValidOptions() {
    return Collections.unmodifiableCollection(validOptions);
}