All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cilib.util.selection.arrangement.RingBasedArrangement Maven / Gradle / Ivy

/**           __  __
 *    _____ _/ /_/ /_    Computational Intelligence Library (CIlib)
 *   / ___/ / / / __ \   (c) CIRG @ UP
 *  / /__/ / / / /_/ /   http://cilib.net
 *  \___/_/_/_/_.___/
 */
package net.sourceforge.cilib.util.selection.arrangement;

import com.google.common.collect.Lists;
import java.util.List;

/**
 *
 */
public class RingBasedArrangement implements Arrangement {

    private T marker;

    public RingBasedArrangement(T marker) {
        this.marker = marker;
    }

    @Override
    public Iterable arrange(Iterable elements) {
        List tmp = Lists.newArrayList(elements);
        List result = Lists.newArrayListWithCapacity(tmp.size());

        int position = 0;
        for (T entry : elements) {
            if (this.marker.equals(entry)) {
                break;
            }
            position++;
        }

        for (int i = 0; i < tmp.size(); ++i) {
            result.add(tmp.get((position + 1 + i) % tmp.size()));
        }

        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy