All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.blahord.bettercollections.compatibility.CollectionWrappers Maven / Gradle / Ivy

Go to download

An collection framework that eliminates some design flaws in Javas CollectionFramework.

There is a newer version: 1.1.0
Show newest version
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 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 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 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 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 collection) {
        return new JavaCollection<>(collection);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy