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

com.bpodgursky.jbool_expressions.Literal Maven / Gradle / Ivy

There is a newer version: 8.1.2
Show newest version
package com.bpodgursky.jbool_expressions;

import com.bpodgursky.jbool_expressions.rules.Rule;

import java.util.List;

public class Literal extends Expression{
  public static final String EXPR_TYPE = "literal";

  private final boolean value;

  private static final Literal TRUE = new Literal(true);
  private static final Literal FALSE = new Literal(false);

  @SuppressWarnings("unchecked")
  public static  Literal getTrue(){
    return TRUE;
  }

  @SuppressWarnings("unchecked")
  public static  Literal getFalse(){
    return FALSE;
  }

  public static  Literal of(boolean value){
    if(value){
      return getTrue();
    }else{
      return getFalse();
    }
  }

  private Literal(boolean value){
    this.value = value;
  }

  public String toString(){
    return Boolean.valueOf(value).toString();
  }

  public boolean getValue(){
    return value;
  }

  @Override
  public Expression apply(List> rules) {
    return this;
  }

  @Override
  public boolean equals(Expression expr) {
    return expr instanceof Literal && ((Literal)expr).getValue() == getValue();
  }

  @Override
  public String getExprType() {
    return EXPR_TYPE;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy