Java Number Negate negateExpression(String expression)

Here you can find the source of negateExpression(String expression)

Description

negate Expression

License

Open Source License

Declaration

private static String negateExpression(String expression) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final char TERM_DELIMITER = '+';
    private static final char FACTOR_DELIMITER = '*';
    private static final char NEGATION_DELIMITER = '!';

    private static String negateExpression(String expression) {
        String result = null;//from  w  w w .ja va  2s.  c  o  m
        if (expression.contains("" + TERM_DELIMITER) || expression.contains("" + FACTOR_DELIMITER)) {
            result = NEGATION_DELIMITER + "(" + expression + ")";
        } else {
            if (expression.startsWith("!")) {
                result = expression.substring(1, expression.length());
            } else if (expression.endsWith("'")) {
                result = expression.substring(0, expression.length() - 1);
            } else {
                result = "!" + expression;
            }
        }
        return result;
    }
}

Related

  1. negate(int[] x, int Max)
  2. negate(String expr)
  3. negate(String string, String trueValue, String falseValue)
  4. negate(String value)
  5. negateExact(double a)
  6. negateInPlace(float[] in)
  7. Negation(String StartIP, String netmask)
  8. negative(float a)
  9. negative(int b)