Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:edu.harvard.mcz.imagecapture.loader.FieldLoader.java

/**
 * Test the headers of a file for conformance with the expectations of loadFromMap
 * /* w  ww .  j a v a  2 s  .co  m*/
 * @param headers the headers to check against allowed fields in List<String> form.
 * @return a HeaderCheckResult object containing a result (true) and a message, the
 *    result is true if there are no unmatched fields in the load, currently exceptions
 *    are thrown instead of any false cases for result.
 *
 * @throws LoadException if no barcode field is found, if no data fields are found, or if
 *    one or more unknown (not mapped to DataShot specimen) fields are found. 
 *    
 * @see HeaderCheckResult.loadFromMap  
 */
public HeaderCheckResult checkHeaderList(List<String> headers) throws LoadException {
    HeaderCheckResult result = new HeaderCheckResult();

    ArrayList<String> knownFields = new ArrayList<String>();
    HashMap<String, String> knownFieldsLowerUpper = new HashMap<String, String>();
    Method[] specimenMethods = Specimen.class.getDeclaredMethods();
    for (int j = 0; j < specimenMethods.length; j++) {
        if (specimenMethods[j].getName().startsWith("set") && specimenMethods[j].getParameterTypes().length == 1
                && specimenMethods[j].getParameterTypes()[0].getName().equals(String.class.getName())) {
            String actualCase = specimenMethods[j].getName().replaceAll("^set", "");
            knownFields.add(specimenMethods[j].getName().replaceAll("^set", ""));
            knownFieldsLowerUpper.put(actualCase.toLowerCase(), actualCase);
            log.debug(actualCase);
        }
    }
    // List of input fields that will need to be parsed into relational tables
    ArrayList<String> toParseFields = new ArrayList<String>();
    toParseFields.add("collectors");
    toParseFields.add("numbers");

    Iterator<String> i = headers.iterator();
    boolean containsBarcode = false;
    boolean containsAField = false;
    boolean containsUnknownField = false;
    while (i.hasNext()) {
        String keyOrig = i.next();
        String key = keyOrig.toLowerCase();
        if (key.equals("barcode")) {
            containsBarcode = true;
            result.addToMessage(keyOrig);
        } else {
            if (key.startsWith("_")) {
                result.addToMessage("[" + keyOrig + "=Skipped]");
            } else {
                String actualCase = knownFieldsLowerUpper.get(key);
                if (toParseFields.contains(key) || (actualCase != null && knownFields.contains(actualCase)
                        && MetadataRetriever.isFieldExternallyUpdatable(Specimen.class, key))) {
                    result.addToMessage(keyOrig);
                    containsAField = true;
                } else {
                    result.addToMessage("[" + keyOrig + "=Unknown]");
                    containsUnknownField = true;
                }
            }
        }
    }

    if (!containsBarcode) {
        throw new LoadException("Header does not contain a barcode field.  \nFields:" + result.getMessage());
    }
    if (!containsAField) {
        throw new LoadException("Header contains no recognized data fields. \nFields: " + result.getMessage());
    }
    if (containsUnknownField) {
        throw new LoadException("Header contains at least one unknown field. \nFields: " + result.getMessage());
    }
    result.setResult(true);

    return result;
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java

private void doZStackGeneration(double[] z) {
    double startUm = z[0];
    double endUm = z[1];
    double stepUm = z[2];

    ArrayList<FOV> temp = tableModel_.getData();
    ArrayList<FOV> newtemp = new ArrayList<FOV>();
    ArrayList<FOV> unique = new ArrayList<FOV>();

    for (FOV fov : temp) {
        if (!unique.contains(fov)) {
            fov.setZ(0);// w w  w  .ja  va  2 s  .  c  o m
            unique.add(fov);
        }
    }

    int Nz = (int) ((endUm - startUm) / stepUm + 1);

    for (FOV fov : unique) {

        for (int zpos = 0; zpos < Nz; zpos++) {

            double zed = startUm + zpos * stepUm;

            newtemp.add(new FOV(fov.getX(), fov.getY(), fov.getZ() + zed, fov.getWell(), fov.getPlateProps()));
        }
    }

    tableModel_.addWholeData(newtemp);
}

From source file:com.box.androidlib.BoxSynchronous.java

/**
 * This method is used to get a tree representing all of the user's files and folders. Executes API action get_account_tree:
 * {@link <a href="http://developers.box.net/w/page/12923929/ApiFunction_get_account_tree"> http://developers.box.net/w/page/12923929/ApiFunction_get_account_tree</a>}
 * /*from ww  w .  j a v  a 2  s.  co  m*/
 * @param authToken
 *            The auth token retrieved through {@link BoxSynchronous#getAuthToken(String)}
 * @param folderId
 *            The ID of the root folder from which the tree begins. If this value is 0, the user's full account tree is returned.
 * @param params
 *            An array of strings. Possible values are {@link com.box.androidlib.Box#PARAM_ONELEVEL}, {@link com.box.androidlib.Box#PARAM_NOFILES},
 *            {@link com.box.androidlib.Box#PARAM_NOZIP}, {@link com.box.androidlib.Box#PARAM_SIMPLE}. Currently, {@link com.box.androidlib.Box#PARAM_NOZIP}
 *            is always included automatically.
 * @return the response parser used to capture the data of interest from the response. See the doc for the specific parser type returned to see what data is
 *         now available. All parsers implement getStatus() at a minimum.
 * @throws IOException
 *             Can be thrown if there is no connection, or if some other connection problem exists.
 */
public final AccountTreeResponseParser getAccountTree(final String authToken, final long folderId,
        final String[] params) throws IOException {

    // nozip should always be included
    final ArrayList<String> paramsList;
    if (params == null) {
        paramsList = new ArrayList<String>();
    } else {
        paramsList = new ArrayList<String>(Arrays.asList(params));
    }
    if (!paramsList.contains(Box.PARAM_NOZIP)) {
        paramsList.add(Box.PARAM_NOZIP);
    }

    final AccountTreeResponseParser parser = new AccountTreeResponseParser();
    final Uri.Builder builder = BoxUriBuilder.getBuilder(mApiKey, authToken, "get_account_tree");
    builder.appendQueryParameter("folder_id", String.valueOf(folderId));
    for (int i = 0; i < paramsList.size(); i++) {
        builder.appendQueryParameter("params[" + i + "]", paramsList.get(i));
    }
    saxRequest(parser, builder.build());
    return parser;
}

From source file:com.box.androidlib.BoxSynchronous.java

/**
 * Returns the contents of a user's Updates tab on box.net. Executes API action get_updates:
 * {@link <a href="http://developers.box.net/w/page/22926051/ApiFunction_get_updates">http://developers.box.net/w/page/22926051/ApiFunction_get_updates</a>}
 * /*from   ww  w .  j a v a  2  s  . c  o m*/
 * @param authToken
 *            The auth token retrieved through {@link BoxSynchronous#getAuthToken(String)}
 * @param beginTimeStamp
 *            a unix_timestamp of the earliest point in time to obtain an update (the time of the oldest update you want to display)
 * @param endTimeStamp
 *            a unix_timestamp of the latest point in time to obtain an update
 * @param params
 *            array of parameters. Currently, the only supported parameter is {@link com.box.androidlib.Box#PARAM_NOZIP}
 * @return the response parser used to capture the data of interest from the response. See the doc for the specific parser type returned to see what data is
 *         now available. All parsers implement getStatus() at a minimum.
 * @throws IOException
 *             Can be thrown if there is no connection, or if some other connection problem exists.
 */
public final UpdatesResponseParser getUpdates(final String authToken, final long beginTimeStamp,
        final long endTimeStamp, final String[] params) throws IOException {
    final UpdatesResponseParser parser = new UpdatesResponseParser();
    final Uri.Builder builder = BoxUriBuilder.getBuilder(mApiKey, authToken, "get_updates");
    builder.appendQueryParameter("begin_timestamp", String.valueOf(beginTimeStamp));
    builder.appendQueryParameter("end_timestamp", String.valueOf(endTimeStamp));

    // use_attributes should always be included
    final ArrayList<String> paramsList;
    if (params == null) {
        paramsList = new ArrayList<String>();
    } else {
        paramsList = new ArrayList<String>(Arrays.asList(params));
    }
    if (!paramsList.contains(Box.PARAM_USE_ATTRIBUTES)) {
        paramsList.add(Box.PARAM_USE_ATTRIBUTES);
    }
    for (int i = 0; i < paramsList.size(); i++) {
        builder.appendQueryParameter("params[" + i + "]", paramsList.get(i));
    }

    saxRequest(parser, builder.build());
    return parser;
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Checks to make sure that the given page has no duplciate dots
 *
 * @param pageNum the page number to check
 *///from  w  w  w  .  j a  v a  2s  .  c om
private boolean checkNoDuplicates(int pageNum) {
    ArrayList<String> names = new ArrayList<>();
    ArrayList<String> badNames = new ArrayList<>();
    PointConcurrentHashMap<Point, String> dots;
    try {
        dots = Main.getPages().get(pageNum).getDots();
    } catch (NullPointerException e) {
        if (pageNum == 0)
            JOptionPane.showMessageDialog(this,
                    "To data from the first page to the second page, navigate to the second page and click \"Play\".",
                    "Can't data the first page", JOptionPane.ERROR_MESSAGE);
        else
            JOptionPane.showMessageDialog(this, "Cannot find previous page", "Error",
                    JOptionPane.ERROR_MESSAGE);
        return false;
    }
    for (String s : dots.values()) {
        if (!names.contains(s))
            names.add(s);
        else
            badNames.add(s);
    }
    if (!badNames.isEmpty()) {
        String str = "The following players have more than one dot on Page " + pageNum + ":\n";
        for (String s : badNames)
            str += s + "\n";
        str += "\nTo data from the first page to the second page, navigate to the second page and click \"Play\".";
        JOptionPane.showMessageDialog(this, str.trim(), "Conflicts!", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}

From source file:net.antidot.semantic.rdf.rdb2rdf.dm.core.DirectMappingEngineWD20110324.java

private ArrayList<CandidateKey> extractPrimaryKeys(ResultSet primaryKeysSet, StdHeader header,
        String tableName) {/* www  .j a v a 2s  .  c o  m*/
    ArrayList<CandidateKey> primaryKeys = new ArrayList<CandidateKey>();
    // In particular : primary key

    ArrayList<String> columnNames = new ArrayList<String>();
    int size = 0;
    // Extract columns names
    try {
        while (primaryKeysSet.next()) {
            size++;
            String columnName = primaryKeysSet.getString("COLUMN_NAME");
            columnNames.add(columnName);
        }
    } catch (SQLException e) {
        log.error(
                "[DirectMappingEngineWD20110324:extractTupleFrom] SQL Error during primary key of tuples extraction");
        e.printStackTrace();
    }
    // Sort columns
    ArrayList<String> sortedColumnNames = new ArrayList<String>();
    for (String columnName : header.getColumnNames()) {
        if (columnNames.contains(columnName))
            sortedColumnNames.add(columnName);
    }
    // Create object
    if (size != 0) {
        CandidateKey primaryKey = new CandidateKey(sortedColumnNames, tableName, CandidateKey.KeyType.PRIMARY);
        primaryKeys.add(primaryKey);
    }
    if (primaryKeys.size() > 1)
        throw new IllegalStateException(
                "[DirectMappingEngine:extractPrimaryKeys] Table " + tableName + " has more primary keys.");
    return primaryKeys;
}

From source file:com.cisco.dvbu.ps.deploytool.services.RebindManagerImpl.java

/**
 * This procedure is used by both rebindFolder and rebindResources to check the existence of the rebind rules old and new paths.
 * The rules are as follows:/*from  ww  w.j  ava 2s  .  co m*/
 *   When the rebind rule list has 1 or more rules then it will use the "rebindResource" API because both the "from" and the "to" paths exist.
 *   When no paths match the "from" criteria or the "from" path does not exist then return null which will invoke the "Replace Text Path" methods.
 *   When the "to" path does not exist, the method will throw an exception since it is not permitted to rebind to a non-existent target folder
 *   
 * @param serverId
 * @param pathToServersXML
 * @param rebindRuleList
 * @return
 */
private RebindRuleList checkPathExists(String serverId, String pathToServersXML,
        RebindRuleList rebindRuleList) {

    // Initialize to true
    Boolean allRebindableResorucesExist = true;

    // Get the list of rebinable resources for a given resource path and type
    //RebindRuleList rebindRuleList = new RebindRuleList();
    List<RebindRule> rebindRules = rebindRuleList.getRebindRule();

    /* 
     * Loop through the rebinbable list and create a new list of non-duplicate paths.  
     * It is more efficient to check resource existence once per unique path.
     */
    ArrayList<PathType> oldPathList = new ArrayList<PathType>();
    ArrayList<PathType> newPathList = new ArrayList<PathType>();
    for (RebindRule rebindRule : rebindRules) {
        PathType pathType = new PathType();
        pathType.setPath(rebindRule.getOldPath());
        pathType.setType(rebindRule.getOldType().name());
        if (!oldPathList.contains(pathType)) {
            oldPathList.add(pathType);
        }

        pathType = new PathType();
        pathType.setPath(rebindRule.getNewPath());
        pathType.setType(rebindRule.getNewType().name());
        if (!newPathList.contains(pathType)) {
            newPathList.add(pathType);
        }
    }

    /* 
     * Check for existence of the unique set of old paths
     * Once it is determined that the path does not exist, there is no need to check any more paths.
     * This is the decision point on whether to invoke the "rebindResource" API that requires both from and to paths to exist,
     * or use the "Text Path Replacement" methodology where the specific CIS resource is called to update the resource based
     * on its sub-type.
     */
    for (int i = 0; i < oldPathList.size() && allRebindableResorucesExist; i++) {
        PathType pathType = oldPathList.get(i);
        if (!getResourceDAO().resourceExists(serverId, pathType.getPath(), pathType.getType(),
                pathToServersXML))
            allRebindableResorucesExist = false;
    }
    /* 
     * Check for existence of the unique set of "to" paths
     * Throw an exception if the "to" paths do not exist.
     * You can't execute a rebind if the target "to" path does not exist.
     */
    for (int i = 0; i < newPathList.size(); i++) {
        PathType pathType = newPathList.get(i);
        if (!getResourceDAO().resourceExists(serverId, pathType.getPath(), pathType.getType(),
                pathToServersXML))
            throw new ApplicationException("The rebind target path [" + pathType.getPath() + "] with type ["
                    + pathType.getType() + "] does not exist.");
    }

    // If all rebindable "from" paths and "to" paths exist then return the RebindRuleList otherwise return null;
    if (allRebindableResorucesExist && rebindRuleList != null && rebindRuleList.getRebindRule().size() > 0) {
        // When the list rebind rule list has 1 or more rules then it will use the "rebindResource" API because both the "from" and the "to" paths exist.
        return rebindRuleList; //
    } else {
        // When no paths match the "from" criteria or the "from" path does not exist then return null which will invoke the "Replace Text Path" methods.
        return null;
    }
}

From source file:com.krawler.spring.crm.accountModule.crmAccountDAOImpl.java

public KwlReturnObject getAccounts(HashMap<String, Object> requestParams) throws ServiceException {
    List ll = null;//w  ww.ja  v a  2 s .c  o  m
    int dl = 0;
    try {
        ArrayList filter_names = new ArrayList();
        ArrayList filter_params = new ArrayList();

        if (requestParams.containsKey("filter_names")) {
            filter_names = (ArrayList) requestParams.get("filter_names");
        }
        if (requestParams.containsKey("filter_params")) {
            filter_params = (ArrayList) requestParams.get("filter_params");
        }

        String Hql = "select distinct c from CrmAccount c ";
        if (filter_names.contains("INp.productId.productid")) {
            Hql += " inner join c.crmProducts as p ";
        }
        String filterQuery = StringUtil.filterQuery(filter_names, "where");
        int ind = filterQuery.indexOf("(");
        if (ind > -1) {
            int index = Integer.valueOf(filterQuery.substring(ind + 1, ind + 2));
            filterQuery = filterQuery.replaceAll("(" + index + ")", filter_params.get(index).toString());
            filter_params.remove(index);
        }
        Hql += filterQuery;

        ll = executeQuery(Hql, filter_params.toArray());
        dl = ll.size();
    } catch (Exception e) {
        throw ServiceException.FAILURE("crmAccountDAOImpl.getActiveAccount : " + e.getMessage(), e);
    }
    return new KwlReturnObject(true, "002", "", ll, dl);
}

From source file:edu.umich.ctools.sectionsUtilityTool.SectionsUtilityToolServlet.java

private boolean isCrosslistAllowed(HttpServletRequest request, HttpSession session, String url) {
    boolean isSectionMatch = false;

    //build api call
    String crosslistApiCall = canvasURL + url.substring(0, url.indexOf("/crosslist"));
    M_log.debug("crosslist API call: " + crosslistApiCall);

    String uniqname = null;/* www  .java  2s.  c o  m*/
    TcSessionData tc = (TcSessionData) request.getSession().getAttribute(TC_SESSION_DATA);
    if (tc != null) {
        uniqname = (String) tc.getCustomValuesMap().get(CUSTOM_CANVAS_USER_LOGIN_ID);
    }

    logApiCall(uniqname, url, request);
    HttpUriRequest clientRequest = null;

    clientRequest = new HttpGet(crosslistApiCall);

    HttpResponse canvasResponse = processApiCall(clientRequest);
    BufferedReader rd = null;
    try {
        rd = new BufferedReader(new InputStreamReader(canvasResponse.getEntity().getContent()));
    } catch (IOException e) {
        M_log.error("Canvas API call did not complete successfully", e);
    } catch (NullPointerException e) {
        M_log.error("Canvas API call did not complete successfully", e);
    }

    String line = "";
    StringBuilder sb = new StringBuilder();

    try {
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException e) {
        M_log.error("Canvas API call did not complete successfully", e);
    }
    M_log.debug("RESPONSE TO isCrosslistAllowed: " + sb.toString());

    String sisSectionId = null;
    try {
        JSONObject crosslistSectionResponse = new JSONObject(sb.toString());
        sisSectionId = crosslistSectionResponse.getString("sis_section_id");
    } catch (JSONException e) {
        M_log.error("JSONException found attempting to process sectionsCallResponse");
        return false;
    }
    M_log.debug("SIS SECTION ID: " + sisSectionId);

    M_log.debug("session id: " + session.getId());
    ArrayList<String> courses = (ArrayList<String>) session.getAttribute(M_PATH_DATA);
    if (M_log.isDebugEnabled()) {
        if (courses != null) {
            for (String section : courses) {
                M_log.debug("CrossSection: " + section);
            }
        }
    }

    if (courses.contains(sisSectionId)) {
        M_log.info("SECTION MATCH FOUND - CROSSLIST CALL ALLOWED");
        isSectionMatch = true;
    } else {
        M_log.info("API CALL REJECTED DUE TO CROSSLIST MISMATCH");
        isSectionMatch = false;
    }

    return isSectionMatch;
}

From source file:cn.future.ssh.service.impl.AccreditationServiceImpl.java

@Override
public Boolean valiDate(AccreditationBean accreditationBean) {

    ArrayList<String> allowType = new ArrayList<String>();
    for (Object key : properties.keySet()) {
        String value = (String) properties.get(key);
        String[] values = value.split(",");
        for (String v : values) {
            allowType.add(v);//from  w  w w. jav a2  s.  co m
        }
    }

    if (accreditationBean.getIdCard() != null) {
        String idCardFileName = accreditationBean.getIdCardFileName();
        if (!allowType.contains(accreditationBean.getIdCardContentType().toLowerCase()) || !properties.keySet()
                .contains(idCardFileName.substring(idCardFileName.lastIndexOf(".") + 1).toLowerCase())) {

            return false;
        }
    }
    if (accreditationBean.getUnitName() != null && !"".equals(accreditationBean.getUnitName().trim())) {
        if (accreditationBean.getBusinessLicense() != null) {
            String businessLicenseFileName = accreditationBean.getBusinessLicenseFileName();
            if (!allowType.contains(accreditationBean.getBusinessLicenseContentType().toLowerCase())
                    || !properties.keySet().contains(businessLicenseFileName
                            .substring(businessLicenseFileName.lastIndexOf(".") + 1).toLowerCase())) {

                return false;
            }
        }
    }
    if (accreditationBean.getEnforceCard() != null) {
        boolean enforceCardValidate = aboutTaskService.childValidate(allowType,
                accreditationBean.getEnforceCard(), accreditationBean.getEnforceCardFileName(),
                accreditationBean.getEnforceCardContentType());
        if (!enforceCardValidate) {
            return false;
        }
    }
    if (accreditationBean.getOrderChangeNotice() != null) {
        boolean orderChangeNoticeValidate = aboutTaskService.childValidate(allowType,
                accreditationBean.getOrderChangeNotice(), accreditationBean.getOrderChangeNoticeFileName(),
                accreditationBean.getOrderChangeNoticeContentType());
        if (!orderChangeNoticeValidate) {
            return false;
        }
    }
    if (accreditationBean.getRecordInquest() != null) {
        boolean recordInquestValidate = aboutTaskService.childValidate(allowType,
                accreditationBean.getRecordInquest(), accreditationBean.getRecordInquestFileName(),
                accreditationBean.getRecordInquestContentType());
        if (!recordInquestValidate) {
            return false;
        }
    }
    if (accreditationBean.getSitePhotos() != null) {
        boolean sitePhotosValidate = aboutTaskService.childValidate(allowType,
                accreditationBean.getSitePhotos(), accreditationBean.getSitePhotosFileName(),
                accreditationBean.getSitePhotosContentType());
        if (!sitePhotosValidate) {
            return false;
        }
    }
    if (accreditationBean.getRecordInv() != null) {
        boolean recordInvValidate = aboutTaskService.childValidate(allowType, accreditationBean.getRecordInv(),
                accreditationBean.getRecordInvFileName(), accreditationBean.getRecordInvContentType());
        if (!recordInvValidate) {
            return false;
        }
    }
    if (accreditationBean.getRecordPaper() != null) {
        boolean recordPaperValidate = aboutTaskService.childValidate(allowType,
                accreditationBean.getRecordPaper(), accreditationBean.getRecordPaperFileName(),
                accreditationBean.getRecordPaperContentType());
        if (!recordPaperValidate) {
            return false;
        }
    }

    return true;
}