/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection;

import java.util.List;
import net.ranides.assira.collection.lists.IntList;

/**
 * An object that can swap elements whose position is specified by integers
 */
public interface Swapper {

    /**
     * Swaps the data at the given positions.
     *
     * @param a the first position to swap.
     * @param b the second position to swap.
     */
    void swap(int a, int b);
     
    static <K> Swapper swapper(List<K> list) {
        return (a,b) -> {
            K t = list.get(a);
            list.set(a, list.get(b));
            list.set(b, t);
        };
    }
    
    static Swapper swapper(IntList list) {
        return (a,b) -> {
            int t = list.getInt(a);
            list.set(a, list.getInt(b));
            list.set(b, t);
        };
    }
    
}
