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

org.evosuite.symbolic.expr.bv.StringMultipleToIntegerExpression Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
/**
 * 
 */
package org.evosuite.symbolic.expr.bv;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.evosuite.Properties;
import org.evosuite.symbolic.ConstraintTooLongException;
import org.evosuite.symbolic.DSEStats;
import org.evosuite.symbolic.expr.AbstractExpression;
import org.evosuite.symbolic.expr.Expression;
import org.evosuite.symbolic.expr.ExpressionVisitor;
import org.evosuite.symbolic.expr.MultipleExpression;
import org.evosuite.symbolic.expr.Operator;
import org.evosuite.symbolic.expr.Variable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 

* StringMultipleExpression class. *

* * @author krusev */ public final class StringMultipleToIntegerExpression extends AbstractExpression implements IntegerValue, MultipleExpression { private static final long serialVersionUID = 7172041118401792672L; private final ArrayList> other_v; private final Operator op; private final Expression left; private final Expression right; protected static final Logger log = LoggerFactory.getLogger(StringMultipleToIntegerExpression.class); /** *

* Constructor for StringMultipleExpression. *

* * @param _left * a {@link org.evosuite.symbolic.expr.Expression} object. * @param _op * a {@link org.evosuite.symbolic.expr.Operator} object. * @param _right * a {@link org.evosuite.symbolic.expr.Expression} object. * @param _other * a {@link java.util.ArrayList} object. * @param con * a {@link java.lang.String} object. */ public StringMultipleToIntegerExpression(Expression _left, Operator _op, Expression _right, ArrayList> _other, Long con) { super(con, 1 + _left.getSize() + _right.getSize() + countSizes(_other), _left.containsSymbolicVariable() || _right.containsSymbolicVariable() || containsSymbolicVariable(_other)); this.op = _op; this.left = _left; this.right = _right; this.other_v = _other; if (getSize() > Properties.DSE_CONSTRAINT_LENGTH) { DSEStats.getInstance().reportConstraintTooLong(getSize()); throw new ConstraintTooLongException(getSize()); } } /** *

* getOther *

* * @return the other */ @Override public ArrayList> getOther() { return other_v; } /** {@inheritDoc} */ @Override public Operator getOperator() { return op; } /** {@inheritDoc} */ @Override public Expression getLeftOperand() { return left; } /** {@inheritDoc} */ @Override public Expression getRightOperand() { return right; } /** {@inheritDoc} */ @Override public String toString() { String str_other_v = ""; for (int i = 0; i < this.other_v.size(); i++) { str_other_v += " " + this.other_v.get(i).toString(); } return "(" + left + op.toString() + (right == null ? "" : right) + str_other_v + ")"; } /** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof StringMultipleToIntegerExpression) { StringMultipleToIntegerExpression other = (StringMultipleToIntegerExpression) obj; return this.op.equals(other.op) && this.left.equals(other.left) && this.right.equals(other.right) && this.other_v.equals(other.other_v); } return false; } @Override public int hashCode() { return this.op.hashCode() + this.left.hashCode() + this.right.hashCode() + this.other_v.hashCode(); } private static boolean containsSymbolicVariable(ArrayList> list) { for (Expression e : list) { if (e.containsSymbolicVariable()) { return true; } } return false; } private static int countSizes(ArrayList> list) { int retVal = 0; for (Expression e : list) { retVal += e.getSize(); } return retVal; } @Override public Set> getVariables() { Set> variables = new HashSet>(); variables.addAll(this.left.getVariables()); variables.addAll(this.right.getVariables()); for (Expression other_e : this.other_v) { variables.addAll(other_e.getVariables()); } return variables; } @Override public Set getConstants() { Set result = new HashSet(); result.addAll(this.left.getConstants()); result.addAll(this.right.getConstants()); for (Expression other_e : this.other_v) { result.addAll(other_e.getConstants()); } return result; } @Override public K accept(ExpressionVisitor v, V arg) { return v.visit(this, arg); } }