for(int i =0;i<jsonArray.lenth();i++){ Operator op = new Operator(); op.name = //get your string here op.id = //get from json object op.status = //get from json object operatorList.add(op); }
Operator plus = new Operator() { public Double do(Double x, Double y) { return x + y; } };
Operator plus = new Operator('+') { double apply(double left, double right) { return left + right; } };
class OperatorFactory { Operator createOperator(String symbol) { if("+".equals(symbol)) return new Operator() { Operator operate(Operand a, Operand b) { return new Operand(a.value + b.value); } }; if("-".equals(symbol)) /* continued */ } }
Operator factorial = new Operator("!", 2, true, Operator.PRECEDENCE_POWER + 1) { @Override public double apply(double... args) { final long arg = (long) args[0]; if ((double) arg != args[0]) { throw new IllegalArgumentException("Operand for factorial has to be an integer"); } if (arg < 0) { throw new IllegalArgumentException("The operand of the factorial can not " + "be " + "less than zero"); } double result = 1; for (int i = 1; i <= arg; i++) { result *= i; } return result; } };
public class RunnableTask implements Runnable { // consider using a getter public int res; private int a; private char c; private int i; public RunnableTask(int a, char c, int i) { this.a = a; this.c = c; this.i = i; } @Override public void run() { Operator ope = new Operator(); this.res = ope.operar(a, this.c, this.i); } }
public static void startServer() { try { final ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(12345); final List<Operator> operators = new ArrayList<>(); final int nOperators = /* your choice */; for (int i = 0; i < nOperators; i++) { operators.add(i, new Operator()); } final int parallelism = Runtime.getRuntime().availableProcessors(); ForkJoinPool pool = new ForkJoinPool(parallelism); pool.submit(() -> new Thread(() -> { int i = 0; while (true) { try { operators.get(i).newOperation(serverSocketChannel.accept()); i++; if (i == nOperators) { i = 0; } } catch (IOException ignored) { } } })).fork().invoke().start(); } catch (IOException ignored) { } }
result.add(new Operator("+")); ++pos; break;
s1.push(new Operator(tempHolder, "Function")); } else {