Example usage for java.util Vector remove

List of usage examples for java.util Vector remove

Introduction

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

Prototype

public synchronized E remove(int index) 

Source Link

Document

Removes the element at the specified position in this Vector.

Usage

From source file:com.brienwheeler.lib.jmx.logging.Log4jMBeanExporter.java

@SuppressWarnings("unchecked")
private synchronized void shutdown() {
    shutdown = true;//from   w  ww .ja  v  a 2  s  .  c o m
    killDelayedThread();

    MBeanServer server = JmxUtils.locateMBeanServer();
    HierarchyDynamicMBean hdm = hierarchyDynamicMBean.get();
    for (ObjectName registeredName : registeredNames) {
        try {
            server.unregisterMBean(registeredName);

            // The AbstractDynamicMBean base class of the HierarchyDynamicMBean tracks these names too
            // and will later try to unregister them and throw warning log messages unless we violate its
            // privacy and clean out its internal bookkeeping
            Field fld = ReflectionUtils.findField(hdm.getClass(), "mbeanList", Vector.class);
            fld.setAccessible(true);
            Vector<ObjectName> mbeanList = (Vector<ObjectName>) ReflectionUtils.getField(fld, hdm);
            mbeanList.remove(registeredName);
        } catch (Exception e) {
            log.error("Error unregistering " + registeredName.getCanonicalName(), e);
        }
    }
    registeredNames.clear();

    if (registeredHierarchy) {
        try {
            ObjectName mbo = new ObjectName(LOG4J_HIERARCHY_DEFAULT);
            server.unregisterMBean(mbo);
        } catch (Exception e) {
            log.error("Error unregistering Log4j MBean Hierarchy", e);
        }
        registeredHierarchy = false;
    }
}

From source file:com.vsquaresystem.safedeals.marketprice.MarketPriceService.java

public boolean saveExcelToDatabase() throws IOException {

    Vector dataHolder = read();
    marketPriceDAL.truncateAll();/*  w w  w  . ja va2s. c o  m*/
    dataHolder.remove(0);
    System.out.println("data line 147" + dataHolder);
    MarketPrice marketPrice = new MarketPrice();
    String id = "";
    String cityId = "";
    String locationId = "";
    String year = "";
    String month = "";
    String mpAgriLandLowest = "";
    String mpAgriLandHighest = "";
    String mpPlotLowest = "";
    String mpPlotHighest = "";
    String mpResidentialLowest = "";
    String mpResidentialHighest = "";
    String mpCommercialLowest = "";
    String mpCommercialHighest = "";
    String sdZoneId = "";
    String locationTypeId = "";
    String locationCategories = "";
    String description = "";
    String majorApproachRoad = "";
    String sourceOfWater = "";
    String publicTransport = "";
    String advantage = "";
    String disadvantage = "";
    String population = "";
    String migrationRate = "";
    String isCommercialCenter = "";

    DataFormatter formatter = new DataFormatter();
    for (Iterator iterator = dataHolder.iterator(); iterator.hasNext();) {

        List list = (List) iterator.next();

        System.out.println("list for save" + list);
        cityId = list.get(1).toString();
        locationId = list.get(2).toString();
        year = list.get(3).toString();
        month = list.get(4).toString();
        mpAgriLandLowest = list.get(5).toString();
        mpAgriLandHighest = list.get(6).toString();
        mpPlotLowest = list.get(7).toString();
        mpPlotHighest = list.get(8).toString();
        mpResidentialLowest = list.get(9).toString();
        mpResidentialHighest = list.get(10).toString();
        mpCommercialLowest = list.get(11).toString();
        mpCommercialHighest = list.get(12).toString();

        List<Integer> numberList = new ArrayList<Integer>();

        try {

            marketPrice.setCityId(Integer.parseInt(cityId));
            marketPrice.setLocationId(Integer.parseInt(locationId));
            marketPrice.setYear(Integer.parseInt(year));
            marketPrice.setMonth(Integer.parseInt(month));
            marketPrice.setMpAgriLandLowest(Double.parseDouble(mpAgriLandLowest));
            marketPrice.setMpAgriLandHighest(Double.parseDouble(mpAgriLandHighest));

            marketPrice.setMpPlotLowest(Double.parseDouble(mpPlotLowest));
            marketPrice.setMpPlotHighest(Double.parseDouble(mpPlotHighest));

            marketPrice.setMpResidentialLowest(Double.parseDouble(mpResidentialLowest));
            marketPrice.setMpResidentialHighest(Double.parseDouble(mpResidentialHighest));

            marketPrice.setMpCommercialLowest(Double.parseDouble(mpCommercialLowest));
            marketPrice.setMpCommercialHighest(Double.parseDouble(mpCommercialHighest));

            marketPriceDAL.insert(marketPrice);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    File excelFile = attachmentUtils.getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.MARKET_PRICE);
    FileUtils.cleanDirectory(excelFile);
    return true;

}

From source file:tvbrowser.core.search.booleansearch.BooleanSearcher.java

private static IMatcher getMatcher(Vector<Object> part, boolean caseSensitive,
        Hashtable<String, Object> matcherTable) throws ParserException {
    boolean lastWasMatch = false;
    for (int i = 0; i < part.size(); i++) {
        Object o = part.get(i);// w  w  w.  ja v a2  s .  c om
        if (o instanceof String) {
            String s = (String) o;
            if (!isKeyWord(s)) {
                if (lastWasMatch) {
                    Object Otemp = part.get(i - 1);
                    if (Otemp instanceof StringMatcher) {
                        StringMatcherRegEx ME = new StringMatcherRegEx(((StringMatcher) Otemp).toString(), s,
                                caseSensitive, matcherTable);
                        part.set(i - 1, ME);
                    } else {
                        StringMatcherRegEx ME = (StringMatcherRegEx) Otemp;
                        ME.addPart(s);
                    }
                    part.remove(i);
                    i--;
                    continue;
                }
                StringMatcher m = new StringMatcher(s, caseSensitive, matcherTable);
                part.set(i, m);
                lastWasMatch = true;
                continue;
            }
        }
        if (o instanceof Vector) {
            if (lastWasMatch) {
                part.insertElementAt("AND", i);
                i = 0;
                continue;
            }
        }
        lastWasMatch = false;
    }

    for (int i = 0; i < part.size(); i++) {
        Object O = part.get(i);
        if (O instanceof Vector) {
            @SuppressWarnings("unchecked")
            Vector<Object> v = (Vector<Object>) O;
            part.set(i, getMatcher(v, caseSensitive, matcherTable));
        }
    }

    boolean found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && (O.toString().equals("NOT"))) {
                if (i + 1 >= part.size()) {
                    throw new ParserException(
                            mLocalizer.msg("unexpectedEndOfInput", "Unexpected end of input"));
                }
                Object O2 = expect(part, i + 1, IMatcher.class, mLocalizer.msg("expression", "expression"));
                NotMatcher n = new NotMatcher((IMatcher) O2);
                part.remove(i);
                part.remove(i);

                /*
                 * If the previous Element is not "AND" insert an "AND"-Element
                 */
                if ((i > 0) && !(part.get(i - 1) instanceof AndMatcher)
                        && !((part.get(i - 1) instanceof String) && ((String) part.get(i - 1)).equals("AND"))) {
                    part.insertElementAt("AND", i);
                    i++;
                }
                part.insertElementAt(n, i);
                found = true;
                break;
            }
        }
    }

    found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && ((O.toString().equals("AND")) || ((O.toString().equals("&&"))))) {

                if (i <= 0) {
                    throw new ParserException(
                            mLocalizer.msg("missingExprBeforeAND", "Missing expression before 'AND'"));
                }
                if (i + 1 >= part.size()) {
                    throw new ParserException(
                            mLocalizer.msg("unexpectedEndOfInput", "Unexpected end of input"));
                }
                IMatcher O2 = (IMatcher) expect(part, i - 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                IMatcher O1 = (IMatcher) expect(part, i + 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                AndMatcher a = new AndMatcher(O1, O2);
                part.remove(i - 1);
                part.remove(i - 1);
                part.remove(i - 1);
                part.insertElementAt(a, i - 1);
                found = true;
                break;
            }
        }
    }

    found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && ((O.toString().equals("OR")) || (O.toString().equals("||")))) {
                if (i <= 0) {
                    throw new ParserException("Missing expression before \"OR\"");
                }
                if (i + 1 >= part.size()) {
                    throw new ParserException("Unexpected end of input");
                }
                IMatcher O2 = (IMatcher) expect(part, i - 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                IMatcher O1 = (IMatcher) expect(part, i + 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                OrMatcher a = new OrMatcher(O1, O2);
                part.remove(i - 1);
                part.remove(i - 1);
                part.remove(i - 1);
                part.insertElementAt(a, i - 1);
                found = true;
                break;
            }
        }
    }
    return (IMatcher) part.get(0);
}

From source file:org.kchine.rpf.db.ServantProxyPoolSingletonDB.java

public static GenericObjectPool getInstance(String poolName, String driver, final String url, final String user,
        final String password) {
    String key = driver + "%" + poolName + "%" + url + "%" + user + "%" + password;
    if (_pool.get(key) != null)
        return _pool.get(key);
    synchronized (lock) {
        if (_pool.get(key) == null) {
            Connection conn = null;
            try {
                Class.forName(driver);
                final Vector<Object> borrowedObjects = new Vector<Object>();
                DBLayerInterface dbLayer = DBLayer.getLayer(getDBType(url), new ConnectionProvider() {
                    public Connection newConnection() throws SQLException {
                        return DriverManager.getConnection(url, user, password);
                    }/*ww w.  ja  v a 2 s.c om*/
                });
                final GenericObjectPool p = new GenericObjectPool(
                        new ServantProxyFactoryDB(poolName, dbLayer)) {
                    @Override
                    public synchronized Object borrowObject() throws Exception {
                        if (_shuttingDown)
                            throw new NoSuchElementException();
                        Object result = super.borrowObject();
                        borrowedObjects.add(result);
                        return result;
                    }

                    @Override
                    public synchronized void returnObject(Object obj) throws Exception {
                        super.returnObject(obj);
                        borrowedObjects.remove(obj);
                    }
                };

                if (System.getProperty("pools.dbmode.shutdownhook.enabled") != null
                        && System.getProperty("pools.dbmode.shutdownhook.enabled").equalsIgnoreCase("false")) {

                } else {
                    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                        public void run() {
                            synchronized (p) {

                                final Vector<Object> bo = (Vector<Object>) borrowedObjects.clone();

                                _shuttingDown = true;
                                try {
                                    for (int i = 0; i < bo.size(); ++i)
                                        p.returnObject(bo.elementAt(i));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }));
                }

                _pool.put(key, p);
                p.setMaxIdle(0);
                p.setTestOnBorrow(true);
                p.setTestOnReturn(true);
            } catch (Exception e) {
                throw new RuntimeException(getStackTraceAsString(e));
            }

        }
        return _pool.get(key);
    }
}

From source file:org.globus.ftp.test.MlsxTest.java

public void test5() throws Exception {
    logger.info("test two consective mlsd, using both mlsd functions, using GridFTPClient");

    GridFTPClient src = new GridFTPClient(TestEnv.serverAHost, TestEnv.serverAPort);
    src.setAuthorization(TestEnv.getAuthorization(TestEnv.serverASubject));
    src.authenticate(null); // use default creds

    String output1 = null;//  w w w.  ja va  2  s. co m
    String output2 = null;

    // using mlsd()

    Vector v = src.mlsd(TestEnv.serverADir);
    logger.debug("mlsd received");
    StringBuffer output1Buffer = new StringBuffer();
    while (!v.isEmpty()) {
        MlsxEntry f = (MlsxEntry) v.remove(0);
        output1Buffer.append(f.toString()).append("\n");

    }
    output1 = output1Buffer.toString();
    logger.debug(output1);

    // using mlsd 2nd time

    HostPort hp2 = src.setPassive();
    src.setLocalActive();

    src.changeDir(TestEnv.serverADir);
    v = src.mlsd();
    logger.debug("mlsd received");
    StringBuffer output2Buffer = new StringBuffer();
    while (!v.isEmpty()) {
        MlsxEntry f = (MlsxEntry) v.remove(0);
        output2Buffer.append(f.toString()).append("\n");

    }
    output2 = output2Buffer.toString();
    logger.debug(output2);

    src.close();
}

From source file:org.kchine.r.server.graphics.GDContainerBag.java

synchronized public Vector<GDObject> popAllGraphicObjects(int maxNbrGraphicPrimitives) {
    // System.out.println("popAllGraphicObjects");
    if (_actions.size() == 0)
        return null;
    Vector<GDObject> result = (Vector<GDObject>) _actions.clone();
    if (maxNbrGraphicPrimitives != -1 && result.size() > maxNbrGraphicPrimitives) {
        int delta = result.size() - maxNbrGraphicPrimitives;
        for (int i = 0; i < delta; ++i) {
            result.remove(result.size() - 1);
        }//from w  w w  .j  a va2  s  . c o m
    }
    for (int i = 0; i < result.size(); ++i)
        _actions.remove(0);
    return result;
}

From source file:org.kepler.sms.SemanticTypeManager.java

/**
 * Remove a concept id from the given object.
 * /*from  w w w .java2  s.  c  o m*/
 * @param obj
 *            the object to remove the concept from
 * @param concept
 *            the concept to remove
 */
public void removeType(Object obj, String concept) {
    if (!isObject(obj) || concept == null)
        return;
    Vector<Object> types = getTypes(obj);
    if (types.contains(concept))
        types.remove(concept);
}

From source file:com.adito.jdbc.JDBCConnectionImpl.java

synchronized PreparedStatement aquirePreparedStatement(String key, String sqlString) throws SQLException {
    Vector avail = (Vector) preparedStatements.get(key);
    if (avail == null) {
        avail = new Vector();
        preparedStatements.put(key, avail);
    }/*  w  ww  .j  a  v  a2 s . c o  m*/

    if (avail.size() > 0) {
        return (PreparedStatement) avail.remove(0);
    } else
        return conn.prepareStatement(sqlString);
}

From source file:com.bt.aloha.sipstone.GenGraph.java

public Map<String, List<Double>> readFile(String fileName) {
    File f = new File(fileName);
    HashMap<String, List<Double>> ret = new HashMap<String, List<Double>>();
    try {/*w  ww.  j  a v  a  2s  .c  o m*/
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line;
        List<String> headers = null;
        Vector<String> lines = new Vector<String>();
        while (null != (line = br.readLine())) {
            lines.add(line);
        }
        // last two lines are not needed
        lines.remove(1);
        lines.remove(1);
        lines.remove(lines.size() - 1);
        for (int row = 0; row < lines.size(); row++) {
            line = lines.get(row);
            System.out.println(line);
            if (row == 0) {
                headers = populateMapWithHeaders(ret, line);
            } else {
                populateMapWithData(ret, line, headers);
            }
        }
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException("Unable to open " + fileName);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to read " + fileName);
    }
    return ret;
}

From source file:org.kepler.ssh.LocalDelete.java

public boolean deleteFiles(String mask, boolean recursive) throws ExecException {

    if (mask == null)
        return true;
    if (mask.trim() == "")
        return true;

    // pre-test to conform to 'rm -rf': if the mask ends for . or ..
    // it must throw an error
    String name = new File(mask).getName();
    if (name.equals(".") || name.equals("..")) {
        throw new ExecException("Directories like . or ..  are not allowed to be removed: " + mask);
    }//from ww  w.  j av  a  2 s. c  o m

    // split the mask into a vector of single masks
    // e.g. a/b*d/c?? into (a, b*d, c??)
    Vector splittedMask = splitMask(mask);
    // sure it has at least one element: .
    String path = (String) splittedMask.firstElement();
    splittedMask.remove(0);

    return delete(new File(path), splittedMask, recursive);
}