Example usage for org.apache.commons.math.complex Complex equals

List of usage examples for org.apache.commons.math.complex Complex equals

Introduction

In this page you can find the example usage for org.apache.commons.math.complex Complex equals.

Prototype

@Override
public boolean equals(Object other) 

Source Link

Document

Test for the equality of two Complex objects.

Usage

From source file:org.renjin.primitives.Ops.java

@Deferrable
@Builtin("==")/*w w w . j  a v a2  s  . co m*/
@DataParallel
public static boolean equalTo(Complex x, Complex y) {
    return x.equals(y);
}

From source file:org.sakaiproject.tool.assessment.services.GradingService.java

public boolean getFINResult(ItemGradingData data, ItemDataIfc itemdata, Map publishedAnswerHash)
        throws FinFormatException {
    String studentanswer = "";
    boolean range;
    boolean matchresult = false;
    ComplexFormat complexFormat = new ComplexFormat();
    Complex answerComplex = null;
    Complex studentAnswerComplex = null;
    BigDecimal answerNum = null, answer1Num = null, answer2Num = null, studentAnswerNum = null;

    if (data.getPublishedAnswerId() == null) {
        return false;
    }//from   w  w  w  . ja  v  a2s .  c  o m

    AnswerIfc answerIfc = (AnswerIfc) publishedAnswerHash.get(data.getPublishedAnswerId());
    if (answerIfc == null) {
        return matchresult;
    }
    String answertext = answerIfc.getText();
    if (answertext != null) {
        StringTokenizer st = new StringTokenizer(answertext, "|");
        range = false;
        if (st.countTokens() > 1) {
            range = true;
        }

        String studentAnswerText = null;
        if (data.getAnswerText() != null) {
            studentAnswerText = data.getAnswerText().replaceAll("\\s+", "").replace(',', '.'); // in Spain, comma is used as a decimal point
        }

        if (range) {

            String answer1 = st.nextToken().trim();
            String answer2 = st.nextToken().trim();

            if (answer1 != null) {
                answer1 = answer1.trim().replace(',', '.'); // in Spain, comma is used as a decimal point     
            }
            if (answer2 != null) {
                answer2 = answer2.trim().replace(',', '.'); // in Spain, comma is used as a decimal point     
            }

            try {
                answer1Num = new BigDecimal(answer1);
                answer2Num = new BigDecimal(answer2);
            } catch (Exception e) {
                log.debug("Number is not BigDecimal: " + answer1 + " or " + answer2);
            }

            Map map = validate(studentAnswerText);
            studentAnswerNum = (BigDecimal) map.get(ANSWER_TYPE_REAL);

            matchresult = (answer1Num != null && answer2Num != null && studentAnswerNum != null
                    && (answer1Num.compareTo(studentAnswerNum) <= 0)
                    && (answer2Num.compareTo(studentAnswerNum) >= 0));
        } else { // not range
            String answer = st.nextToken().trim();

            if (answer != null) {
                answer = answer.replaceAll("\\s+", "").replace(',', '.'); // in Spain, comma is used as a decimal point     
            }

            try {
                answerNum = new BigDecimal(answer);
            } catch (NumberFormatException ex) {
                log.debug("Number is not BigDecimal: " + answer);
            }

            try {
                answerComplex = complexFormat.parse(answer);
            } catch (ParseException ex) {
                log.debug("Number is not Complex: " + answer);
            }

            if (data.getAnswerText() != null) {
                Map map = validate(studentAnswerText);

                if (answerNum != null) {
                    studentAnswerNum = (BigDecimal) map.get(ANSWER_TYPE_REAL);
                    matchresult = (studentAnswerNum != null && answerNum.compareTo(studentAnswerNum) == 0);
                } else if (answerComplex != null) {
                    studentAnswerComplex = (Complex) map.get(ANSWER_TYPE_COMPLEX);
                    matchresult = (studentAnswerComplex != null && answerComplex.equals(studentAnswerComplex));
                }
            }
        }
    }
    return matchresult;
}