1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-07-04 08:01:30 -07:00
Abacus/src/main/java/org/nwapw/abacus/function/Operator.java

77 lines
1.7 KiB
Java
Raw Normal View History

package org.nwapw.abacus.function;
/**
* A class that represents a single infix operator.
*/
public class Operator {
/**
* The associativity of the operator.
*/
private OperatorAssociativity associativity;
2017-07-28 10:26:25 -07:00
/**
* The type of this operator.
*/
private OperatorType type;
/**
* The precedence of the operator.
*/
private int precedence;
/**
* The function that is called by this operator.
*/
private Function function;
/**
* Creates a new operator with the given parameters.
2017-07-30 21:11:32 -07:00
*
* @param associativity the associativity of the operator.
2017-08-05 16:15:30 -07:00
* @param operatorType the type of this operator, like binary infix or unary postfix.
2017-07-30 21:11:32 -07:00
* @param precedence the precedence of the operator.
* @param function the function that the operator calls.
*/
2017-07-30 21:11:32 -07:00
public Operator(OperatorAssociativity associativity, OperatorType operatorType, int precedence, Function function) {
this.associativity = associativity;
2017-07-28 11:14:45 -07:00
this.type = operatorType;
this.precedence = precedence;
this.function = function;
}
/**
* Gets the operator's associativity.
2017-07-30 21:11:32 -07:00
*
* @return the associativity.
*/
public OperatorAssociativity getAssociativity() {
return associativity;
}
2017-07-28 10:26:25 -07:00
/**
* Gets the operator's type.
2017-07-30 21:11:32 -07:00
*
2017-07-28 10:26:25 -07:00
* @return the type.
*/
public OperatorType getType() {
return type;
}
/**
* Gets the operator's precedence.
2017-07-30 21:11:32 -07:00
*
* @return the precedence.
*/
public int getPrecedence() {
return precedence;
}
/**
* Gets the operator's function.
2017-07-30 21:11:32 -07:00
*
* @return the function.
*/
public Function getFunction() {
return function;
}
}