List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
public static boolean isUserLoggedIn(Context context) { return !PreferenceManager.getDefaultSharedPreferences(context) .getStringSet(LOGGED_IN_USER_PREFERENCE_KEY, new HashSet<String>()).isEmpty(); }
From source file:Main.java
public static boolean validProcess(String xml) { try {/*from www. ja va 2s . c om*/ Set<String> classifiers = new HashSet<String>(); InputStream is = new ByteArrayInputStream(xml.getBytes()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(is); // iterate over all operators NodeList nodes = document.getElementsByTagName("operator"); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); String className = element.getAttribute("class"); if (classifiers.contains(className)) { return false; } classifiers.add(className); } return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static Set<String> LoadLisPreferences(String key, Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> value = new HashSet<String>(); value = sharedPreferences.getStringSet(key, null); return value; }
From source file:com.glaf.core.util.JsonUtils.java
public static void main(String[] args) throws Exception { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); dataMap.put("key01", ""); dataMap.put("key02", 12345); dataMap.put("key03", 789.85D); dataMap.put("date", new Date()); Collection<Object> actorIds = new HashSet<Object>(); actorIds.add("sales01"); actorIds.add("sales02"); actorIds.add("sales03"); actorIds.add("sales04"); actorIds.add("sales05"); dataMap.put("actorIds", actorIds.toArray()); dataMap.put("x_sale_actor_actorIds", actorIds); Map<String, Object> xxxMap = new java.util.HashMap<String, Object>(); xxxMap.put("0", "--------"); xxxMap.put("1", "?"); xxxMap.put("2", ""); xxxMap.put("3", ""); dataMap.put("trans", xxxMap); String str = JsonUtils.encode(dataMap); System.out.println(str);/*from ww w . jav a 2 s. co m*/ Map<?, ?> p = JsonUtils.decode(str); System.out.println(p); System.out.println(p.get("date").getClass().getName()); String xx = "{name:\"trans\",nodeType:\"select\",children:{\"1\":\"?\",\"3\":\"\",\"2\":\"\",\"0\":\"--------\"}}"; Map<String, Object> xMap = JsonUtils.decode(xx); System.out.println(xMap); Set<Entry<String, Object>> entrySet = xMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); System.out.println(key + " = " + value); System.out.println(key.getClass().getName() + " " + value.getClass().getName()); if (value instanceof JSONObject) { JSONObject json = (JSONObject) value; Iterator<?> iter = json.keySet().iterator(); while (iter.hasNext()) { String kk = (String) iter.next(); System.out.println(kk + " = " + json.get(kk)); } } } }
From source file:Main.java
static Set<Pattern> getFilterFromFile(String filename) { try {//from w w w .j ava 2 s . c o m BufferedReader br = new BufferedReader(new FileReader(filename)); Set<Pattern> filter = new HashSet<>(); String line; while ((line = br.readLine()) != null) { if (line.trim().equals("")) { continue; } filter.add(Pattern.compile(line.trim().toLowerCase())); } return filter; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:Main.java
/** * Converts an array of chars to a Set of Characters. * @param array the contents of the new Set * @return a Set containing the elements in the array *///from w w w . ja va2 s . c o m public static Set<Character> arrayToSet(char... array) { Set<Character> toReturn; if (array == null) return new HashSet<Character>(); toReturn = new HashSet<Character>(array.length); for (char c : array) { toReturn.add(c); } return toReturn; }
From source file:Main.java
protected static Set unionEmail(Set excluded, String email) { String _sub = email.substring(email.indexOf('@') + 1); if (excluded.isEmpty()) { excluded.add(_sub);/*from w w w . ja v a 2 s . c om*/ return excluded; } else { Set intersect = new HashSet(); Iterator _iter = excluded.iterator(); while (_iter.hasNext()) { String _excluded = (String) _iter.next(); if (_sub.endsWith(_excluded)) { intersect.add(_excluded); } else if (_excluded.endsWith(_sub)) { intersect.add(_sub); } else { intersect.add(_excluded); intersect.add(_sub); } } return intersect; } }
From source file:Main.java
protected static Set intersectEmail(Set permitted, String email) { String _sub = email.substring(email.indexOf('@') + 1); if (permitted.isEmpty()) { permitted.add(_sub);//from ww w. j a v a2s.co m return permitted; } else { Set intersect = new HashSet(); Iterator _iter = permitted.iterator(); while (_iter.hasNext()) { String _permitted = (String) _iter.next(); if (_sub.endsWith(_permitted)) { intersect.add(_sub); } else if (_permitted.endsWith(_sub)) { intersect.add(_permitted); } } return intersect; } }
From source file:Main.java
public static Set minus(Set oriSet, Set tarSet) { if (oriSet == null || oriSet.size() == 0) return oriSet; if (tarSet == null || tarSet.size() == 0) return oriSet; Iterator oriItor = oriSet.iterator(); Set minusSet = new HashSet(); while (oriItor.hasNext()) { Object oriObj = oriItor.next(); Iterator tarItor = tarSet.iterator(); boolean isExist = false; while (tarItor.hasNext()) { Object tarObj = tarItor.next(); if (tarObj.equals(oriObj)) { isExist = true;/*ww w . ja va 2 s . c o m*/ break; } } if (!isExist) { minusSet.add(oriObj); } } return minusSet; }
From source file:Main.java
public static void deleteFaces(List<String> faceIdsToDelete, String personId, Context context) { Set<String> faceIds = getAllFaceIds(personId, context); Set<String> newFaceIds = new HashSet<>(); for (String faceId : faceIds) { if (!faceIdsToDelete.contains(faceId)) { newFaceIds.add(faceId);//from w ww .ja va 2s. c o m } } SharedPreferences faceIdSet = context.getSharedPreferences(personId + "FaceIdSet", Context.MODE_PRIVATE); SharedPreferences.Editor faceIdSetEditor = faceIdSet.edit(); faceIdSetEditor.putStringSet("FaceIdSet", newFaceIds); faceIdSetEditor.commit(); }