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

org.rapidpm.frp.SystemProperties Maven / Gradle / Ivy

There is a newer version: 01.00.07-RPM
Show newest version
/**
 * Copyright © 2017 Sven Ruppert ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.rapidpm.frp;

import static java.lang.System.getProperty;
import static org.rapidpm.frp.Converting.convertToBoolean;
import static org.rapidpm.frp.Converting.convertToDouble;
import static org.rapidpm.frp.Converting.convertToInteger;
import static org.rapidpm.frp.model.Result.ofNullable;

import java.util.function.BiFunction;
import java.util.function.Function;

import org.rapidpm.frp.model.Result;

public interface SystemProperties {

  static BiFunction qualifiedParameter() {
    return (clazz , unqualifiedName) -> clazz.getName() + "." + unqualifiedName;
  }

  static BiFunction hasSystemProperty() {
    return qualifiedParameter().andThen(key -> getProperty(key) != null);
  }

  static Function hasSystemProperty(Class qualifier) {
    return (key) -> hasSystemProperty().apply(qualifier , key);
  }


  static BiFunction> systemProperty() {
    return qualifiedParameter().andThen(key -> ofNullable(getProperty(key)));
  }

  static BiFunction> systemProperty(String defaultValue) {
    return qualifiedParameter().andThen(key -> ofNullable(getProperty(key , defaultValue)));
  }


  static Function> systemProperty(Class qualifier) {
    return (key) -> qualifiedParameter()
        .andThen(k -> ofNullable(getProperty(k)))
        .apply(qualifier , key);
  }

  static Function> systemProperty(Class qualifier , String defaultValue) {
    return (key) -> qualifiedParameter()
        .andThen(k -> ofNullable(getProperty(k , defaultValue)))
        .apply(qualifier , key);
  }


  static Function> systemPropertyBoolean(Class qualifier) {
    return (key) -> systemProperty(qualifier)
        .apply(key)
        .flatMap(convertToBoolean());
  }

  static Function> systemPropertyBoolean(Class qualifier , String defaultValue) {
    return (key) -> systemProperty(qualifier, defaultValue)
        .apply(key)
        .flatMap(convertToBoolean());
  }

  static Function> systemPropertyInt(Class qualifier) {
    return (key) -> systemProperty(qualifier)
        .apply(key)
        .flatMap(convertToInteger());
  }

  static Function> systemPropertyInt(Class qualifier , String defaultValue) {
    return (key) -> systemProperty(qualifier, defaultValue)
        .apply(key)
        .flatMap(convertToInteger());
  }

  static Function> systemPropertyDouble(Class qualifier) {
    return (key) -> systemProperty(qualifier)
        .apply(key)
        .flatMap(convertToDouble());
  }

  static Function> systemPropertyDouble(Class qualifier , String defaultValue) {
    return (key) -> systemProperty(qualifier, defaultValue)
        .apply(key)
        .flatMap(convertToDouble());
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy