com.github.blahord.bettercollections.compatibility.CollectionWrappers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bettercollections Show documentation
Show all versions of bettercollections Show documentation
An collection framework that eliminates some design flaws in Javas CollectionFramework.
package com.github.blahord.bettercollections.compatibility;
import com.github.blahord.bettercollections.collection.*;
/**
* Utility methods to wrap between java.util collections and betterCollection collections.
*
* @since 1.0
*/
public final class CollectionWrappers {
private CollectionWrappers() {
}
/**
* Wraps a {@link java.util.Collection} to a {@link MutableCollection}.
* Note: You should know the capability of javaCollection and use the result set only in that way, the javaCollection can do. So be careful,
* when using this
*
* @param javaCollection the java.util collection
* @param the type of the collection
* @return a Collection that wraps the javaCollection.
* @since 1.0
*/
public static MutableCollection extends T, ? super T> wrapJavaUtilCollection(java.util.Collection javaCollection) {
return CollectionWrapper.create(javaCollection);
}
/**
* Wraps a {@link MutableCollection} to {@link java.util.Collection}.
* The resulting collection is fully usable.
* Note: asJavaUtilCollection(wrapJavaUtilCollection(x)) may ne NOT fully usable, because x may to be fully usable
*
* @param collection the collection to wrap
* @param the type of the collection
* @return a MutableCollection wrapped as a java.util.Collection
* @since 1.0
*/
public static java.util.Collection asMutableJavaUtilCollection(MutableCollection extends T, ? super T> collection) {
return new MutableJavaCollection<>(collection);
}
/**
* Wraps a {@link ExtensibleCollection} to {@link java.util.Collection}.
* The resulting collection cannot do anything that removed items from the collection.
*
* @param collection the collection to wrap
* @param the type of the collection
* @return an ExtensibleCollection wrapped as a java.util.Collection
* @since 1.0
*/
public static java.util.Collection asExtensibleJavaUtilCollection(ExtensibleCollection extends T, ? super T> collection) {
return new ExtensibleJavaCollection<>(collection);
}
/**
* Wraps a {@link ReducibleCollection} to {@link java.util.Collection}.
* The resulting collection cannot do anything that add items to the collection.
*
* @param collection the collection to wrap
* @param the type of the collection
* @return an ReducibleCollection wrapped as a java.util.Collection
* @since 1.0
*/
public static java.util.Collection asReducibleJavaUtilCollection(ReducibleCollection extends T> collection) {
return new ReducibleJavaCollection<>(collection);
}
/**
* Wraps a {@link Collection} to {@link java.util.Collection}.
* The resulting collection cannot do anything that modifies the the collection.
*
* @param collection the collection to wrap
* @param the type of the collection
* @return an Collection wrapped as a java.util.Collection
* @since 1.0
*/
public static java.util.Collection asJavaUtilCollection(Collection extends T> collection) {
return new JavaCollection<>(collection);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy