package ca.janeg.cb;

import java.util.ArrayList;

/*
 *  Takes an array of objects and uses their string names to separate
 *  the elements by their access levels.
 *
 *  @author  Jane Griscti    jane@janeg.ca
 *  @created January 13, 2002
 */
class AccessSeparator {

    /*
     *  Checks the name of an object for one of the four access levels:
     *  public, protected, private or default and returns four ArrayLists
     *  with the objects separated accordingly.
     */
    static Object[] separate( final Object[] obj ) {
        ArrayList pub  = new ArrayList();
        ArrayList pro  = new ArrayList();
        ArrayList pri  = new ArrayList();
        ArrayList pkg  = new ArrayList();

        String name    = null;
        int index      = 0;
        for( int i = 0; i < obj.length; i++ ) {
            name = obj[i].toString();

            if( name.indexOf( "public" ) >= 0 ) {
                pub.add( obj[i] );
            } else if( name.indexOf( "protected" ) >= 0 ) {
                pro.add( obj[i] );
            } else if( name.indexOf( "private" ) >= 0 ) {
                pri.add( obj[i] );
            } else {
                pkg.add( obj[i] );
            }
        }

        return new Object[]{pub, pro, pri, pkg};
    }
}