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

/**
 * Method sortVectorRecursive.//from   ww w.j av  a  2 s.c  o m
 * @param vector Vector
 * @param getter String
 * @param low double
 * @param high double
 * @param sortDirection int
 * @param caseSensitiveSort boolean
 * @throws Exception
 */
private static void sortVectorRecursive(Vector vector, String getter, double low, double high,
        int sortDirection, boolean caseSensitiveSort) throws Exception {
    Class[] cls = new Class[0];
    Object[] objs = new Object[0];
    Object middleVectorElem = vector.elementAt((int) ((low + high) / 2));
    Method method = null;
    Object middleObject = null;

    if (middleVectorElem != null) {
        method = middleVectorElem.getClass().getMethod(getter, cls);
        middleObject = method.invoke(middleVectorElem, objs);
    }

    Object tmpElement;
    Object compareVectorElem;
    Object compareObject;
    int i = (int) high;
    int j = (int) low;

    Class[] objectClass = new Class[1];
    objectClass[0] = Class.forName("java.lang.Object");
    Class[] stringObjectClass = new Class[1];
    stringObjectClass[0] = Class.forName("java.lang.String");

    Object[] object = new Object[1];
    object[0] = middleObject;
    Object compResult;
    boolean repeatDo;

    do {
        do {
            compareVectorElem = vector.elementAt(j);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!caseSensitiveSort && compareObject instanceof String && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }
                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }

            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() < 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() > 0))) {
                j++;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        do {
            compareVectorElem = vector.elementAt(i);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!(caseSensitiveSort) && compareObject instanceof String
                            && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }

                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }
            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() > 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() < 0))) {
                i--;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        if (i >= j) {
            if (i != j) {
                tmpElement = vector.elementAt(i);

                vector.set(i, vector.elementAt(j));
                vector.set(j, tmpElement);
            }

            i--;
            j++;
        }
    } while (j <= i);

    if (low < i) {
        sortVectorRecursive(vector, getter, low, (double) i, sortDirection, caseSensitiveSort);
    }

    if (j < high) {
        sortVectorRecursive(vector, getter, (double) j, high, sortDirection, caseSensitiveSort);
    }
}

From source file:Main.java

/**
 * Method sortVectorRecursive./* w w  w.  j av  a2 s  .  c o  m*/
 * @param vector Vector
 * @param getter String
 * @param low double
 * @param high double
 * @param sortDirection int
 * @param caseSensitiveSort boolean
 * @throws Exception
 */
private static void sortVectorRecursive(Vector vector, String getter, double low, double high,
        int sortDirection, boolean caseSensitiveSort) throws Exception {
    Class[] cls = new Class[0];
    Object[] objs = new Object[0];
    Object middleVectorElem = vector.elementAt((int) ((low + high) / 2));
    Method method = null;
    Object middleObject = null;

    if (middleVectorElem != null) {
        method = middleVectorElem.getClass().getMethod(getter, cls);
        middleObject = method.invoke(middleVectorElem, objs);
    }

    Object tmpElement;
    Object compareVectorElem;
    Object compareObject;
    int i = (int) high;
    int j = (int) low;

    Class[] objectClass = new Class[1];
    objectClass[0] = Class.forName("java.lang.Object");
    Class[] stringObjectClass = new Class[1];
    stringObjectClass[0] = Class.forName("java.lang.String");

    Object[] object = new Object[1];
    object[0] = middleObject;
    Object compResult;
    boolean repeatDo;

    do {
        do {
            compareVectorElem = vector.elementAt(j);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!(caseSensitiveSort) && compareObject instanceof String
                            && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }
                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }

            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() < 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() > 0))) {
                j++;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        do {
            compareVectorElem = vector.elementAt(i);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!(caseSensitiveSort) && compareObject instanceof String
                            && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }

                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }
            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() > 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() < 0))) {
                i--;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        if (i >= j) {
            if (i != j) {
                tmpElement = vector.elementAt(i);

                vector.set(i, vector.elementAt(j));
                vector.set(j, tmpElement);
            }

            i--;
            j++;
        }
    } while (j <= i);

    if (low < i) {
        sortVectorRecursive(vector, getter, low, i, sortDirection, caseSensitiveSort);
    }

    if (j < high) {
        sortVectorRecursive(vector, getter, j, high, sortDirection, caseSensitiveSort);
    }
}

From source file:com.sittinglittleduck.DirBuster.GenBaseCase.java

private static String getBaseCaseAgain(Manager manager, URL failurl, String failString) throws IOException {
    int failcode;
    String baseResponce = "";

    GetMethod httpget = new GetMethod(failurl.toString());
    // set the custom HTTP headers
    Vector HTTPheaders = manager.getHTTPHeaders();
    for (int a = 0; a < HTTPheaders.size(); a++) {
        HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a);
        /*//from w  w  w. j av  a  2 s  . c  o  m
         * Host header has to be set in a different way!
         */
        if (httpHeader.getHeader().startsWith("Host")) {
            httpget.getParams().setVirtualHost(httpHeader.getValue());
        } else {
            httpget.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue());
        }
    }
    httpget.setFollowRedirects(Config.followRedirects);

    // save the http responce code for the base case
    failcode = manager.getHttpclient().executeMethod(httpget);
    manager.workDone();

    // we now need to get the content as we need a base case!
    if (failcode == 200) {
        if (Config.debug) {
            System.out.println("DEBUG GenBaseCase: base case for " + failurl.toString() + "came back as 200!");
        }

        BufferedReader input = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream()));
        String tempLine;
        StringBuffer buf = new StringBuffer();
        while ((tempLine = input.readLine()) != null) {
            buf.append("\r\n" + tempLine);
        }
        baseResponce = buf.toString();
        input.close();

        // HTMLparse.parseHTML();

        // HTMLparse htmlParse = new HTMLparse(baseResponce, null);
        // Thread parse  = new Thread(htmlParse);
        // parse.start();

        // clean up the base case, based on the basecase URL
        baseResponce = FilterResponce.CleanResponce(baseResponce, failurl, failString);

        httpget.releaseConnection();

        /*
         * return the cleaned responce
         */
        return baseResponce;
    } else {
        /*
         * we have a big problem here as the server has returned an other responce code, for the same request
         * TODO: think of a way to deal with this!
         */
        return null;
    }
}

From source file:com.sittinglittleduck.DirBuster.GenBaseCase.java

public static BaseCase genURLFuzzBaseCase(Manager manager, String fuzzStart, String FuzzEnd)
        throws MalformedURLException, IOException {
    BaseCase baseCase = null;/*  w  w w .jav  a2 s.c o  m*/
    int failcode = 0;
    String failString = Config.failCaseString;
    String baseResponce = "";

    /*
     * markers for using regex instead
     */
    boolean useRegexInstead = false;
    String regex = null;

    URL failurl = new URL(fuzzStart + failString + FuzzEnd);

    GetMethod httpget = new GetMethod(failurl.toString());
    // set the custom HTTP headers
    Vector HTTPheaders = manager.getHTTPHeaders();
    for (int a = 0; a < HTTPheaders.size(); a++) {
        HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a);
        /*
         * Host header has to be set in a different way!
         */
        if (httpHeader.getHeader().startsWith("Host")) {
            httpget.getParams().setVirtualHost(httpHeader.getValue());
        } else {
            httpget.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue());
        }
    }
    httpget.setFollowRedirects(Config.followRedirects);

    // save the http responce code for the base case
    failcode = manager.getHttpclient().executeMethod(httpget);
    manager.workDone();

    if (failcode == 200) {
        if (Config.debug) {
            System.out.println("DEBUG GenBaseCase: base case for " + failurl.toString() + "came back as 200!");
        }

        BufferedReader input = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream()));
        String tempLine;
        StringBuffer buf = new StringBuffer();
        while ((tempLine = input.readLine()) != null) {
            buf.append("\r\n" + tempLine);
        }
        baseResponce = buf.toString();
        input.close();

        // clean up the base case, based on the basecase URL
        baseResponce = FilterResponce.CleanResponce(baseResponce, failurl, failString);

        if (Config.debug) {
            System.out.println("DEBUG GenBaseCase: base case was set to :" + baseResponce);
        }
    }

    httpget.releaseConnection();

    /*
     * create the base case object
     */
    baseCase = new BaseCase(null, failcode, false, failurl, baseResponce, null, useRegexInstead, regex);

    return baseCase;
}

From source file:Main.java

public static String[] getElementPath(Node node) {
    Vector vector = new Vector();
    for (; node != null; node = node.getParentNode())
        if (node.getNodeType() == 1)
            if (!hasSameNamedSibling(node))
                vector.addElement(node.getNodeName());
            else/* w  w w .ja v  a2s .c  o m*/
                vector.addElement(node.getNodeName() + "[" + (getElementIndex(node) + 1) + "]");

    int i = vector.size();
    String as[] = new String[i];
    int j = i - 1;
    for (int k = 0; k < i;) {
        as[k] = (String) vector.elementAt(j);
        k++;
        j--;
    }

    return as;
}

From source file:Main.java

/**
 *
 * @param vtData Vector/*  w ww  . ja v  a2 s.  c  o m*/
 * @param iComboIndex int
 * @param iVectorIndex int
 * @param cbo JComboBox
 * @param vt Vector
 * @param bClear boolean
 * @param bHaveNull boolean
 * @throws Exception
 */
public static void fillValue(Vector vtData, int iComboIndex, int iVectorIndex, JComboBox cbo, Vector vt,
        boolean bClear, boolean bHaveNull) throws Exception {
    // Clear
    if (bClear) {
        vt.clear();
        cbo.removeAllItems();
    }

    // Add null value
    if (bHaveNull) {
        vt.addElement("");
        cbo.addItem("");
    }

    // Fill value
    for (int iRowIndex = 0; iRowIndex < vtData.size(); iRowIndex++) {
        Vector vtResultRow = (Vector) vtData.elementAt(iRowIndex);
        vt.addElement(vtResultRow.elementAt(iVectorIndex));
        cbo.addItem(vtResultRow.elementAt(iComboIndex));
    }
}

From source file:Main.java

/**
 * Method getTokenSeparatedStrings./*from  w  w w .j  av a  2s.  c  o m*/
 * @param vector Vector
 * @param getter String
 * @param tokenizer String
 * @param tokenDelimiter String
 * @return String
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws Exception
 */
public static String getTokenSeparatedStrings(Vector vector, String getter, String tokenizer,
        String tokenDelimiter) throws NoSuchMethodException, IllegalAccessException, Exception {
    StringBuffer tokenSeparatedStrings = new StringBuffer("");
    String stringValue = null;
    Class[] clsParms = new Class[0];
    Object[] objParms = new Object[0];
    Object property;
    Method getterMethod = null;

    Object vectorElement = null;

    for (int i = 0; i < vector.size(); i++) {
        vectorElement = vector.elementAt(i);
        getterMethod = vectorElement.getClass().getMethod(getter, clsParms);
        property = getterMethod.invoke(vectorElement, objParms);

        if (property != null) {
            stringValue = property.toString();
        } else {
            stringValue = "";
        }

        tokenSeparatedStrings.append(tokenDelimiter + stringValue + tokenDelimiter);

        if (i < vector.size() - 1) {
            tokenSeparatedStrings.append(tokenizer);
        }
    }

    return tokenSeparatedStrings.toString();
}

From source file:Main.java

/**
 * Method getTokenSeparatedStrings./*w ww . j a v  a2s .  c  o  m*/
 * @param vector Vector
 * @param getter String
 * @param tokenizer String
 * @param tokenDelimiter String
 * @return String
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static String getTokenSeparatedStrings(Vector vector, String getter, String tokenizer,
        String tokenDelimiter) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    StringBuffer tokenSeparatedStrings = new StringBuffer("");
    String stringValue = null;
    Class[] clsParms = new Class[0];
    Object[] objParms = new Object[0];
    Object property;
    Method getterMethod = null;

    Object vectorElement = null;

    for (int i = 0; i < vector.size(); i++) {
        vectorElement = vector.elementAt(i);
        getterMethod = vectorElement.getClass().getMethod(getter, clsParms);
        property = getterMethod.invoke(vectorElement, objParms);

        if (property != null) {
            stringValue = property.toString();
        } else {
            stringValue = "";
        }

        tokenSeparatedStrings.append(tokenDelimiter + stringValue + tokenDelimiter);

        if (i < vector.size() - 1) {
            tokenSeparatedStrings.append(tokenizer);
        }
    }

    return tokenSeparatedStrings.toString();
}

From source file:org.apache.cactus.internal.util.CookieUtil.java

/**
 * Transforms an array of Cactus cookies into an array of Commons-HttpClient
 * cookies, using information from the request and URL.
 * /*from   www  .  j av  a 2 s. c om*/
 * @param theRequest The request
 * @param theUrl The URL
 * @return The array of HttpClient cookies
 */
public static org.apache.commons.httpclient.Cookie[] createHttpClientCookies(WebRequest theRequest,
        URL theUrl) {
    Vector cactusCookies = theRequest.getCookies();

    // transform the Cactus cookies into HttpClient cookies
    org.apache.commons.httpclient.Cookie[] httpclientCookies = new org.apache.commons.httpclient.Cookie[cactusCookies
            .size()];

    for (int i = 0; i < cactusCookies.size(); i++) {
        Cookie cactusCookie = (Cookie) cactusCookies.elementAt(i);
        httpclientCookies[i] = CookieUtil.createHttpClientCookie(theRequest, theUrl, cactusCookie);
    }

    return httpclientCookies;
}

From source file:FileUtil.java

public static Vector removeDuplicateDomains(Vector s) {
    int i = 0;//from   ww  w . j  a v  a 2s  .co m
    int j = 0;
    boolean duplicates = false;
    String str1 = "";
    String str2 = "";

    Vector v = new Vector();

    for (i = 0; i < s.size(); i++) {
        duplicates = false;
        for (j = (i + 1); j < s.size(); j++) {
            str1 = "";
            str2 = "";
            str1 = s.elementAt(i).toString().trim();
            str2 = s.elementAt(j).toString().trim();
            if (str1.indexOf('@') > -1) {
                str1 = str1.substring(str1.indexOf('@'));
            }
            if (str2.indexOf('@') > -1) {
                str2 = str2.substring(str2.indexOf('@'));
            }

            if (str1.equalsIgnoreCase(str2)) {
                duplicates = true;
            }

        }
        if (duplicates == false) {
            v.addElement(s.elementAt(i).toString().trim());
        }

    }

    return v;
}