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

com.ctrip.framework.apollo.util.function.Functions Maven / Gradle / Ivy

The newest version!
package com.ctrip.framework.apollo.util.function;

import java.util.Date;

import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.util.parser.ParserException;
import com.ctrip.framework.apollo.util.parser.Parsers;
import com.google.common.base.Function;

/**
 * @author Jason Song([email protected])
 */
public interface Functions {
  Function TO_INT_FUNCTION = new Function() {
    @Override
    public Integer apply(String input) {
      return Integer.parseInt(input);
    }
  };
  Function TO_LONG_FUNCTION = new Function() {
    @Override
    public Long apply(String input) {
      return Long.parseLong(input);
    }
  };
  Function TO_SHORT_FUNCTION = new Function() {
    @Override
    public Short apply(String input) {
      return Short.parseShort(input);
    }
  };
  Function TO_FLOAT_FUNCTION = new Function() {
    @Override
    public Float apply(String input) {
      return Float.parseFloat(input);
    }
  };
  Function TO_DOUBLE_FUNCTION = new Function() {
    @Override
    public Double apply(String input) {
      return Double.parseDouble(input);
    }
  };
  Function TO_BYTE_FUNCTION = new Function() {
    @Override
    public Byte apply(String input) {
      return Byte.parseByte(input);
    }
  };
  Function TO_BOOLEAN_FUNCTION = new Function() {
    @Override
    public Boolean apply(String input) {
      return Boolean.parseBoolean(input);
    }
  };
  Function TO_DATE_FUNCTION = new Function() {
    @Override
    public Date apply(String input) {
      try {
        return Parsers.forDate().parse(input);
      } catch (ParserException ex) {
        throw new ApolloConfigException("Parse date failed", ex);
      }
    }
  };
  Function TO_DURATION_FUNCTION = new Function() {
    @Override
    public Long apply(String input) {
      try {
        return Parsers.forDuration().parseToMillis(input);
      } catch (ParserException ex) {
        throw new ApolloConfigException("Parse duration failed", ex);
      }
    }
  };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy