예제 #1
0
 Polynomial fromString(String polynomial, boolean deepEvaluate) {
   if (deepEvaluate) {
     String[] divisors = StringManipulator.split(polynomial, ",/,");
     Polynomial[] dividing = new Polynomial[divisors.length];
     for (int i = 0; i < divisors.length; ++i) {
       String[] multipliers = StringManipulator.split(divisors[i], ",*,");
       Polynomial[] multiplying = new Polynomial[multipliers.length];
       for (int j = 0; j < multipliers.length; ++j) {
         multiplying[j] =
             new Polynomial(null, variableCode, oldvariablecode, consts)
                 .fromString(multipliers[j], variableCode, oldvariablecode, consts, false);
       }
       Polynomial multiplied = multiplying[0];
       for (int j = 1; j < multiplying.length; ++j) {
         multiplied.multiply(multiplying[j]);
       }
       dividing[i] = multiplied;
     }
     Polynomial divided = dividing[0];
     for (int i = 1; i < dividing.length; ++i) {
       divided.divide(dividing[i]);
     }
     init(divided);
     return this;
   }
   @NotNull String[] tokens = split(polynomial, ",");
   terms.ensureCapacity(tokens.length);
   signs.ensureCapacity(tokens.length + 1);
   for (@NotNull String token : tokens) {
     if (token.equals("+") || token.equals("-")) {
       signs.add(token.trim());
     } else {
       terms.add(new Term(variableCode, oldvariablecode, consts).fromString(token.trim()));
     }
   }
   if (signs.size() == terms.size() - 1) {
     signs.add(0, "+");
   }
   return this;
 }