Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:org.jfree.chart.demo.SampleXYSymbolicDataset.java

/**
 * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
 * order that they share the same Y symbolic value list.
 * <P>//from www  . ja  va  2s.c o  m
 * The sharing Y symbolic value list is obtained adding the Y symbolic data list of the fist data set to the Y symbolic data list of the second data set.
 * <P>
 * This function is use with the <I>combined plot</I> functions of JFreeChart.
 * 
 * @param dataset1
 *           the first data set to combine.
 * @param dataset2
 *           the second data set to combine.
 * @return the shared Y symbolic array.
 */
public static String[] combineYSymbolicDataset(final YisSymbolic dataset1, final YisSymbolic dataset2) {

    final SampleXYSymbolicDataset sDataset1 = (SampleXYSymbolicDataset) dataset1;
    final SampleXYSymbolicDataset sDataset2 = (SampleXYSymbolicDataset) dataset2;
    final String[] sDatasetSymbolicValues1 = sDataset1.getYSymbolicValues();
    final String[] sDatasetSymbolicValues2 = sDataset2.getYSymbolicValues();

    // Combine the two list of symbolic value of the two data set
    final int s1length = sDatasetSymbolicValues1.length;
    final int s2length = sDatasetSymbolicValues2.length;
    final List ySymbolicValuesCombined = new Vector();
    for (int i = 0; i < s1length; i++) {
        ySymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
    }
    for (int i = 0; i < s2length; i++) {
        if (!ySymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
            ySymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
        }
    }

    // Change the Integer reference of the second data set
    int newIndex;
    for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
        for (int j = 0; j < sDataset2.getItemCount(i); j++) {
            newIndex = ySymbolicValuesCombined.indexOf(sDataset2.getYSymbolicValue(i, j));
            sDataset2.setYValue(i, j, new Integer(newIndex));
        }
    }

    // Set the new list of symbolic value on the two data sets
    final String[] ySymbolicValuesCombinedA = new String[ySymbolicValuesCombined.size()];
    ySymbolicValuesCombined.toArray(ySymbolicValuesCombinedA);
    sDataset1.setYSymbolicValues(ySymbolicValuesCombinedA);
    sDataset2.setYSymbolicValues(ySymbolicValuesCombinedA);

    return ySymbolicValuesCombinedA;
}

From source file:com.fiveamsolutions.nci.commons.util.HibernateHelper.java

/**
 * @param entity the entity to validate//from www  .java 2  s  .  co m
 * @return a map of validation messages keyed by the property path. The keys represent the field/property validation
 *         errors however, when key is null it means the validation is a type/class validation error
 */
public static Map<String, String[]> validate(PersistentObject entity) {
    Map<String, List<String>> messageMap = new HashMap<String, List<String>>();
    ClassValidator<PersistentObject> classValidator = getClassValidator(entity);
    InvalidValue[] validationMessages = classValidator.getInvalidValues(entity);
    for (InvalidValue validationMessage : validationMessages) {
        String path = StringUtils.defaultString(validationMessage.getPropertyPath());
        List<String> m = messageMap.get(path);
        if (m == null) {
            m = new ArrayList<String>();
            messageMap.put(path, m);
        }
        String msg = validationMessage.getMessage();
        msg = msg.replace("(fieldName)", "").trim();
        if (!m.contains(msg)) {
            m.add(msg);
        }
    }

    return convertMapListToMapArray(messageMap);
}

From source file:massbank.extend.ChemicalFormulaUtils.java

/**
 * m/zlXgvq//w w  w .j  a  v a  2 s .c o  m
 */
public static String[] getMatchedFormulas(String[] mzs, double peakTolerance, List<String[]> massList)
        throws IOException {
    List<String> formulaList = new ArrayList();
    for (String mz : mzs) {
        double dblMz = Double.parseDouble(mz);
        double min = dblMz - peakTolerance;
        double max = dblMz + peakTolerance;
        for (String[] items : massList) {
            String formula = items[0];
            String mass = items[1];
            double dblMass = Double.parseDouble(mass);
            if (min <= dblMass && dblMass <= max) {
                if (!formulaList.contains(formula)) {
                    formulaList.add(formula);
                }
            } else if (max < dblMass) {
                break;
            }
        }
    }
    return formulaList.toArray(new String[] {});
}

From source file:de.xirp.plugin.PluginLoader.java

/**
 * Checks if the given plugin needs other plugins to run.
 * /*from  w w  w.  ja  va2 s . c  om*/
 * @param plugin
 *            plugin to check
 * @param jarList
 *            list of jar files on the class path
 * @param loader
 *            the current class loader used to check if a class is
 *            available
 * @return <code>true</code> if all other Plugins needed by this
 *         Plugin are available
 * @see IPlugable#requiredLibs()
 */
@SuppressWarnings("unchecked")
private static boolean checkNeeds(IPlugable plugin, ClassLoader loader, List<String> jarList) {
    if (plugin == null) {
        return true;
    }

    List<String> req = plugin.requiredLibs();
    if (req == null) {
        return true;
    }
    boolean ret = true;
    for (String claas : req) {
        if (claas.endsWith(".jar")) { //$NON-NLS-1$
            if (!jarList.contains(claas)) {
                ret &= false;
                logClass.warn(I18n.getString("PluginLoader.log.removingPluginBecauseOfMissingLib", //$NON-NLS-1$
                        plugin.getName(), claas) + Constants.LINE_SEPARATOR);
            }
        } else if (!currentPluginList.contains(claas)) {
            boolean hasClass = true;
            try {
                loader.loadClass(claas);
            } catch (ClassNotFoundException e) {
                logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
                hasClass = false;
            }

            if (!hasClass) {
                logClass.warn(I18n.getString("PluginLoader.log.removingPluginBecauseOfMissingLib", //$NON-NLS-1$
                        plugin.getName(), claas) + Constants.LINE_SEPARATOR);
                ret &= false;
                break;
            }
        } else {
            refs.put(claas, plugin.getInfo().getMainClass());
        }
    }
    return ret;
}

From source file:com.soomla.data.RewardStorage.java

private static List<String> getRewardIds() {
    List<String> kvKeys = KeyValueStorage.getEncryptedKeys();
    List<String> rewardIds = new ArrayList<String>();
    if (kvKeys == null) {
        return rewardIds;
    }/*from ww w  .  j  a  va  2 s .com*/

    for (String key : kvKeys) {
        if (key.startsWith(DB_KEY_REWARDS)) {
            String rewardId = key.replace(DB_KEY_REWARDS, "");
            int dotIndex = rewardId.indexOf('.');
            if (dotIndex != -1) {
                rewardId = rewardId.substring(0, dotIndex);
            }
            if (!rewardIds.contains(rewardId)) {
                rewardIds.add(rewardId);
            }
        }
    }

    return rewardIds;
}

From source file:com.tethrnet.manage.db.SystemDB.java

/**
 * method to check system permissions for user
 *
 * @param con DB connection/*  ww  w .  j av a2  s .  co m*/
 * @param systemSelectIdList list of system ids to check
 * @param userId             user id
 * @return only system ids that user has perms for
 */
public static List<Long> checkSystemPerms(Connection con, List<Long> systemSelectIdList, Long userId) {

    List<Long> systemIdList = new ArrayList<Long>();
    List<Long> userSystemIdList = getAllSystemIdsForUser(con, userId);

    for (Long systemId : userSystemIdList) {
        if (systemSelectIdList.contains(systemId)) {
            systemIdList.add(systemId);
        }
    }

    return systemIdList;

}

From source file:com.glaf.base.security.BaseIdentityFactory.java

/**
 * ???/*from   w  w w .java2  s  .  c  o m*/
 * 
 * @param actorIds
 * @return
 */
public static List<String> getUserRoleCodes(List<String> actorIds) {
    List<String> codes = new java.util.ArrayList<String>();
    List<SysRole> list = getUserRoles(actorIds);
    if (list != null && !list.isEmpty()) {
        for (SysRole role : list) {
            if (!codes.contains(role.getCode())) {
                codes.add(role.getCode());
            }
        }
    }
    return codes;
}

From source file:com.keybox.manage.db.SystemDB.java

/**
 * method to check system permissions for user
 *
 * @param con DB connection//  w w w  . j a  v  a  2s. c  o  m
 * @param systemSelectIdList list of system ids to check
 * @param userId             user id
 * @return only system ids that user has perms for
 */
public static List<Long> checkSystemPerms(Connection con, List<Long> systemSelectIdList, Long userId) {

    List<Long> systemIdList = new ArrayList<>();
    List<Long> userSystemIdList = getAllSystemIdsForUser(con, userId);

    for (Long systemId : userSystemIdList) {
        if (systemSelectIdList.contains(systemId)) {
            systemIdList.add(systemId);
        }
    }

    return systemIdList;

}

From source file:com.taobao.android.builder.tools.sign.LocalSignHelper.java

private static Predicate<String> getNoCompressPredicate(File inputFile) throws IOException {
    List<String> paths = new ArrayList<>();
    ZipFile zFile = new ZipFile(inputFile);
    Enumeration<? extends ZipEntry> enumeration = zFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = enumeration.nextElement();
        if (zipEntry.getMethod() == 0) {
            paths.add(zipEntry.getName());
        }/* w w  w . j  av  a2  s. c  o  m*/
    }
    return s -> paths.contains(s);

}

From source file:edu.umn.msi.tropix.proteomics.parameters.ParameterUtils.java

/**
 * This is the (mostly) inverse of {@link #setParametersFromMap(Map, Object)}. Given a parameter object that is bean where the parameters are the
 * attributes with a simple type (i.e. Double, Integer, Float, or Boolean), a map of the attribute names to values (as strings) is
 * created.//from   w  w w  . java2 s. c o  m
 * 
 * @param parameters
 *          Parameter object to pull keys and values from.
 * @return
 */
@SuppressWarnings("unchecked")
public static void setMapFromParameters(final Object parameters, final Map parameterMap) {
    final List<Class> simpleTypes = java.util.Arrays.asList(new Class[] { Double.class, Integer.class,
            Float.class, Boolean.class, Long.class, String.class, Short.class, double.class, int.class,
            float.class, boolean.class, long.class, short.class });
    for (final Method method : parameters.getClass().getMethods()) {
        String methodName = method.getName();
        if (method.getParameterTypes().length != 0
                || !(methodName.startsWith("get") || methodName.startsWith("is"))
                || !simpleTypes.contains(method.getReturnType())) {
            continue;
        }
        String attributeName;
        if (methodName.startsWith("get")) {
            attributeName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
        } else { // is method
            attributeName = methodName.substring(2, 3).toLowerCase() + methodName.substring(3);
        }
        Object result;
        try {
            result = method.invoke(parameters);
        } catch (final Exception e) {
            logger.info(e);
            throw new IllegalArgumentException(
                    "Failed to invoke get method on bean, should not happen with simple beans.", e);
        }
        if (result != null) {
            parameterMap.put(attributeName, result.toString());
        } // else null value found in setMapFromParameters, not adding it to the map"
    }
}