/*
 * Copyright 2015 - 2016 Nebula Bay.
 *
 * 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.tascape.reactor.data;

import com.tascape.reactor.SystemConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author linsong wang
 */
public class CaseIterationData extends AbstractCaseData {
    private static final Logger LOG = LoggerFactory.getLogger(CaseIterationData.class);
    
    public static final String USE_ITERATIONS = "useIterations";

    private int iteration = 1;

    private int iterations = 1;

    public CaseIterationData() {
    }

    private CaseIterationData(int iteration, int iterations) {
        this.iteration = iteration;
        this.iterations = iterations;
    }

    public CaseIterationData[] getData(String sysPropIterations) {
        String n = SystemConfiguration.getInstance().getProperty(sysPropIterations);
        return useIterations(n);
    }

    public CaseIterationData[] useIterations(String n) {
        int iters = 1;
        try {
            iters = Integer.parseInt(n);
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
        }
        CaseIterationData[] data = new CaseIterationData[iters];
        for (int i = 0; i < iters; i++) {
            data[i] = new CaseIterationData(i, iters);
        }
        return data;
    }

    public CaseIterationData[] useSystemProperty(String sysPropIterations) {
        String n = SystemConfiguration.getInstance().getProperty(sysPropIterations);
        return useIterations(n);
    }

    @Override
    public String getValue() {
        int len = (this.iterations + "").length();
        return String.format("%0" + len + "d/%d", this.iteration + 1, this.iterations);
    }

    public int getIteration() {
        return iteration;
    }

    public int getIterations() {
        return iterations;
    }
}

@@ -945,20 +945,16 @@
 lass);%0D%0A
-    
 %0D%0A    pu
@@ -1318,32 +1318,25 @@
 Data(String 
-sysPropI
+i
 terations) %7B
@@ -1349,94 +1349,8 @@
     
-String n = SystemConfiguration.getInstance().getProperty(sysPropIterations);%0D%0A        
 retu
@@ -1348,32 +1348,43 @@
      return useI
+terations(i
 terations(n);%0D%0A 
@@ -1368,34 +1368,32 @@
 tions(iterations
-(n
 );%0D%0A    %7D%0D%0A%0D%0A   
@@ -1441,17 +1441,26 @@
 (String 
-n
+iterations
 ) %7B%0D%0A   
@@ -1532,17 +1532,26 @@
 arseInt(
-n
+iterations
 );%0D%0A    

set default method to useIterations