/*
 * #%L
 * SciJava mathematical expression parser.
 * %%
 * Copyright (C) 2015 Board of Regents of the University of
 * Wisconsin-Madison.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * #L%
 */

package org.scijava.sjep;

import java.util.Arrays;
import java.util.List;

import org.scijava.sjep.Operator.Associativity;

/**
 * A collection of standard {@link Operator}s.
 *
 * @author Curtis Rueden
 */
public final class Operators {

	public static final Operator NEG = new DefaultOperator("-", 1,
		Associativity.RIGHT, 2);

	public static final Operator ADD = new DefaultOperator("+", 2,
		Associativity.EITHER, 2);
	public static final Operator SUB = new DefaultOperator("-", 2,
		Associativity.LEFT, 2);
	public static final Operator MUL = new DefaultOperator("*", 2,
		Associativity.EITHER, 3);
	public static final Operator DIV = new DefaultOperator("/", 2,
		Associativity.LEFT, 3);
	public static final Operator POW = new DefaultOperator("^", 2,
		Associativity.RIGHT, 4);

	private Operators() {
		// NB: Prevent instantiation of utility class.
	}

	/** Gets the standard list of operators. */
	public static List<Operator> standardList() {
		return Arrays.asList(Operators.NEG, Operators.ADD, Operators.SUB,
			Operators.MUL, Operators.DIV, Operators.POW);
	}

}

@@ -1580,16 +1580,200 @@
 ivity;%0A%0A
+import static org.scijava.sjep.Operator.Associativity.EITHER;%0Aimport static org.scijava.sjep.Operator.Associativity.LEFT;%0Aimport static org.scijava.sjep.Operator.Associativity.RIGHT;%0A%0A
 /**%0A * A
@@ -1879,16 +1879,33 @@
 tors %7B%0A%0A
+%09// -- unary --%0A%0A
 %09public 
@@ -1936,62 +1936,55 @@
 G = 
-new DefaultOperator(%22-%22, 1,%0A%09%09Associativity.RIGHT, 2);
+op(%22-%22, 1, RIGHT, 2);%0A%0A%09// -- multiplicative --
 %0A%0A%09p
@@ -2015,66 +2015,33 @@
 tor 
-ADD = new DefaultOperator(%22+
+MUL = op(%22*
 %22, 2,
-%0A%09%09Associativity.
+ 
 EITHER, 
 2);%0A
@@ -2036,17 +2036,17 @@
 EITHER, 
-2
+3
 );%0A%09publ
@@ -2074,68 +2074,56 @@
 tor 
-SUB = new DefaultOperator(%22-
+DIV = op(%22/
 %22, 2,
-%0A%09%09Associativity.
+ 
 LEFT, 
-2
+3
 );%0A
+%0A%09// -- additive --%0A%0A
 %09pub
@@ -2152,66 +2152,33 @@
 tor 
-MUL = new DefaultOperator(%22*
+ADD = op(%22+
 %22, 2,
-%0A%09%09Associativity.
+ 
 EITHER, 
 3);%0A
@@ -2165,33 +2165,33 @@
 %22+%22, 2, EITHER, 
-3
+2
 );%0A%09public stati
@@ -2211,68 +2211,53 @@
 tor 
-DIV = new DefaultOperator(%22/
+SUB = op(%22-
 %22, 2,
-%0A%09%09Associativity.
+ 
 LEFT, 
-3
+2
 );%0A
+%0A%09// -- extra --%0A%0A
 %09pub
@@ -2292,52 +2292,19 @@
 W = 
-new DefaultOperator(%22%5E%22, 2,%0A%09%09Associativity.
+op(%22%5E%22, 2, 
 RIGH
@@ -2600,10 +2600,243 @@
 W);%0A%09%7D%0A%0A
+%09// -- Helper methods --%0A%0A%09private static Operator op(final String symbol, final int arity,%0A%09%09final Associativity associativity, final double precedence)%0A%09%7B%0A%09%09return new DefaultOperator(symbol, arity, associativity, precedence);%0A%09%7D%0A%0A
 %7D%0A

streamline declaration of standard ops