Example usage for java.util Vector size

List of usage examples for java.util Vector size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of components in this vector.

Usage

From source file:eionet.gdem.utils.Utils.java

/**
 * Is Null or empty vector//from w ww .  j a va2 s  . c  o m
 * @param v Vector
 * @return True if Null or empty vector
 */
public static boolean isNullVector(Vector v) {
    if (v == null) {
        return true;
    } else if (v.size() == 0) {
        return true;
    }

    return false;
}

From source file:biblivre3.z3950.BiblivrePrefixString.java

@Override
public InternalModelRootNode toInternalQueryModel(ApplicationContext ctx) throws InvalidQueryException {
    if (StringUtils.isBlank(queryAttr) || StringUtils.isBlank(queryTerms)) {
        throw new InvalidQueryException("Null prefix string");
    }//  ww w  . j  a va 2s . c o  m
    try {
        if (internalModel == null) {
            internalModel = new InternalModelRootNode();
            InternalModelNamespaceNode node = new InternalModelNamespaceNode();
            node.setAttrset(DEFAULT_ATTRSET);
            internalModel.setChild(node);
            AttrPlusTermNode attrNode = new AttrPlusTermNode();
            final String attrValue = "1." + queryAttr;
            attrNode.setAttr(DEFAULT_ATTRTYPE, new AttrValue(null, attrValue));
            Vector terms = new Vector();
            StringTokenizer tokenizer = new StringTokenizer(queryTerms);
            while (tokenizer.hasMoreElements()) {
                terms.add(tokenizer.nextElement());
            }
            if (terms.size() > 1) {
                attrNode.setTerm(terms);
            } else if (terms.size() == 1) {
                attrNode.setTerm(terms.get(0));
            } else {
                throw new PrefixQueryException("No Terms");
            }
            node.setChild(attrNode);
        }
    } catch (Exception e) {
        throw new InvalidQueryException(e.getMessage());
    }
    return internalModel;
}

From source file:forseti.JSubirArchivo.java

@SuppressWarnings("rawtypes")
public int processFiles(Vector archivos) {
    int numFiles = 0, thisFile = 0;

    try {//from w  ww.  j av  a 2  s  . c  o m
        FileItem actual = null;

        for (int i = 0; i < archivos.size(); i++) {
            actual = (FileItem) archivos.elementAt(i);
            String fileName = actual.getName();
            // construimos un objeto file para recuperar el trayecto completo
            File file = new File(fileName);
            String ext = "." + getExt(thisFile).toLowerCase();
            boolean frz = isFrz(thisFile);
            //System.out.println("Archivo: " + fileName + " Ext esperada: " + ext);

            // Verifica que el archivo sea de la extension esperada
            if (file.getName().toLowerCase().indexOf(ext) != -1) {
                // nos quedamos solo con el nombre y descartamos el path
                file = new File(m_Path + file.getName());
                // escribimos el fichero colgando del nuevo path
                actual.write(file);
                MyUploadedFiles part = (MyUploadedFiles) m_Files.elementAt(thisFile);
                part.m_File = file.getName();

                numFiles += 1;
            } else if (frz) //Si era forzozo 
                m_Error += " " + JUtil.Msj("GLB", "GLB", "GLB", "ARCHIVO", 4) + " " + file.getName() + " - "
                        + ext;

            thisFile += 1;

        }

    } catch (Exception e) {
        if (e != null)
            m_Error += " " + JUtil.Msj("GLB", "GLB", "GLB", "ARCHIVO", 3) + " " + e.getMessage(); //"Error al subir archivos: " + e.getMessage();
    }

    return numFiles;
}

From source file:com.yahoo.messenger.data.json.GroupList.java

public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

        JSONObject o = a.getJSONObject(i);
        Group c = new Group();
        c.unserializeJSON(o.getJSONObject("group"));
        v.addElement(c);/* ww w.  ja v a  2  s  .  co m*/
    }

    groups = new Group[v.size()];
    v.copyInto(groups);

}

From source file:com.sittinglittleduck.DirBuster.workGenerators.BruteForceURLFuzz.java

public void run() {
    // checks if the server surports heads requests

    if (manager.getAuto()) {
        try {/*from  w w w . ja  v a2s.  co  m*/
            URL headurl = new URL(firstPart);

            HeadMethod httphead = new HeadMethod(headurl.toString());

            // set the custom HTTP headers
            Vector HTTPheaders = manager.getHTTPHeaders();
            for (int a = 0; a < HTTPheaders.size(); a++) {
                HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a);
                httphead.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue());
            }
            int responceCode = httpclient.executeMethod(httphead);

            // if the responce code is method not implemented or fails
            if (responceCode == 501 || responceCode == 400) {
                // switch the mode to just GET requests
                manager.setAuto(false);
            }
        } catch (MalformedURLException e) {
            // TODO deal with error
        } catch (IOException e) {
            // TODO deal with error
        }
    }

    // deal with the dirs
    try {
        // get item from  queue
        DirToCheck tempDirToCheck = dirQueue.take();
        // get dir name
        currentDir = tempDirToCheck.getName();
        // get any extention that need to be checked
        extToCheck = tempDirToCheck.getExts();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    System.out.println("Starting fuzz on " + firstPart + urlFuzzStart + "{dir}" + urlFuzzEnd);
    started = currentDir;

    String baseCase = null;
    // store for the basecase object set to null;
    BaseCase baseCaseObj = null;

    try {
        // get fail responce code for a dir test

        baseCaseObj = GenBaseCase.genURLFuzzBaseCase(manager, firstPart + urlFuzzStart, urlFuzzEnd);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // baseCaseObj = new BaseCase(null, failcode, true, failurl, baseCase);
    // call function to generate the brute force

    makeList(minLen, maxLen, baseCase, baseCaseObj);

    manager.youAreFinished();
}

From source file:edu.ku.brc.specify.conversion.TableDataChecker.java

/**
 * @param tableName/*from   ww  w.  j av  a2s. c  om*/
 * @param skipNames
 * @return
 */
public List<Pair<String, String>> getColumnNamesWithData(final String tableName,
        final HashSet<String> skipNames) {
    List<Pair<String, String>> fieldsWithData = new Vector<Pair<String, String>>();

    int numRows = BasicSQLUtils.getNumRecords(connection, tableName);
    if (numRows > 0) {
        try {
            Vector<Object[]> rows = BasicSQLUtils.query(connection, String.format(
                    "SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS "
                            + "WHERE table_name = '%s' AND table_schema = '%s'",
                    tableName, connection.getCatalog()));

            for (Object[] cols : rows) {
                String fieldName = cols[0].toString();

                if ((skipNames == null || !skipNames.contains(fieldName.toLowerCase()))) {
                    if (cols[2].equals("YES")) {
                        String sql = String.format("SELECT COUNT(*) FROM `%s` WHERE `%s` IS NOT NULL",
                                tableName, fieldName);
                        int cnt = BasicSQLUtils.getCountAsInt(connection, sql);
                        if (cnt > 0) {
                            sql = String.format(
                                    "SELECT DISTINCT c.caption, fst.TextForValue from usysmetacontrol c INNER JOIN usysmetaobject o on o.objectid = c.objectid "
                                            + "INNER JOIN usysmetafieldset fs on fs.fieldsetid = o.fieldsetid LEFT JOIN usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                                            + "WHERE fs.fieldsetname = '%s' and o.objectname = '%s' and (fst.TextForValue is null or (fst.TextForValue not in('TissueOrExtract', 'KaryoSlide', 'HistoSlideSeries', 'Image', 'Sound', 'SoundRecording', 'ImagePrint', 'Spectrogram', 'Container')))",
                                    tableName, fieldName);

                            Pair<String, String> namePair = new Pair<String, String>();
                            Vector<Object[]> captions = BasicSQLUtils.query(connection, sql);
                            if (captions.size() > 0) {
                                namePair.second = (String) captions.get(0)[0];
                            }
                            namePair.first = fieldName;
                            fieldsWithData.add(namePair);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return fieldsWithData;
}

From source file:com.yahoo.messenger.data.json.ContactList.java

public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

        JSONObject o = a.getJSONObject(i);
        Contact c = new Contact();
        c.unserializeJSON(o.getJSONObject("contact"));
        v.addElement(c);//from   w ww  .  ja  v a 2s.  co  m
    }

    contacts = new Contact[v.size()];
    v.copyInto(contacts);

}

From source file:com.concursive.connect.web.modules.common.social.images.jobs.ImageResizerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    LOG.debug("Starting...");
    SchedulerContext schedulerContext = null;
    Connection db = null;//from  w ww.  ja  va2s  .  c o  m

    // Initial setup
    try {
        schedulerContext = context.getScheduler().getContext();
    } catch (Exception e) {
        LOG.error("ImageResizerJob Exception due to scheduler", e);
        throw new JobExecutionException(e);
    }

    // Process the arrays
    Vector exportList = (Vector) schedulerContext.get(IMAGE_RESIZER_ARRAY);

    while (exportList.size() > 0) {

        // Holds the transactions to be threaded
        List<TransactionTask> renderTasks = new ArrayList<TransactionTask>();

        // Pre-process the files using a database connection
        try {
            db = SchedulerUtils.getConnection(schedulerContext);
            // The imageResizerBean contains the image handle to be processed
            ImageResizerBean bean = (ImageResizerBean) exportList.remove(0);

            LOG.debug("Preparing thumbnails for FileItem (" + bean.getFileItemId() + ")... " + bean.getWidth()
                    + "x" + bean.getHeight());
            // Load the fileItem
            FileItem fileItem = new FileItem(db, bean.getFileItemId());
            if (bean.getWidth() > 0 || bean.getHeight() > 0) {
                // A specific size needs to be rendered
                renderTasks.add(new TransactionTask(bean, fileItem, bean.getWidth(), bean.getHeight(), false));
            } else {
                // No specific size so for each fileItem, generate several sizes of the image
                renderTasks.add(new TransactionTask(bean, fileItem, 640, 480, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 210, 150, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 200, 200, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 133, 133, true));
                renderTasks.add(new TransactionTask(bean, fileItem, 100, 100, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 75, 75, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 50, 50, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 45, 45, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 30, 30, false));
            }
        } catch (Exception e) {
            LOG.error("ImageResizerJob Exception", e);
            continue;
        } finally {
            SchedulerUtils.freeConnection(schedulerContext, db);
        }

        int threads = 2;
        // Process the files
        ExecutorService executor = null;
        List<Future<Thumbnail>> futures = null;
        try {
            executor = Executors.newFixedThreadPool(threads);
            // NOTE: this wrapper fix is for Java 1.5
            final Collection<Callable<Thumbnail>> wrapper = Collections
                    .<Callable<Thumbnail>>unmodifiableCollection(renderTasks);
            LOG.debug("Generating thumbnails... " + renderTasks.size());
            futures = executor.invokeAll(wrapper);
        } catch (InterruptedException e) {
            LOG.error("ImageResizerJob executor exception", e);
            if (executor != null) {
                executor.shutdown();
            }
            throw new JobExecutionException(e);
        }

        // Insert the thumbnails using the database connection
        try {
            db = SchedulerUtils.getConnection(schedulerContext);
            LOG.debug("Inserting thumbnails into database... " + futures.size());
            // Process the executor results
            for (Future<Thumbnail> f : futures) {
                Thumbnail thumbnail = f.get();
                thumbnail.insert(db);
            }
        } catch (Exception e) {
            LOG.error("ImageResizerJob insert thumbnails into database exception", e);
            throw new JobExecutionException(e);
        } finally {
            SchedulerUtils.freeConnection(schedulerContext, db);
            if (executor != null) {
                executor.shutdown();
            }
        }
    }
}

From source file:com.yahoo.messenger.data.notification.json.BuddyInfoContactList.java

public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

        JSONObject o = a.getJSONObject(i);

        BuddyInfoContact c = new BuddyInfoContact();
        c.unserializeJSON(o);/*from ww w.ja va 2 s.  c  o  m*/
        v.addElement(c);

    }

    buddyInfoContacts = new BuddyInfoContact[v.size()];
    v.copyInto(buddyInfoContacts);

}

From source file:com.globalsight.everest.webapp.pagehandler.administration.config.fileextension.FileExtensionMainHandler.java

private String checkDependencies(FileExtensionImpl fileExtension, HttpSession session) {
    ResourceBundle bundle = PageHandler.getBundle(session);
    FileExtensionDependencyChecker depChecker = new FileExtensionDependencyChecker();

    Hashtable catDeps = depChecker.categorizeDependencies(fileExtension);

    StringBuffer deps = new StringBuffer();
    if (catDeps.size() == 0) {
        return null;
    }/*  w w  w.j a va  2 s. c om*/

    deps.append("<span class=\"errorMsg\">");
    Object[] args = { bundle.getString("lb_file_extension") };
    deps.append(MessageFormat.format(bundle.getString("msg_dependency"), args));

    for (Enumeration e = catDeps.keys(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        deps.append("<p>*** " + bundle.getString(key) + " ***<br>");
        Vector values = (Vector) catDeps.get(key);
        for (int i = 0; i < values.size(); i++) {
            deps.append((String) values.get(i));
            deps.append("<br>");
        }
    }
    deps.append("</span>");
    return deps.toString();
}