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

fj.Primitive Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 5.0
Show newest version
package fj;

/**
 * Functions that convert between Java primitive types.
 *
 * @version %build.number%
 */
public final class Primitive {
  private Primitive() {
    throw new UnsupportedOperationException();
  }

  // BEGIN Boolean ->

  /**
   * A function that converts booleans to bytes.
   */
  public static final F Boolean_Byte = new F() {
    public Byte f(final Boolean b) {
      return (byte) (b ? 1 : 0);
    }
  };

  /**
   * A function that converts booleans to characters.
   */
  public static final F Boolean_Character = new F() {
    public Character f(final Boolean b) {
      return (char) (b ? 1 : 0);
    }
  };

  /**
   * A function that converts booleans to doubles.
   */
  public static final F Boolean_Double = new F() {
    public Double f(final Boolean b) {
      return b ? 1D : 0D;
    }
  };

  /**
   * A function that converts booleans to floats.
   */
  public static final F Boolean_Float = new F() {
    public Float f(final Boolean b) {
      return b ? 1F : 0F;
    }
  };

  /**
   * A function that converts booleans to integers.
   */
  public static final F Boolean_Integer = new F() {
    public Integer f(final Boolean b) {
      return b ? 1 : 0;
    }
  };

  /**
   * A function that converts booleans to longs.
   */
  public static final F Boolean_Long = new F() {
    public Long f(final Boolean b) {
      return b ? 1L : 0L;
    }
  };

  /**
   * A function that converts booleans to shorts.
   */
  public static final F Boolean_Short = new F() {
    public Short f(final Boolean b) {
      return (short) (b ? 1 : 0);
    }
  };

  // END Boolean ->

  // BEGIN Byte ->

  /**
   * A function that converts bytes to booleans.
   */
  public static final F Byte_Boolean = new F() {
    public Boolean f(final Byte b) {
      return b != 0;
    }
  };

  /**
   * A function that converts bytes to characters.
   */
  public static final F Byte_Character = new F() {
    public Character f(final Byte b) {
      return (char) (byte) b;
    }
  };

  /**
   * A function that converts bytes to doubles.
   */
  public static final F Byte_Double = new F() {
    public Double f(final Byte b) {
      return (double) b;
    }
  };

  /**
   * A function that converts bytes to floats.
   */
  public static final F Byte_Float = new F() {
    public Float f(final Byte b) {
      return (float) b;
    }
  };

  /**
   * A function that converts bytes to integers.
   */
  public static final F Byte_Integer = new F() {
    public Integer f(final Byte b) {
      return (int) b;
    }
  };

  /**
   * A function that converts bytes to longs.
   */
  public static final F Byte_Long = new F() {
    public Long f(final Byte b) {
      return (long) b;
    }
  };

  /**
   * A function that converts bytes to shorts.
   */
  public static final F Byte_Short = new F() {
    public Short f(final Byte b) {
      return (short) b;
    }
  };

  // END Byte ->

  // BEGIN Character ->

  /**
   * A function that converts characters to booleans.
   */
  public static final F Character_Boolean = new F() {
    public Boolean f(final Character c) {
      return c != 0;
    }
  };

  /**
   * A function that converts characters to bytes.
   */
  public static final F Character_Byte = new F() {
    public Byte f(final Character c) {
      return (byte) (char) c;
    }
  };

  /**
   * A function that converts characters to doubles.
   */
  public static final F Character_Double = new F() {
    public Double f(final Character c) {
      return (double) (char) c;
    }
  };

  /**
   * A function that converts characters to floats.
   */
  public static final F Character_Float = new F() {
    public Float f(final Character c) {
      return (float) (char) c;
    }
  };

  /**
   * A function that converts characters to integers.
   */
  public static final F Character_Integer = new F() {
    public Integer f(final Character c) {
      return (int) (char) c;
    }
  };

  /**
   * A function that converts characters to longs.
   */
  public static final F Character_Long = new F() {
    public Long f(final Character c) {
      return (long) (char) c;
    }
  };

  /**
   * A function that converts characters to shorts.
   */
  public static final F Character_Short = new F() {
    public Short f(final Character c) {
      return (short) (char) c;
    }
  };

  // END Character ->

  // BEGIN Double ->

  /**
   * A function that converts doubles to booleans.
   */
  public static final F Double_Boolean = new F() {
    public Boolean f(final Double d) {
      return d != 0D;
    }
  };

  /**
   * A function that converts doubles to bytes.
   */
  public static final F Double_Byte = new F() {
    public Byte f(final Double d) {
      return (byte) (double) d;
    }
  };

  /**
   * A function that converts doubles to characters.
   */
  public static final F Double_Character = new F() {
    public Character f(final Double d) {
      return (char) (double) d;
    }
  };

  /**
   * A function that converts doubles to floats.
   */
  public static final F Double_Float = new F() {
    public Float f(final Double d) {
      return (float) (double) d;
    }
  };

  /**
   * A function that converts doubles to integers.
   */
  public static final F Double_Integer = new F() {
    public Integer f(final Double d) {
      return (int) (double) d;
    }
  };

  /**
   * A function that converts doubles to longs.
   */
  public static final F Double_Long = new F() {
    public Long f(final Double d) {
      return (long) (double) d;
    }
  };

  /**
   * A function that converts doubles to shorts.
   */
  public static final F Double_Short = new F() {
    public Short f(final Double d) {
      return (short) (double) d;
    }
  };

  // END Double ->

  // BEGIN Float ->

  /**
   * A function that converts floats to booleans.
   */
  public static final F Float_Boolean = new F() {
    public Boolean f(final Float f) {
      return f != 0F;
    }
  };

  /**
   * A function that converts floats to bytes.
   */
  public static final F Float_Byte = new F() {
    public Byte f(final Float f) {
      return (byte) (float) f;
    }
  };

  /**
   * A function that converts floats to characters.
   */
  public static final F Float_Character = new F() {
    public Character f(final Float f) {
      return (char) (float) f;
    }
  };

  /**
   * A function that converts floats to doubles.
   */
  public static final F Float_Double = new F() {
    public Double f(final Float f) {
      return (double) (float) f;
    }
  };

  /**
   * A function that converts floats to integers.
   */
  public static final F Float_Integer = new F() {
    public Integer f(final Float f) {
      return (int) (float) f;
    }
  };

  /**
   * A function that converts floats to longs.
   */
  public static final F Float_Long = new F() {
    public Long f(final Float f) {
      return (long) (float) f;
    }
  };

  /**
   * A function that converts floats to shorts.
   */
  public static final F Float_Short = new F() {
    public Short f(final Float f) {
      return (short) (float) f;
    }
  };

  // END Float ->

  // BEGIN Integer ->

  /**
   * A function that converts integers to booleans.
   */
  public static final F Integer_Boolean = new F() {
    public Boolean f(final Integer i) {
      return i != 0;
    }
  };

  /**
   * A function that converts integers to bytes.
   */
  public static final F Integer_Byte = new F() {
    public Byte f(final Integer i) {
      return (byte) (int) i;
    }
  };

  /**
   * A function that converts integers to characters.
   */
  public static final F Integer_Character = new F() {
    public Character f(final Integer i) {
      return (char) (int) i;
    }
  };

  /**
   * A function that converts integers to doubles.
   */
  public static final F Integer_Double = new F() {
    public Double f(final Integer i) {
      return (double) i;
    }
  };

  /**
   * A function that converts integers to floats.
   */
  public static final F Integer_Float = new F() {
    public Float f(final Integer i) {
      return (float) i;
    }
  };

  /**
   * A function that converts integers to longs.
   */
  public static final F Integer_Long = new F() {
    public Long f(final Integer i) {
      return (long) i;
    }
  };

  /**
   * A function that converts integers to shorts.
   */
  public static final F Integer_Short = new F() {
    public Short f(final Integer i) {
      return (short) (int) i;
    }
  };

  // END Integer ->

  // BEGIN Long ->

  /**
   * A function that converts longs to booleans.
   */
  public static final F Long_Boolean = new F() {
    public Boolean f(final Long l) {
      return l != 0L;
    }
  };

  /**
   * A function that converts longs to bytes.
   */
  public static final F Long_Byte = new F() {
    public Byte f(final Long l) {
      return (byte) (long) l;
    }
  };

  /**
   * A function that converts longs to characters.
   */
  public static final F Long_Character = new F() {
    public Character f(final Long l) {
      return (char) (long) l;
    }
  };

  /**
   * A function that converts longs to doubles.
   */
  public static final F Long_Double = new F() {
    public Double f(final Long l) {
      return (double) (long) l;
    }
  };

  /**
   * A function that converts longs to floats.
   */
  public static final F Long_Float = new F() {
    public Float f(final Long l) {
      return (float) (long) l;
    }
  };

  /**
   * A function that converts longs to integers.
   */
  public static final F Long_Integer = new F() {
    public Integer f(final Long l) {
      return (int) (long) l;
    }
  };

  /**
   * A function that converts longs to shorts.
   */
  public static final F Long_Short = new F() {
    public Short f(final Long l) {
      return (short) (long) l;
    }
  };

  // END Long ->

  // BEGIN Short ->

  /**
   * A function that converts shorts to booleans.
   */
  public static final F Short_Boolean = new F() {
    public Boolean f(final Short s) {
      return s != 0;
    }
  };

  /**
   * A function that converts shorts to bytes.
   */
  public static final F Short_Byte = new F() {
    public Byte f(final Short s) {
      return (byte) (short) s;
    }
  };

  /**
   * A function that converts shorts to characters.
   */
  public static final F Short_Character = new F() {
    public Character f(final Short s) {
      return (char) (short) s;
    }
  };

  /**
   * A function that converts shorts to doubles.
   */
  public static final F Short_Double = new F() {
    public Double f(final Short s) {
      return (double) (short) s;
    }
  };

  /**
   * A function that converts shorts to floats.
   */
  public static final F Short_Float = new F() {
    public Float f(final Short s) {
      return (float) (short) s;
    }
  };

  /**
   * A function that converts shorts to integers.
   */
  public static final F Short_Integer = new F() {
    public Integer f(final Short s) {
      return (int) (short) s;
    }
  };

  /**
   * A function that converts shorts to longs.
   */
  public static final F Short_Long = new F() {
    public Long f(final Short s) {
      return (long) (short) s;
    }
  };

  // END Short
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy