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

generator.server.javatool.base.main.collection.ProjectCollections.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}}.shared.collection.domain;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Null safe utility class to manage collections
 */
public final class {{ baseName }}Collections {

  private {{ baseName }}Collections() {}

  /**
   * Get an immutable collection from the given collection
   *
   * @param 
   *          Type of this collection
   * @param collection
   *          input collection
   * @return An immutable collection
   */
  public static  Collection immutable(Collection collection) {
    if (collection == null) {
      return Set.of();
    }

    return Collections.unmodifiableCollection(collection);
  }

  /**
   * Get an immutable set from the given set
   *
   * @param 
   *          Type of this set
   * @param set
   *          input set
   * @return An immutable set
   */
  public static  Set immutable(Set set) {
    if (set == null) {
      return Set.of();
    }

    return Collections.unmodifiableSet(set);
  }

  /**
   * Get an immutable set from the given list
   *
   * @param 
   *          Type of this list
   * @param list
   *          input list
   * @return An immutable list
   */
  public static  List immutable(List list) {
    if (list == null) {
      return List.of();
    }

    return Collections.unmodifiableList(list);
  }

  /**
   * Get an immutable map from the given map
   *
   * @param  Key type of this map
   * @param  value type of this map
   * @return An immutable map
   */
  public static  Map immutable(Map map) {
    if (map == null) {
      return Map.of();
    }
    return Collections.unmodifiableMap(map);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy