From 6d76f07d4947115e5db0ed4258facb63859d289f Mon Sep 17 00:00:00 2001 From: eric567 Date: Tue, 19 Jul 2016 07:49:30 +0800 Subject: [PATCH] refactoring with code --- src/main/java/com/github/eric/Function.java | 32 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/eric/Function.java b/src/main/java/com/github/eric/Function.java index 93c25bf..6214e06 100644 --- a/src/main/java/com/github/eric/Function.java +++ b/src/main/java/com/github/eric/Function.java @@ -10,6 +10,14 @@ public class Function { private List args; private int reslut; + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + public Operator getOperator() { return operator; } @@ -33,16 +41,34 @@ public Function transform(ValuePair valuePair) if(valuePair.first==null) return null; - Object first = valuePair.first; + Object first = ValuePairUtils.first(valuePair); + Object rest = ValuePairUtils.rest(valuePair); + Function function=new Function(); if(first instanceof String) { if(((String) first).equalsIgnoreCase("+")) { - Function function=new Function(); + function.setOperator(Operator.PLUS); } + }else if(rest instanceof ValuePair) + { + ValuePair vp= (ValuePair) rest; + function=travleValuePair(function,vp); } - return null; + return function; + } + + private Function travleValuePair(Function function, ValuePair vp) { + if (vp==null||vp.first==null) + return function; + + Object first = vp.first; + function.getArgs().add(first); + if(vp.rest + !=null) + function.getArgs().add(vp.rest); + return function; } }