Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

In this page you can find the example usage for java.util HashSet add.

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:com.github.michalbednarski.intentslab.Utils.java

/**
 * contentValues.keySet() with fallback for older platform versions
 *//*w  w  w.ja v a 2s  . co m*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static Set<String> getKeySet(ContentValues contentValues) {
    try {
        return contentValues.keySet();
    } catch (NoSuchMethodError error) {
        HashSet<String> set = new HashSet<String>();
        for (Map.Entry<String, Object> entry : contentValues.valueSet()) {
            set.add(entry.getKey());
        }
        return set;
    }
}

From source file:com.fiveamsolutions.nci.commons.web.struts2.validator.HibernateValidator.java

private static Set<String> parseList(String list) {
    if (StringUtils.isBlank(list)) {
        return null;
    }//from w  w w. j av a2s .  c om
    HashSet<String> names = new HashSet<String>();
    StringTokenizer st = new StringTokenizer(list, ",");
    while (st.hasMoreTokens()) {
        String n = st.nextToken().trim();
        if (StringUtils.isNotBlank(n)) {
            names.add(n);
        }
    }
    return !names.isEmpty() ? names : null;
}

From source file:de.schaeuffelhut.android.openvpn.Preferences.java

public final static ArrayList<File> listKnownConfigs(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    HashSet<File> configs = new HashSet<File>();
    for (String key : preferences.getAll().keySet())
        if (isConfigKey(key))
            configs.add(configOf(key));
    configs.addAll(configs(getConfigDir(context, preferences)));
    ArrayList<File> sortedConfigs = new ArrayList<File>(configs);
    Collections.sort(sortedConfigs);
    return sortedConfigs;
}

From source file:com.indivica.olis.Driver.java

private static void notifyOlisError(Provider provider, String errorMsg) {
    HashSet<String> sendToProviderList = new HashSet<String>();

    String providerNoTemp = "999998";
    sendToProviderList.add(providerNoTemp);

    if (provider != null) {
        // manual prompts always send to admin
        sendToProviderList.add(providerNoTemp);

        providerNoTemp = provider.getProviderNo();
        sendToProviderList.add(providerNoTemp);
    }//from   w  w w.jav  a  2 s.c o  m

    // no one wants to hear about the problem
    if (sendToProviderList.size() == 0)
        return;

    String message = "OSCAR attempted to perform a fetch of OLIS data at " + new Date()
            + " but there was an error during the task.\n\nSee below for the error message:\n" + errorMsg;

    oscar.oscarMessenger.data.MsgMessageData messageData = new oscar.oscarMessenger.data.MsgMessageData();

    ArrayList<MsgProviderData> sendToProviderListData = new ArrayList<MsgProviderData>();
    for (String providerNo : sendToProviderList) {
        MsgProviderData mpd = new MsgProviderData();
        mpd.providerNo = providerNo;
        mpd.locationId = "145";
        sendToProviderListData.add(mpd);
    }

    String sentToString = messageData.createSentToString(sendToProviderListData);
    messageData.sendMessage2(message, "OLIS Retrieval Error", "System", sentToString, "-1",
            sendToProviderListData, null, null);
}

From source file:exm.stc.ic.ICUtil.java

public static void removeDuplicates(List<Var> varList) {
    ListIterator<Var> it = varList.listIterator();
    HashSet<Var> alreadySeen = new HashSet<Var>();
    while (it.hasNext()) {
        Var v = it.next();//from  w ww.  j a v  a  2  s .  c o m
        if (alreadySeen.contains(v)) {
            it.remove();
        } else {
            alreadySeen.add(v);
        }
    }
}

From source file:edu.illinois.whereru.JSONObjectParser.java

/**
 * Extracts profile from DB's response.// www  .j av a 2  s .  c o m
 * One profile per friend.
 * 
 * @param json a result returned from DB
 * @return list of profiles
 * @throws JSONException 
 */
public static ArrayList<Profile> parseDistinctProfile(JSONObject json) throws JSONException {

    HashSet<Profile> set = new HashSet<Profile>();

    JSONArray friendsInfo = json.getJSONArray(TAG_FRIENDS_INFO);

    for (int i = 0; i < friendsInfo.length(); i++) {
        if (!friendsInfo.isNull(i)) {
            JSONObject obj = friendsInfo.getJSONObject(i);
            String id = obj.getString(TAG_FRIEND_ID);
            String nickname = obj.getString(TAG_FRIEND_NAME);
            set.add(new Profile(id, nickname));
        }
    }

    return new ArrayList<Profile>(set);
}

From source file:de.steilerdev.myVerein.server.model.Division.java

/**
 * This function expands the set of divisions. This means that every division, the user is part of (all child divisions of every division) are going to be returned.
 * @param initialSetOfDivisions The set of divisions that needs to be expanded.
 * @param divisionRepository The division repository, needed to get queried.
 * @return The expanded list of divisions.
 *//*  w  w w  .ja va2s  . c  o m*/
@JsonIgnore
@Transient
public static List<Division> getExpandedSetOfDivisions(List<Division> initialSetOfDivisions,
        DivisionRepository divisionRepository) {
    if ((initialSetOfDivisions = getOptimizedSetOfDivisions(initialSetOfDivisions)) == null) {
        logger.warn("Trying to expand a set of divisions, but initial set is either null or empty");
        return null;
    } else {
        logger.debug("Expanding division set");
        HashSet<Division> expandedSetOfDivisions = new HashSet<>();

        for (Division division : initialSetOfDivisions) {
            expandedSetOfDivisions.addAll(divisionRepository.findByAncestors(division));
            expandedSetOfDivisions.add(divisionRepository.findById(division.getId()));
        }
        return new ArrayList<>(expandedSetOfDivisions);
    }
}

From source file:DirectoryWalker.java

/**
 * Get all the Directories in the starting directory (and sub dirs)
 * returns only files ending this the filename
 * @param startingDirectory/*  w  w  w.  j a va  2s  .  c o  m*/
 * @return filesFound (as HashSet)
 * @exception java.io.IOException
 */
public static HashSet getDirs(String startingDirectory) throws java.io.IOException {

    //Local Variables
    String tmpFullFile;
    String tmpSubDir;
    File startDir = new File(startingDirectory);
    File tmpFile;
    String[] thisDirContents;
    HashSet dirsFound = new HashSet();
    HashSet subDirFilesFound;

    //Check that this is a valid directory
    if (!startDir.isDirectory()) {
        throw new java.io.IOException(startingDirectory + " was not a valid directory");
    }

    //Add the current directory to the output list
    dirsFound.add(startingDirectory);

    //Get the contents of the current directory
    thisDirContents = startDir.list();

    if (thisDirContents != null) {
        //Now loop through , apply filter , or adding them to list of sub dirs
        for (int a = 0; a < thisDirContents.length; a++) {

            //Get Handle to (full) file (inc path)  
            tmpFullFile = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory);

            tmpFile = new File(tmpFullFile);

            //We're only interested in directories
            if (tmpFile.isDirectory()) {

                //Add this to the directory list
                dirsFound.add(tmpFullFile);

                //Now Do Recursive Call (to this method)if Directory
                tmpSubDir = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory);
                subDirFilesFound = DirectoryWalker.getDirs(tmpSubDir);
                dirsFound.addAll(subDirFilesFound);
            }

        }
    }

    return dirsFound;

}

From source file:net.dries007.coremod.Coremod.java

public static HashSet<? extends IDependency> getDependencies(IDependency dependency) {
    final HashSet<IDependency> set = new HashSet<IDependency>();

    for (final IDependency nd : dependency.getTransitiveDependencies()) {
        set.add(nd);
        if (dependency.getTransitiveDependencies() != null && !dependency.getTransitiveDependencies().isEmpty())
            set.addAll(getDependencies(nd));
    }//www.j  ava2s  .  c om

    return set;
}

From source file:Main.java

public static void getTop(float[] array, ArrayList<Integer> rankList, int i) {
    rankList.clear();//w w w .  ja v  a2  s. c  om

    int index = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    float max = Float.MIN_VALUE;
    for (int m = 0; m < i && m < array.length; m++) {
        boolean flag = false;
        max = Float.MIN_VALUE;
        for (int no = 0; no < array.length; no++) {
            if (!scanned.contains(no) && array[no] >= max) {
                index = no;
                max = array[no];
                flag = true;
            }
        }
        if (flag) { // found value
            scanned.add(index);
            rankList.add(index);
        }
    }
}