88import com .github .sidhant92 .boolparser .exception .InvalidContainerTypeException ;
99import com .github .sidhant92 .boolparser .exception .InvalidDataType ;
1010import com .github .sidhant92 .boolparser .operator .logical .AbstractOperator ;
11- import lombok .extern .slf4j .Slf4j ;
1211
1312/**
1413 * @author sidhant.aggarwal
1514 * @since 05/03/2023
1615 */
17- @ Slf4j
1816public class OperatorService {
1917 public OperatorService () {
2018 DataTypeFactory .initialize ();
@@ -25,16 +23,13 @@ public boolean evaluateLogicalOperator(final Operator operator, final ContainerD
2523 final Object leftOperand , final Object ... rightOperands ) {
2624 final AbstractOperator abstractOperator = OperatorFactory .getLogicalOperator (operator );
2725 if (!abstractOperator .getAllowedContainerTypes ().contains (containerDataType )) {
28- log .error ("Invalid left container type {} for operator {}" , containerDataType , operator );
29- throw new InvalidContainerTypeException ();
26+ throw new InvalidContainerTypeException (String .format ("Invalid left container type %s for operator %s" , containerDataType , operator ));
3027 }
3128 if (!abstractOperator .getAllowedDataTypes ().contains (dataType )) {
32- log .error ("Invalid left operand data type {} for operator {}" , dataType , operator );
33- throw new InvalidDataType ();
29+ throw new InvalidDataType (String .format ("Invalid left operand data type %s for operator %s" , dataType , operator ));
3430 }
3531 if (!containerDataType .isValid (dataType , leftOperand )) {
36- log .error ("Validation failed for the operator {} for the operand {}" , operator , leftOperand );
37- throw new InvalidDataType ();
32+ throw new InvalidDataType (String .format ("Validation failed for the operator %s for the operand %s" , operator , leftOperand ));
3833 }
3934 return OperatorFactory .getLogicalOperator (operator ).evaluate (containerDataType , dataType , leftOperand , rightOperands );
4035 }
@@ -43,24 +38,19 @@ public Object evaluateArithmeticOperator(final Object leftOperand, final DataTyp
4338 final DataType rightDataType , final Operator operator , final ContainerDataType containerDataType ) {
4439 final com .github .sidhant92 .boolparser .operator .arithmetic .AbstractOperator abstractOperator = OperatorFactory .getArithmeticOperator (operator );
4540 if (!abstractOperator .getAllowedContainerTypes ().contains (containerDataType )) {
46- log .error ("Invalid left container type {} for operator {}" , containerDataType , operator );
47- throw new InvalidContainerTypeException ();
41+ throw new InvalidContainerTypeException (String .format ("Invalid left container type %s for operator %s" , containerDataType , operator ));
4842 }
4943 if (!abstractOperator .getAllowedDataTypes ().contains (leftDataType )) {
50- log .error ("Invalid left operand data type {} for operator {}" , leftDataType , operator );
51- throw new InvalidDataType ();
44+ throw new InvalidDataType (String .format ("Invalid left operand data type %s for operator %s" , leftDataType , operator ));
5245 }
5346 if (!containerDataType .isValid (leftDataType , leftOperand )) {
54- log .error ("Validation failed for the operator {} for the operand {}" , operator , leftOperand );
55- throw new InvalidDataType ();
47+ throw new InvalidDataType (String .format ("Validation failed for the operator %s for the operand %s" , operator , leftOperand ));
5648 }
5749 if (Objects .nonNull (rightDataType ) && !abstractOperator .getAllowedDataTypes ().contains (rightDataType )) {
58- log .error ("Invalid left operand data type {} for operator {}" , rightDataType , operator );
59- throw new InvalidDataType ();
50+ throw new InvalidDataType (String .format ("Invalid left operand data type %s for operator %s" , rightDataType , operator ));
6051 }
6152 if (Objects .nonNull (rightOperand ) && !containerDataType .isValid (rightDataType , rightOperand )) {
62- log .error ("Validation failed for the operator {} for the operand {}" , operator , rightDataType );
63- throw new InvalidDataType ();
53+ throw new InvalidDataType (String .format ("Validation failed for the operator %s for the operand %s" , operator , rightDataType ));
6454 }
6555 return OperatorFactory .getArithmeticOperator (operator ).evaluate (leftOperand , leftDataType , rightOperand , rightDataType );
6656 }
0 commit comments