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

com.undefinedlabs.scope.settings.ScopeEnvironmentPropertiesBooleanExtractor Maven / Gradle / Ivy

package com.undefinedlabs.scope.settings;

import org.apache.commons.lang3.StringUtils;

public enum ScopeEnvironmentPropertiesBooleanExtractor {
  INSTANCE;

  public boolean extract(final String envVarValue) {
    if (StringUtils.isEmpty(envVarValue)) {
      return false;
    }

    final String trimmedStr = envVarValue.trim();
    final String firstChar = trimmedStr.substring(0, 1).toLowerCase();
    final Integer firstCharAsInt = intoInt(firstChar);
    return "y".equalsIgnoreCase(firstChar) || "t".equalsIgnoreCase(firstChar) || firstCharAsInt > 0;
  }

  private Integer intoInt(final String firstChar) {
    try {
      return Integer.valueOf(firstChar);
    } catch (final Exception e) {
      return 0;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy