List of usage examples for java.util HashSet retainAll
boolean retainAll(Collection<?> c);
From source file:jef.tools.ArrayUtils.java
/** * ?/* w w w.java2 s.c om*/ * * @param ls * @param ls2 * @return */ public static Object[] intersect(Object[] ls, Object[] ls2) { HashSet<Object> set = new HashSet<Object>(Arrays.asList(ls)); set.retainAll(Arrays.asList(ls2)); return set.toArray(); }
From source file:jef.tools.ArrayUtils.java
/** * ????? ? //from w w w . j a v a2s. c o m * * @param ls * @param ls2 * @return */ public static Object[] xor(Object[] ls, Object[] ls2) { // Set<Object> setAll = new HashSet<Object>(Arrays.asList(ls)); for (Object o : ls2) { setAll.add(o); } // HashSet<Object> setInter = new HashSet<Object>(Arrays.asList(ls)); setInter.retainAll(Arrays.asList(ls2)); // ? setAll.removeAll(setInter); return setAll.toArray(); }
From source file:edu.anu.spice.SemanticConcept.java
/** * SemanticConcepts are similar if they share a synset or a concept *///from www.j a v a2 s . c om public boolean similarTo(Object o) { if (o == null) { return false; } if (!(o instanceof SemanticConcept)) { return false; } SemanticConcept otherConcept = (SemanticConcept) o; HashSet<Integer> synset_intersection = new HashSet<Integer>(this.synsets); synset_intersection.retainAll(otherConcept.synsets); if (!synset_intersection.isEmpty()) { return true; } HashSet<String> concept_intersection = new HashSet<String>(this.concepts); concept_intersection.retainAll(otherConcept.concepts); return !concept_intersection.isEmpty(); }
From source file:edu.anu.spice.SemanticConcept.java
public float similarity(Object o) { if (o == null) { return 0; }//w w w . ja v a 2s . co m if (!(o instanceof SemanticConcept)) { return 0; } SemanticConcept otherConcept = (SemanticConcept) o; HashSet<String> concept_intersection = new HashSet<String>(this.concepts); concept_intersection.retainAll(otherConcept.concepts); if (!concept_intersection.isEmpty()) { return 1; } HashSet<Integer> synset_intersection = new HashSet<Integer>(this.synsets); synset_intersection.retainAll(otherConcept.synsets); HashSet<Integer> synset_union = new HashSet<Integer>(this.synsets); synset_union.addAll(otherConcept.synsets); return ((float) synset_intersection.size()) / ((float) synset_union.size()); }
From source file:org.xwalk.runtime.extension.api.contacts.ContactEventListener.java
private HashSet<String> getIntersectSet(HashSet<String> setA, HashSet<String> setB) { HashSet<String> resultSet = new HashSet<String>(); resultSet.addAll(setA);/*from ww w. ja v a2s. c o m*/ resultSet.retainAll(setB); return resultSet; }
From source file:at.bitfire.davdroid.mirakel.webdav.TlsSniSocketFactory.java
@SuppressLint("DefaultLocale") private void setReasonableEncryption(SSLSocket ssl) { // set reasonable SSL/TLS settings before the handshake // Android 5.0+ (API level21) provides reasonable default settings // but it still allows SSLv3 // https://developer.android.com/about/versions/android-5.0-changes.html#ssl // - enable all supported protocols (enables TLSv1.1 and TLSv1.2 on Android <5.0, if available) // - remove all SSL versions (especially SSLv3) because they're insecure now List<String> protocols = new LinkedList<String>(); for (String protocol : ssl.getSupportedProtocols()) if (!protocol.toUpperCase().contains("SSL")) protocols.add(protocol);//from ww w .j a va 2s. c o m Log.v(TAG, "Setting allowed TLS protocols: " + StringUtils.join(protocols, ", ")); ssl.setEnabledProtocols(protocols.toArray(new String[0])); if (android.os.Build.VERSION.SDK_INT < 21) { // choose secure cipher suites List<String> allowedCiphers = Arrays.asList(// TLS 1.2 "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECHDE_RSA_WITH_AES_128_GCM_SHA256", // maximum interoperability "TLS_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA", // additionally "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"); List<String> availableCiphers = Arrays.asList(ssl.getSupportedCipherSuites()); // preferred ciphers = allowed Ciphers \ availableCiphers HashSet<String> preferredCiphers = new HashSet<String>(allowedCiphers); preferredCiphers.retainAll(availableCiphers); // add preferred ciphers to enabled ciphers // for maximum security, preferred ciphers should *replace* enabled ciphers, // but I guess for the security level of DAVdroid, disabling of insecure // ciphers should be a server-side task HashSet<String> enabledCiphers = preferredCiphers; enabledCiphers.addAll(new HashSet<String>(Arrays.asList(ssl.getEnabledCipherSuites()))); Log.v(TAG, "Setting allowed TLS ciphers: " + StringUtils.join(enabledCiphers, ", ")); ssl.setEnabledCipherSuites(enabledCiphers.toArray(new String[0])); } }
From source file:com.wso2.mobile.mdm.api.PhoneState.java
/** * Generate Data Usage Report/*from w w w. ja va 2 s .com*/ */ public JSONObject takeDataUsageSnapShot() { previous = latest; latest = new TrafficSnapshot(context); JSONObject dataObj = new JSONObject(); JSONArray jsonArray = new JSONArray(); String latestRX, latestTX, previousRX, previousTX, deltaRX, deltaTX; latestRX = String.valueOf(formatSizeMB(latest.device.rx)); latestTX = String.valueOf(formatSizeMB(latest.device.tx)); try { dataObj.put("totalupload", latestRX); dataObj.put("totaldownload", latestTX); if (previous != null) { previousRX = String.valueOf(previous.device.rx); previousTX = String.valueOf(previous.device.tx); deltaRX = String.valueOf(latest.device.rx - previous.device.rx); deltaTX = String.valueOf(latest.device.tx - previous.device.tx); } ArrayList<String> log = new ArrayList<String>(); HashSet<Integer> intersection = new HashSet<Integer>(latest.apps.keySet()); if (previous != null) { intersection.retainAll(previous.apps.keySet()); } for (Integer uid : intersection) { TrafficRecord latest_rec = latest.apps.get(uid); TrafficRecord previous_rec = (previous == null ? null : previous.apps.get(uid)); jsonArray.add(getDataUseReport(latest_rec.tag, latest_rec, previous_rec, log)); } dataObj.put("appdata", jsonArray); Collections.sort(log); for (String row : log) { Log.d("TrafficMonitor", row); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataObj; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.persistenceApi.orientdbObj.index.IndexIntersection.java
/** * Load the intersecting referenced objects from the specified indices. * First load the database ids from all indices, intersect them, and load the remaining ids. * /*from w w w . jav a2 s . com*/ * @return the resulting {@link IndexCollectionElement}s */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Collection<IndexCollectionElement<V>> load() { //load dbIds only and sort them by result set size TreeList rawResults = new TreeList(); //no generics possible int maxSize = 0; for (AbstractIndex index : indices) { ResultSet<V> oneResultSet = new ResultSet<V>(index.loadIdsOnly(), index.getName()); rawResults.add(oneResultSet); maxSize = Math.max(maxSize, oneResultSet.getSize()); } // create a list of intersecting dbIds // start with the smallest result set and intersect with the second smallest, intersect this result with the third smallest a.s.o. HashSet<String> intersectingDbIds = new HashSet<String>(maxSize); for (Object r : rawResults) { ResultSet<V> aResult = (ResultSet<V>) r; if (intersectingDbIds.isEmpty()) { intersectingDbIds.addAll(aResult.getDbIds()); } else { intersectingDbIds.retainAll(aResult.getDbIds()); } if (intersectingDbIds.isEmpty()) { break; } } //create Map of IndexElements each, i.e. group by referenced id. Every group is stored in a IndexCollectedElement HashMap<String, IndexCollectionElement<V>> finalElements = new HashMap<String, IndexCollectionElement<V>>( indices.size()); for (Object r : rawResults) { ResultSet<V> aResult = (ResultSet<V>) r; for (IndexElement indexElement : aResult.getList()) { String currentString = indexElement.getDbId(); if (intersectingDbIds.contains(currentString)) { if (!finalElements.containsKey(currentString)) { finalElements.put(currentString, new IndexCollectionElement<V>(currentString)); } finalElements.get(currentString).addIndexElements(indexElement); } } } //load pojos for (IndexCollectionElement<V> collectionElement : finalElements.values()) { collectionElement.loadPojo(papi); } return finalElements.values(); }
From source file:org.apache.accumulo.examples.wikisearch.iterator.BooleanLogicTreeNode.java
public HashSet<Key> getIntersection(HashSet<Key> h) { h.retainAll(uids); return h; }
From source file:dao.FriendDaoDb.java
/** * Get the friends back as a List of Friend beans if they * happen to be friends of each other.//from w w w . j a v a2 s. c o m * * @param friend1 * @param friend2 * @exception BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return HashSet */ public HashSet getSecondFriends(String friend1, String friend2) throws BaseDaoException { if (RegexStrUtil.isNull(friend1) || RegexStrUtil.isNull(friend2)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the already set in the cache * If it exists, return from the cache. */ /* StringBuffer sb = new StringBuffer(friend1); sb.append(friend2); String key = sb.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.FRIEND_SECOND); Object obj = treeCache.get(fqn, key); if (obj != null) { return (HashSet)obj; } */ // friend1 Hdlogin hdlogin = getLoginid(friend1); if (hdlogin == null) { throw new BaseDaoException("hdlogin is null for friend1 " + friend1); } String friendid1 = hdlogin.getValue(DbConstants.LOGIN_ID); if (RegexStrUtil.isNull(friendid1)) { throw new BaseDaoException("friendid1 is null for friend1 " + friend1); } // friend2 hdlogin = getLoginid(friend2); if (hdlogin == null) { throw new BaseDaoException("hdlogin is null for friend2 " + friend2); } String friendid2 = hdlogin.getValue(DbConstants.LOGIN_ID); if (RegexStrUtil.isNull(friendid2)) { throw new BaseDaoException("friendid2 is null for friend2 " + friend2); } /** * Get scalability datasource for hdfriends - not partitioned **/ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getSecondFriends()" + sourceName); } // first query Object[] params = { (Object) friendid1, (Object) friendid1 }; List result = null; try { result = friendQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error occured while executing dbquery " + friendQuery.getSql(), e); } if (result == null) { result = new ArrayList(); } HashSet hs1 = new HashSet(result); // second query params[0] = friendid2; params[1] = friendid2; List result2 = friendQuery.execute(params); if (result2 == null) { result2 = new ArrayList(); } HashSet hs2 = new HashSet(result2); // return the intersection of the two sets boolean f = hs1.retainAll(hs2); //treeCache.put(fqn, key, hs1); return hs1; }