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

org.tiogasolutions.notify.pub.common.TraitUtil Maven / Gradle / Ivy

There is a newer version: 5.1.4
Show newest version
package org.tiogasolutions.notify.pub.common;

import java.util.*;
import java.util.stream.Collectors;

/**
 * User: Harlan
 * Date: 1/31/2015
 * Time: 5:51 PM
 */
public class TraitUtil {

  public static Map toTraitMap(String... keyValues) {
    Map traitMap = new HashMap<>();

    for(String keyValue : keyValues) {
      String key;
      String value;
      keyValue = (keyValue == null) ? null : keyValue.trim().toLowerCase();
      if (keyValue == null || keyValue.length() == 0) {
        key = "none";
        value = null;
      } else {
        int splitAt = keyValue.indexOf(':');
        if (splitAt > 0) {
          key = keyValue.substring(0, splitAt);
          if (splitAt < keyValue.length()) {
            value = keyValue.substring(splitAt + 1);
          } else {
            value = null;
          }
        } else {
          key = keyValue;
          value = null;
        }
      }
      traitMap.put(key, value);
    }

    return traitMap;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy