<commit_before>/*
 * The MIT License
 *
 * Copyright 2014-2017 TweetWallFX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.tweetwallfx.controls.stepengine;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import javax.json.bind.JsonbBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author <NAME>
 */
public class StepIterator implements Iterator<Step> {

    private static final Logger LOGGER = LogManager.getLogger(StepIterator.class);
    private Step current = null;
    private int stateIndex = 0;
    private final List<Step> states = new ArrayList<>();

    @Override
    public boolean hasNext() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private static class Builder {

        private final List<Step> steps = new ArrayList<>();

        public Builder addStep(String classname) {
            try {
                Object newInstance = Thread.currentThread().getContextClassLoader().loadClass(classname).getDeclaredConstructor().newInstance();
                if (newInstance instanceof Step) {
                    steps.add((Step) newInstance);
                } else {
                    LOGGER.error("Class cannot be cast to Step " + classname + ". Skipping adding the step.");
                }
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException ex) {
                LOGGER.error("Failure instatiating step for " + classname, ex);
            }
            return this;
        }

        public StepIterator build() {
            return new StepIterator(steps);
        }
    }

    public static StepIterator ofDefaultConfiguration() {
        StepIterator.Builder builder = new StepIterator.Builder();
        try (InputStream s = Thread.currentThread().getContextClassLoader().getResourceAsStream("steps.json")) {
            StepEngineConfiguration stepEngineConfig = JsonbBuilder.create().fromJson(s, StepEngineConfiguration.class);
            stepEngineConfig.steps.forEach(className -> builder.addStep(className));
        } catch (IOException ex) {
            LOGGER.error("IO Problem loading steps description file", ex);
        }
        return builder.build();
    }

    public static StepIterator of(Step... steps) {
        return new StepIterator(Arrays.asList(steps));
    }

    public static StepIterator of(List<Step> steps) {
        return new StepIterator(steps);
    }

    private StepIterator(List<Step> states) {
        this.states.addAll(states);
    }

    void applyWith(Consumer<Step> consumer) {
        states.forEach(consumer);
    }

    public Step getCurrent() {
        return current;
    }

    public Step getNext() {
        int getIndex = stateIndex;
        if (getIndex == states.size()) {
            getIndex = 0;
        }
        return states.get(getIndex);
    }

    @Override
    public Step next() {
        if (stateIndex == states.size()) {
            //loop
            stateIndex = 0;
        }
        current = states.get(stateIndex++);
        return current;
    }
}<commit_msg>Step iterator class elements reordering (#352)<commit_after>/*
 * The MIT License
 *
 * Copyright 2014-2017 TweetWallFX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.tweetwallfx.controls.stepengine;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import javax.json.bind.JsonbBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author <NAME>
 */
public class StepIterator implements Iterator<Step> {

    private static final Logger LOGGER = LogManager.getLogger(StepIterator.class);
    private Step current = null;
    private int stepIndex = 0;
    private final List<Step> steps = new ArrayList<>();

    private StepIterator(final List<Step> steps) {
        this.steps.addAll(steps);
    }

    public static StepIterator of(final Step... steps) {
        return new StepIterator(Arrays.asList(steps));
    }

    public static StepIterator of(final List<Step> steps) {
        return new StepIterator(steps);
    }

    public static StepIterator ofDefaultConfiguration() {
        StepIterator.Builder builder = new StepIterator.Builder();
        try (InputStream s = Thread.currentThread().getContextClassLoader().getResourceAsStream("steps.json")) {
            StepEngineConfiguration stepEngineConfig = JsonbBuilder.create().fromJson(s, StepEngineConfiguration.class);
            stepEngineConfig.steps.forEach(className -> builder.addStep(className));
        } catch (IOException ex) {
            LOGGER.error("IO Problem loading steps description file", ex);
        }
        return builder.build();
    }

    @Override
    public boolean hasNext() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    void applyWith(final Consumer<Step> consumer) {
        steps.forEach(consumer);
    }

    public Step getCurrent() {
        return current;
    }

    public Step getNext() {
        int getIndex = stepIndex;
        if (getIndex == steps.size()) {
            getIndex = 0;
        }
        return steps.get(getIndex);
    }

    @Override
    public Step next() {
        if (stepIndex == steps.size()) {
            //loop
            stepIndex = 0;
        }
        current = steps.get(stepIndex++);
        return current;
    }

    private static class Builder {

        private final List<Step> steps = new ArrayList<>();

        public Builder addStep(final String classname) {
            try {
                Object newInstance = Thread.currentThread().getContextClassLoader().loadClass(classname).getDeclaredConstructor().newInstance();
                if (newInstance instanceof Step) {
                    steps.add((Step) newInstance);
                } else {
                    LOGGER.error("Class cannot be cast to Step " + classname + ". Skipping adding the step.");
                }
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException ex) {
                LOGGER.error("Failure instatiating step for " + classname, ex);
            }
            return this;
        }

        public StepIterator build() {
            return new StepIterator(steps);
        }
    }
}
{'fraction_non_alphanumeric': 0.08758228271784001, 'fraction_numerical': 0.0032355238201495036, 'mean_word_length': 2.888937093275488, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662722', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2187, 'n_words': 774}