*/
public PairedList<ConsCell, ConsCell> orderOfTerm(ConsCell term, ArrayList<String> variables) throws ParserException {
PairedList<ConsCell, ConsCell> orders = new PairedList<ConsCell, ConsCell>();
if (term.length() < 1)
return orders;
ConsCell current = term;
do {
if (current.getCarType() != ConsType.OPERATOR && !(current.getNextConsCell().getCarType() == ConsType.OPERATOR && (Character) current.getNextConsCell().getCar() == '^')) {
ConsCell eqn = current.singular();
boolean subtract = current.getPreviousConsCell().getCarType() == ConsType.OPERATOR && (Character) current.getPreviousConsCell().getCar() == '/';
while (!(current = current.getNextConsCell()).isNull() && !(current.getCarType() == ConsType.OPERATOR && ((Character) current.getCar() == '*' || (Character) current.getCar() == '/'))) {
if (current.getCarType() == ConsType.OPERATOR) {
if ((Character) current.getCar() == '^')
break;
if ((Character) current.getCar() == '-')
continue;
}
eqn = eqn.append(current.singular());
}
if (current.getCarType() == ConsType.OPERATOR && (Character) current.getCar() == '^') {
current = current.getPreviousConsCell();
continue;
}
eqn = eqn.getFirstConsCell();
if (!orders.containsKey(eqn))
orders.put(eqn, new ConsCell());
orders.put(eqn, orders.get(eqn).getLastConsCell().append(new ConsCell(subtract ? '-' : '+', ConsType.OPERATOR)).append(new ConsCell(BigDec.ONE, ConsType.NUMBER)).getFirstConsCell());
}
if (current.getCarType() == ConsType.OPERATOR && (Character) current.getCar() == '^') {
ConsCell head = current.getPreviousConsCell();
ConsCell left = new ConsCell();
do {
if (!(head.getCarType() == ConsType.OPERATOR && (Character) head.getCar() == '-'))
left = head.singular().append(left.getFirstConsCell());
} while (!(head = head.getPreviousConsCell()).isNull() && !(head.getCarType() == ConsType.OPERATOR && ((Character) head.getCar() == '*' || (Character) head.getCar() == '/')));
left = left.getFirstConsCell();
boolean subtract = left.getCarType() == ConsType.OPERATOR && (Character) left.getCar() == '/';
if (subtract)
left = left.remove();
if (!orders.containsKey(left))
orders.put(left, new ConsCell());
head = current.getNextConsCell();
ConsCell exponent = head.singular();
while (!(head = head.getNextConsCell()).isNull() && !(head.getCarType() == ConsType.OPERATOR && ((Character) head.getCar() == '*' || (Character) head.getCar() == '/')))
exponent = exponent.append(head.singular());
exponent = exponent.getFirstConsCell();
orders.put(left, orders.get(left).getLastConsCell().append(new ConsCell(subtract ? '-' : '+', ConsType.OPERATOR)).append(exponent).getFirstConsCell());
current = head;
}
} while (!(current = current.getNextConsCell()).isNull());
for (int i = 0; i < orders.size(); i++) {
ConsCell key = orders.getKeys().get(i);
if (!parser.containsVariables(key, variables) && !parser.containsVariables(orders.get(key), variables)) {
orders.remove(key);
i--;
continue;
}