/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.presidentio.testdatagenerator.provider;

import com.presidentio.testdatagenerator.cons.PropConst;
import com.presidentio.testdatagenerator.context.Context;
import com.presidentio.testdatagenerator.model.Field;

import java.util.Map;

public class CounterProvider implements ValueProvider {

    public static final String INC = "++";
    public static final String DEC = "--";
    public static final String EQ = "==";

    private String var;

    private String op = "++";

    @Override
    public void init(Map<String, String> props) {
        if (props.containsKey(PropConst.OP)) {
            op = props.get(PropConst.OP);
        }
        var = props.get(PropConst.VAR);
        if (var == null) {
            throw new IllegalArgumentException("Var does not specified or null");
        }
    }

    @Override
    public Object nextValue(Context context, Field field) {
        Map<String, Object> vars = context.getVariables();
        Long varVal = Long.valueOf(vars.get(var).toString());
        if (varVal == null) {
            varVal = 0L;
        }
        Long newVal;

        switch (op) {
            case INC:
                newVal = varVal + 1;
                break;
            case DEC:
                newVal = varVal - 1;
                break;
            case EQ:
                newVal = varVal;
                break;
            default:
                throw new RuntimeException("Unknown operation: " + op);
        }
        vars.put(var, newVal);
        return TypeConverter.convert(varVal.toString(), field.getType());
    }
}

@@ -177,16 +177,20 @@
 se at%0A *
+ %3Cp%3E
 %0A * http
@@ -230,16 +230,20 @@
 E-2.0%0A *
+ %3Cp%3E
 %0A * Unle
@@ -1523,16 +1523,84 @@
    Long 
+varVal;%0A        synchronized (context.getVariables()) %7B%0A            
 varVal =
@@ -1644,24 +1644,28 @@
 ));%0A        
+    
 if (varVal =
@@ -1678,32 +1678,36 @@
 ) %7B%0A            
+   
+ 
 varVal = 0L;%0A   
@@ -1703,16 +1703,20 @@
 l = 0L;%0A
+    
         
@@ -1721,24 +1721,28 @@
   %7D%0A        
+    
 Long newVal;
@@ -1751,16 +1751,20 @@
         
+ 
+   
 switch (
@@ -1777,24 +1777,28 @@
             
+    
 case INC:%0A  
@@ -1803,32 +1803,36 @@
                 
+  
+  
 newVal = varVal 
@@ -1844,39 +1844,47 @@
                 
+    
 break;%0A
+    
             case
@@ -1897,32 +1897,36 @@
                 
+    
 newVal = varVal 
@@ -1938,32 +1938,36 @@
                 
+    
 break;%0A         
@@ -1965,24 +1965,28 @@
             
+ 
+   
 case EQ:%0A   
@@ -1982,16 +1982,20 @@
 ase EQ:%0A
+    
         
@@ -2027,39 +2027,47 @@
                 
+   
+ 
 break;%0A
+    
             defa
@@ -2071,16 +2071,20 @@
 efault:%0A
+    
         
@@ -2147,34 +2147,42 @@
  + op);%0A        
-%7D%0A
+    %7D%0A    
         vars.put
@@ -2196,16 +2196,26 @@
 ewVal);%0A
+        %7D%0A
         

fix async problem