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

com.descope.utils.CollectionUtils Maven / Gradle / Ivy

The newest version!
package com.descope.utils;

import java.util.HashMap;
import java.util.Map;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

/**
 * A few utility methods since we are using Java8.
 */
@UtilityClass
public class CollectionUtils {
  public static  Map mapOf(K k, V v) {
    Map m = new HashMap<>();
    m.put(k, v);
    return m;
  }

  public static  Map mapOf(K k1, V v1, K k2, V v2) {
    Map m = new HashMap<>();
    m.put(k1, v1);
    m.put(k2, v2);
    return m;
  }

  public static  Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3) {
    Map m = new HashMap<>();
    m.put(k1, v1);
    m.put(k2, v2);
    m.put(k3, v3);
    return m;
  }

  public static  Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
    Map m = new HashMap<>();
    m.put(k1, v1);
    m.put(k2, v2);
    m.put(k3, v3);
    m.put(k4, v4);
    return m;
  }

  public static  Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    Map m = new HashMap<>();
    m.put(k1, v1);
    m.put(k2, v2);
    m.put(k3, v3);
    m.put(k4, v4);
    m.put(k5, v5);
    return m;
  }

  public static  Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
    Map m = new HashMap<>();
    m.put(k1, v1);
    m.put(k2, v2);
    m.put(k3, v3);
    m.put(k4, v4);
    m.put(k5, v5);
    m.put(k6, v6);
    return m;
  }

  public static void addIfNotNull(Map m, String k, Object v) {
    if (v != null) {
      m.put(k, v);
    }
  }

  public static void addIfNotBlank(Map m, String k, String v) {
    if (StringUtils.isNotBlank(v)) {
      m.put(k, v);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy