Example usage for java.util Vector elementAt

List of usage examples for java.util Vector elementAt

Introduction

In this page you can find the example usage for java.util Vector elementAt.

Prototype

public synchronized E elementAt(int index) 

Source Link

Document

Returns the component at the specified index.

Usage

From source file:Main.java

/**
 * J2ME implementation of String.split(). Is very fragile.
 * // ww w.ja  v a 2 s.c  o  m
 * @param string
 * @param separator
 * @return
 */
public static String[] stringSplit(String string, char separator) {
    Vector parts = new Vector();
    int start = 0;
    for (int i = 0; i <= string.length(); i++) {
        if ((i == string.length()) || (string.charAt(i) == separator)) {
            if (start == i) {
                // no data between separators
                parts.addElement("");
            } else {
                // data between separators
                String part = string.substring(start, i);
                parts.addElement(part);
            }
            // start of next part is the char after this separator
            start = i + 1;
        }
    }
    // return as array
    String[] partsArray = new String[parts.size()];
    for (int i = 0; i < partsArray.length; i++) {
        partsArray[i] = (String) parts.elementAt(i);
    }
    return partsArray;
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Returns a list of all Species  //from w  w w  .j  a v  a 2 s .com
 * Used for submission and search screens
 * 
 * @return speciesNames
 * @throws Exception
 */
private static List getQueryOnlySpeciesList(HttpServletRequest inRequest, String inAddBlank) throws Exception {
    log.debug("Entering NewDropdownUtil.getQueryOnlySpeciesList");

    Species sp = new Species();

    Vector species = sp.retrieveAllWhere("species_name IS NOT NULL ORDER BY species_name");

    // Get values for dropdown lists for Species
    List<DropdownOption> theReturnList = new ArrayList<DropdownOption>();
    for (int j = 0; j < species.size(); j++) {
        Species speciesTab = (Species) species.elementAt(j);
        if (speciesTab.getSpecies_id() != null) {
            DropdownOption theOption = new DropdownOption(speciesTab.getSpecies_name(),
                    speciesTab.getSpecies_id().toString());
            theReturnList.add(theOption);
        }
    }
    log.debug("Exiting getQueryOnlySpeciesList.size " + theReturnList.size());
    return theReturnList;
}

From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java

/**
 * Checks if the XML-RPC response is an GreenPepper server Exception.
 * If so an GreenPepperServerException will be thrown with the error id found.
 * </p>//from   w  w w. ja  v  a 2  s. c  om
 *
 * @param xmlRpcResponse a {@link java.lang.Object} object.
 * @throws com.greenpepper.server.GreenPepperServerException if any.
 */
public static void checkForErrors(Object xmlRpcResponse) throws GreenPepperServerException {
    if (xmlRpcResponse instanceof Vector) {
        Vector temp = (Vector) xmlRpcResponse;
        if (!temp.isEmpty()) {
            checkErrors(temp.elementAt(0));
        }
    } else if (xmlRpcResponse instanceof Hashtable) {
        Hashtable table = (Hashtable) xmlRpcResponse;
        if (!table.isEmpty()) {
            checkForErrors(table.get(GreenPepperServerErrorKey.ERROR));
        }
    } else {
        checkErrors(xmlRpcResponse);
    }
}

From source file:Main.java

/**
 * Resolve a link relative to an absolute base.  The path to resolve could
 * itself be absolute or relative.//w  ww .java 2s.  c  om
 * 
 * e.g.
 * resolvePath("http://www.server.com/some/dir", "../img.jpg");
 *  returns http://www.server.com/some/img.jpg
 * 
 * @param base The absolute base path
 * @param link The link given relative to the base
 * @return 
 */
public static String resolveLink(String base, String link) {
    String linkLower = link.toLowerCase();
    int charFoundIndex;

    charFoundIndex = linkLower.indexOf("://");
    if (charFoundIndex != -1) {
        boolean isAllChars = true;
        char cc;
        for (int i = 0; i < charFoundIndex; i++) {
            cc = linkLower.charAt(i);
            isAllChars &= ((cc > 'a' && cc < 'z') || (cc > '0' && cc < '9') || cc == '+' || cc == '.'
                    || cc == '-');
        }

        //we found :// and all valid scheme name characters before; path itself is absolute
        if (isAllChars) {
            return link;
        }
    }

    //Check if this is actually a data: link which should not be resolved
    if (link.startsWith("data:")) {
        return link;
    }

    if (link.length() > 2 && link.charAt(0) == '/' && link.charAt(1) == '/') {
        //we want the protocol only from the base
        String resolvedURL = base.substring(0, base.indexOf(':') + 1) + link;
        return resolvedURL;
    }

    if (link.length() > 1 && link.charAt(0) == '/') {
        //we should start from the end of the server
        int serverStartPos = base.indexOf("://") + 3;
        int serverFinishPos = base.indexOf('/', serverStartPos + 1);
        return base.substring(0, serverFinishPos) + link;
    }

    //get rid of query if it's present in the base path
    charFoundIndex = base.indexOf('?');
    if (charFoundIndex != -1) {
        base = base.substring(0, charFoundIndex);
    }

    //remove the filename component if present in base path
    //if the base path ends with a /, remove that, because it will be joined to the path using a /
    charFoundIndex = base.lastIndexOf(FILE_SEP);
    base = base.substring(0, charFoundIndex);

    String[] baseParts = splitString(base, FILE_SEP);
    String[] linkParts = splitString(link, FILE_SEP);

    Vector resultVector = new Vector();
    for (int i = 0; i < baseParts.length; i++) {
        resultVector.addElement(baseParts[i]);
    }

    for (int i = 0; i < linkParts.length; i++) {
        if (linkParts[i].equals(".")) {
            continue;
        }

        if (linkParts[i].equals("..")) {
            resultVector.removeElementAt(resultVector.size() - 1);
        } else {
            resultVector.addElement(linkParts[i]);
        }
    }

    StringBuffer resultSB = new StringBuffer();
    int numElements = resultVector.size();
    for (int i = 0; i < numElements; i++) {
        resultSB.append(resultVector.elementAt(i));
        if (i < numElements - 1) {
            resultSB.append(FILE_SEP);
        }
    }

    return resultSB.toString();
}

From source file:Mopex.java

/**
 * Returns a Method array of the methods to which instances of the specified
 * respond except for those methods defined in the class specifed by limit
 * or any of its superclasses. Note that limit is usually used to eliminate
 * them methods defined by java.lang.Object.
 * //from   w  w  w.  ja v  a  2s  .  c o  m
 * @return Method[]
 * @param cls
 *            java.lang.Class
 * @param limit
 *            java.lang.Class
 */
//start extract getSupportedMethods
public static Method[] getSupportedMethods(Class cls, Class limit) {
    Vector supportedMethods = new Vector();
    for (Class c = cls; c != limit; c = c.getSuperclass()) {
        Method[] methods = c.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            boolean found = false;
            for (int j = 0; j < supportedMethods.size(); j++)
                if (equalSignatures(methods[i], (Method) supportedMethods.elementAt(j))) {
                    found = true;
                    break;
                }
            if (!found)
                supportedMethods.add(methods[i]);
        }
    }
    Method[] mArray = new Method[supportedMethods.size()];
    for (int k = 0; k < mArray.length; k++)
        mArray[k] = (Method) supportedMethods.elementAt(k);
    return mArray;
}

From source file:Sort.java

/**
 * This is a generic version of C.A.R Hoare's Quick Sort algorithm. This
 * will handle vectors that are already sorted, and vectors with duplicate
 * keys.//  w ww.  j av  a 2  s.  com
 * <p>
 * If you think of a one dimensional vector as going from the lowest index
 * on the left to the highest index on the right then the parameters to this
 * function are lowest index or left and highest index or right.
 * 
 * @param v
 *            A <code>Vector</code> of <code>Ordered</code> items.
 * @param lo0
 *            Left boundary of vector partition.
 * @param hi0
 *            Right boundary of vector partition.
 * @exception ClassCastException
 *                If the vector contains objects that are not
 *                <code>Ordered</code>.
 */
public static void QuickSort(Vector v, int lo0, int hi0) throws ClassCastException {
    int lo = lo0;
    int hi = hi0;
    Ordered mid;

    if (hi0 > lo0) { // arbitrarily establish partition element as the
                     // midpoint of the vector
        mid = (Ordered) v.elementAt((lo0 + hi0) / 2);

        // loop through the vector until indices cross
        while (lo <= hi) {
            // find the first element that is greater than or equal to
            // the partition element starting from the left index
            while ((lo < hi0) && (0 > ((Ordered) v.elementAt(lo)).compare(mid)))
                ++lo;

            // find an element that is smaller than or equal to
            // the partition element starting from the right index
            while ((hi > lo0) && (0 < ((Ordered) v.elementAt(hi)).compare(mid)))
                --hi;

            // if the indexes have not crossed, swap
            if (lo <= hi)
                swap(v, lo++, hi--);
        }

        // if the right index has not reached the left side of array
        // must now sort the left partition
        if (lo0 < hi)
            QuickSort(v, lo0, hi);

        // if the left index has not reached the right side of array
        // must now sort the right partition
        if (lo < hi0)
            QuickSort(v, lo, hi0);
    }
}

From source file:org.apache.tomcat.util.IntrospectionUtils.java

/**
 * Return a URL[] that can be used to construct a class loader
 *///from   w w w.  ja va  2s .co m
public static URL[] getClassPath(Vector v) {
    URL[] urls = new URL[v.size()];
    for (int i = 0; i < v.size(); i++) {
        urls[i] = (URL) v.elementAt(i);
    }
    return urls;
}

From source file:Sort.java

/**
 * Binary search for an object//from   w w w.j av a2 s  .co m
 * 
 * @param vector
 *            The vector of <code>Ordered</code> objects.
 * @param ref
 *            The name to search for.
 * @param lo
 *            The lower index within which to look.
 * @param hi
 *            The upper index within which to look.
 * @return The index at which reference was found or is to be inserted.
 */
public static int bsearch(Vector vector, Ordered ref, int lo, int hi) {
    int num;
    int mid;
    int half;
    int result;
    int ret;

    ret = -1;

    num = (hi - lo) + 1;
    while ((-1 == ret) && (lo <= hi)) {
        half = num / 2;
        mid = lo + ((0 != (num & 1)) ? half : half - 1);
        result = ref.compare(vector.elementAt(mid));
        if (0 == result)
            ret = mid;
        else if (0 > result) {
            hi = mid - 1;
            num = ((0 != (num & 1)) ? half : half - 1);
        } else {
            lo = mid + 1;
            num = half;
        }
    }
    if (-1 == ret)
        ret = lo;

    return (ret);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java

/**
 * Given a list of locale pairs, remove them from the list of all locale
 * pairs. Then create a hashtable where the key is the source locale, and
 * the value is all possible target locales.
 * //  w  ww .j a  v a  2s.co m
 */
public static Hashtable getRemainingLocales(List currentLocales) throws EnvoyServletException {
    Hashtable remaining = new Hashtable();
    Vector sourceLocales = UserHandlerHelper.getAllSourceLocales();
    for (int i = 0; i < sourceLocales.size(); i++) {
        GlobalSightLocale curLocale = (GlobalSightLocale) sourceLocales.elementAt(i);
        Vector validTargets = UserHandlerHelper.getTargetLocales(curLocale);
        remaining.put(curLocale, validTargets);
    }

    // Now that we have a hashtable of all valid source locales and
    // their target locales, removes the ones that already exist for
    // this vendor.
    for (int i = 0; i < currentLocales.size(); i++) {
        LocalePair pair = (LocalePair) currentLocales.get(i);
        GlobalSightLocale target = pair.getTarget();
        Vector targets = (Vector) remaining.get(pair.getSource());
        if (targets != null && targets.contains(target)) {
            targets.remove(target);
            if (targets.size() == 0) {
                // no valid targets left so remove the entry in the hash
                remaining.remove(pair.getSource());
            }
        }
    }

    return remaining;
}

From source file:Main.java

public SortedComboBoxModel(Vector items) {
    Collections.sort(items);//from ww  w . jav a  2s  . c o  m
    int size = items.size();
    for (int i = 0; i < size; i++) {
        super.addElement(items.elementAt(i));
    }
    setSelectedItem(items.elementAt(0));
}