Example usage for java.util Vector contains

List of usage examples for java.util Vector contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this vector contains the specified element.

Usage

From source file:com.toughra.mlearnplayer.EXEStrMgr.java

/**
 * Initiate the locale management.  This will look for a preference
 * called 'locale'.  If this does not exist will refer to system property
 * microedition.locale (device locale) and trim to two letters.
 * /*from w  w w. ja  v a 2s .  c  o  m*/
 * If the device locale is available that will be set, otherwise will be
 * set to work in English (en)
 * 
 * @throws IOException 
 */
public void initLocale() throws IOException {
    host.localeRes = Resources.open("/localization.res");
    String localeToUse = getPref("locale");
    if (localeToUse == null) {
        //locale not yet set - see if we have the system locale
        String sysLocal = System.getProperty("microedition.locale");
        if (sysLocal == null) {
            sysLocal = "en";
        } else if (sysLocal.length() > 2) {
            sysLocal = sysLocal.substring(0, 2);
        }

        Vector localesAvail = getLocaleList(host.localeRes, localeResName);
        if (localesAvail.contains(sysLocal)) {
            localeToUse = sysLocal;
        } else {
            localeToUse = "en";
        }
        setPref("locale", localeToUse);
        savePrefs();
    }

    host.localeHt = host.localeRes.getL10N("localize", localeToUse);

    System.out.println("Loaded localization res for " + localeToUse);
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectClinicalRawFileListener.java

public boolean createTabFileFromSoft(File rawFile, File newFile) {
    Vector<String> columns = new Vector<String>();
    Vector<HashMap<String, String>> lines = new Vector<HashMap<String, String>>();
    try {/*from  ww w  . ja va  2  s. c  o  m*/
        BufferedReader br = new BufferedReader(new FileReader(rawFile));
        String line;
        Pattern p1 = Pattern.compile(".SAMPLE = .*");
        Pattern p2 = Pattern.compile("!Sample_characteristics_ch. = .*: .*");
        while ((line = br.readLine()) != null) {
            if (line.compareTo("") != 0) {
                Matcher m1 = p1.matcher(line);
                Matcher m2 = p2.matcher(line);
                if (m1.matches()) {
                    lines.add(new HashMap<String, String>());
                    if (!columns.contains("sample")) {
                        columns.add("sample");
                    }
                    lines.get(lines.size() - 1).put("sample", line.split(".SAMPLE = ", -1)[1]);
                } else if (m2.matches()) {
                    String s = line.split("!Sample_characteristics_ch. = ", -1)[1];
                    String tag = s.split(": ", -1)[0];
                    if (!columns.contains(tag)) {
                        columns.add(tag);
                    }
                    lines.get(lines.size() - 1).put(tag, s.split(": ", -1)[1]);
                }
            }
        }
        br.close();
    } catch (Exception e) {
        selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    if (columns.size() <= 1) {
        selectRawFilesUI.setMessage("Wrong soft format: no characteristics");
        selectRawFilesUI.setIsLoading(false);
        return false;
    }
    FileWriter fw;
    try {
        fw = new FileWriter(newFile);
        BufferedWriter out = new BufferedWriter(fw);

        for (int i = 0; i < columns.size() - 1; i++) {
            out.write(columns.get(i) + "\t");
        }
        out.write(columns.get(columns.size() - 1) + "\n");

        for (HashMap<String, String> sample : lines) {
            for (int i = 0; i < columns.size() - 1; i++) {
                String value = sample.get(columns.get(i));
                if (value == null)
                    value = "";
                out.write(value + "\t");
            }
            String value = sample.get(columns.get(columns.size() - 1));
            if (value == null)
                value = "";
            out.write(value + "\n");
        }
        out.close();
        return true;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage());
        selectRawFilesUI.setIsLoading(false);
        e.printStackTrace();
        return false;
    }
}

From source file:net.sf.l2j.gameserver.model.entity.L2JOneoRusEvents.CTF.java

public static boolean addPlayerOk(String teamName, L2PcInstance eventPlayer) {
    if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventCTF) {
        eventPlayer.sendMessage("You already participated in the event!");
        return false;
    }/*from   w w  w  .j  a  v a  2 s.c  om*/
    if (eventPlayer._inEventFOS || eventPlayer._inEventTvT || eventPlayer._inEventDM) {
        eventPlayer.sendMessage("You already participated in another event!");
        return false;
    }
    for (L2PcInstance player : _players) {
        if (player.getObjectId() == eventPlayer.getObjectId()) {
            eventPlayer.sendMessage("You already participated in the event!");
            return false;
        } else if (player.getName() == eventPlayer.getName()) {
            eventPlayer.sendMessage("You already participated in the event!");
            return false;
        }
    }
    if (_players.contains(eventPlayer)) {
        eventPlayer.sendMessage("You already participated in the event!");
        return false;
    }
    if (TvT._savePlayers.contains(eventPlayer.getName())) {
        eventPlayer.sendMessage("You already participated in another event!");
        return false;
    }
    if (Config.CTF_EVEN_TEAMS.equals("NO"))
        return true;
    else if (Config.CTF_EVEN_TEAMS.equals("BALANCE")) {
        boolean allTeamsEqual = true;
        int countBefore = -1;
        for (int playersCount : _teamPlayersCount) {
            if (countBefore == -1)
                countBefore = playersCount;
            if (countBefore != playersCount) {
                allTeamsEqual = false;
                break;
            }
            countBefore = playersCount;
        }
        if (allTeamsEqual)
            return true;
        countBefore = Integer.MAX_VALUE;
        for (int teamPlayerCount : _teamPlayersCount) {
            if (teamPlayerCount < countBefore)
                countBefore = teamPlayerCount;
        }
        Vector<String> joinableTeams = new Vector<String>();
        for (String team : _teams) {
            if (teamPlayersCount(team) == countBefore)
                joinableTeams.add(team);
        }
        if (joinableTeams.contains(teamName))
            return true;
    } else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
        return true;
    eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
    return false;
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.CashierMessageRenderController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView render(HttpServletRequest request) {
    // object to store keys from cashier and backboneforms
    Vector<String> keys = new Vector<String>();

    // locate and retrieve cashier messages
    Locale locale = RequestContextUtils.getLocale(request);
    ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", locale);

    // store cashier message keys in the vector object
    keys.addAll(resourceBundle.keySet());

    // retrieve backboneforms messages
    BackboneMessageRenderController backboneController = new BackboneMessageRenderController();
    ModelAndView modelAndView = backboneController.render(request);

    // store backboneforms message keys in the vector object
    for (Map.Entry<String, Object> messageKeys : modelAndView.getModel().entrySet()) {
        Enumeration<String> messageKey = (Enumeration<String>) messageKeys.getValue();
        while (messageKey.hasMoreElements()) {
            String key = messageKey.nextElement();
            if (!keys.contains(key))
                keys.add(key);/*from  ww w .  java2 s. c o  m*/
        }
    }

    return new ModelAndView(CashierWebConstants.MESSAGE_PAGE, "keys", keys.elements());
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetPlatformListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> values = this.ui.getValues();
    Vector<String> samples = this.ui.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File mappingFile = ((SnpData) this.dataType).getMappingFile();
    if (mappingFile == null) {
        this.ui.displayMessage("Error: no subject to sample mapping file");
    }//  w w  w  .j  a  v  a2s  .  c  om
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);

        try {
            BufferedReader br = new BufferedReader(new FileReader(mappingFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String platform;
                if (samples.contains(sample)) {
                    platform = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.ui.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (mappingFile != null) {
                String fileName = mappingFile.getName();
                mappingFile.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((SnpData) this.dataType).setMappingFile(fileDest);
        } catch (IOException ioe) {
            this.ui.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.ui.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.ui.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:org.ecoinformatics.seek.sms.AnnotationEngine.java

/**
 * helper function to find all class names
 * /*from   w w w . ja v a  2  s  .c  o  m*/
 *@param classname
 *            Description of the Parameter
 *@param approx
 *            Description of the Parameter
 *@return The matchingClassNames value
 */
private Vector<OntClass> getMatchingClassNames(String classname, boolean approx) {
    Vector<OntClass> initResult = new Vector<OntClass>();
    // get all classes in ontology
    Iterator iter = ontModelOntology().listClasses();
    while (iter.hasNext()) {
        // find classes that have a similar name
        OntClass cls = (OntClass) iter.next();
        if (approx && approxMatch(cls.getLocalName(), classname)) {
            initResult.add(cls);
        } else if (!approx && classname.equals(cls.getLocalName())) {
            initResult.add(cls);
        }
    }
    Vector<OntClass> result = (Vector) initResult.clone();
    iter = initResult.iterator();
    while (iter.hasNext()) {
        // find all subclasses of direct classes
        OntClass cls = (OntClass) iter.next();
        Iterator clsIter = cls.listSubClasses(false);
        // direct = false
        while (clsIter.hasNext()) {
            OntClass subCls = (OntClass) clsIter.next();
            if (!result.contains(subCls)) {
                result.add(subCls);
            }
        }
    }
    return result;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetTissueListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> values = this.ui.getValues();
    Vector<String> samples = this.ui.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File mappingFile = ((SnpData) this.dataType).getMappingFile();
    if (mappingFile == null) {
        this.ui.displayMessage("Error: no subject to sample mapping file");
    }//from  w w  w  .j  a v  a  2  s .c  o m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);

        try {
            BufferedReader br = new BufferedReader(new FileReader(mappingFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String tissueType;
                if (samples.contains(sample)) {
                    tissueType = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + fields[4]
                        + "\t" + tissueType + "\t" + fields[6] + "\t" + fields[7] + "\t" + "PLATFORM+TISSUETYPE"
                        + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.ui.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (mappingFile != null) {
                String fileName = mappingFile.getName();
                mappingFile.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((SnpData) this.dataType).setMappingFile(fileDest);
        } catch (IOException ioe) {
            this.ui.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.ui.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.ui.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:captureplugin.CapturePlugin.java

/**
 * This Function Iterates over all Devices and collects the list of Programs
 * to mark...//from   www.j av  a 2 s .c o m
 *
 * @return List with all Programs to mark
 */
private Vector<Program> getMarkedByDevices() {
    Vector<Program> v = new Vector<Program>();

    for (Object o : mConfig.getDevices()) {
        DeviceIf device = (DeviceIf) o;

        Program[] programs = device.getProgramList();

        if (programs != null) {
            for (Program program : programs) {
                if (!v.contains(program)) {
                    v.add(program);
                }
            }
        }
    }

    return v;
}

From source file:org.hyperimage.service.search.HIIndexer.java

public Vector<Long> simpleSearch(String text, HIProject project, String language) {
    Vector<Long> results = new Vector<Long>();

    HIHitCollector collector = new HIHitCollector();
    QueryParser parser = new QueryParser("all", new StandardAnalyzer());
    try {/*from  w  ww.  j av a2 s .  com*/

        prepDir(project);
        Query query = parser.parse("all." + language + ":\"" + text + "\"");
        IndexSearcher searcher = new IndexSearcher(getDir(project));
        searcher.search(query, collector);

        IndexReader reader = IndexReader.open(getDir(project));
        for (int doc : collector.getDocs()) {
            long baseID = Long.parseLong(reader.document(doc).get("id"));
            if (!results.contains(baseID))
                results.addElement(baseID);
        }
        searcher.close();
        reader.close();
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (CorruptIndexException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return results;
}

From source file:kenh.xscript.elements.Method.java

/**
 * Process method of {@code Method} element.
 * /* www. j  av a2s  . com*/
 * @param name
 * @param parameter
 * @throws UnsupportedScriptException
 */
@Processing
public void process(@Attribute(ATTRIBUTE_NAME) String name, @Primal @Attribute(ATTRIBUTE_PARA) String parameter)
        throws UnsupportedScriptException {
    this.name = name;

    if (StringUtils.isBlank(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty.");
        throw ex;
    }

    Map<String, Element> methods = this.getEnvironment().getMethods();
    if (methods.containsKey(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Reduplicate method. [" + name + "]");
        throw ex;
    }

    if (StringUtils.isNotBlank(parameter)) {
        String[] paras = StringUtils.split(parameter, ",");
        Vector<String[]> allParas = new Vector();
        Vector<String> existParas = new Vector(); // exist parameters
        for (String para : paras) {
            if (StringUtils.isBlank(para)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }

            String[] all = StringUtils.split(para, " ");
            String paraName = StringUtils.trimToEmpty(all[all.length - 1]);
            if (StringUtils.isBlank(paraName) || StringUtils.contains(paraName, "{")) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }
            if (existParas.contains(paraName)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Reduplicate parameter. [" + name + ", " + paraName + "]");
                throw ex;
            } else {
                existParas.add(paraName);
            }

            Vector<String> one = new Vector();
            one.add(paraName);
            for (int i = 0; i < all.length - 1; i++) {
                String s = StringUtils.trimToEmpty(all[i]);
                if (StringUtils.isBlank(s))
                    continue;
                if (s.equals(MODI_FINAL) || s.equals(MODI_REQUIRED)
                        || (s.startsWith(MODI_DEFAULT + "(") && s.endsWith(")"))) {
                    one.add(s);
                } else {
                    UnsupportedScriptException ex = new UnsupportedScriptException(this,
                            "Unsupported modifier. [" + name + ", " + paraName + ", " + s + "]");
                    throw ex;
                }
            }

            String[] one_ = one.toArray(new String[] {});
            allParas.add(one_);
        }

        parameters = allParas.toArray(new String[][] {});
    }

    // store into {methods}
    methods.put(name, this);
}