List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:net.nifheim.beelzebu.coins.common.utils.dependencies.DependencyManager.java
public static void loadAllDependencies() { Set<Dependency> dependencies = new LinkedHashSet<>(); dependencies.addAll(Arrays.asList(Dependency.values())); if (classExists("org.sqlite.JDBC") || core.isBungee()) { dependencies.remove(Dependency.SQLITE_DRIVER); }/* w ww . ja v a 2 s . c o m*/ if (classExists("com.mysql.jdbc.Driver")) { dependencies.remove(Dependency.MYSQL_DRIVER); } if (classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory")) { dependencies.remove(Dependency.SLF4J_API); dependencies.remove(Dependency.SLF4J_SIMPLE); } if (classExists("org.apache.commons.io.FileUtils")) { dependencies.remove(Dependency.COMMONS_IO); } if (!dependencies.isEmpty()) { loadDependencies(dependencies); } }
From source file:net.big_oh.common.utils.CollectionsUtil.java
/** * //from ww w.j a v a 2 s. c o m * @param <T> * @param originalSet * The set of original objects from which combinations of size k * will be generated. * @param k * The size of combinations to be generated. * @return Returns the set of all size k sets (or combinations) that can be * constructed from the originalSet * @throws IllegalArgumentException * thrown if k is less than zero of greater than the size of the * original set. */ @SuppressWarnings("unchecked") public static <T> Set<Set<T>> getCombinations(Set<T> originalSet, int k) throws IllegalArgumentException { // sanity check if (k < 0) { throw new IllegalArgumentException("The value of the k parameter cannot be less than zero."); } if (k > originalSet.size()) { throw new IllegalArgumentException( "The value of the k parameter cannot be greater than the size of originalSet."); } // base case ... k == 0 if (k == 0) { Set<Set<T>> combinations = new HashSet<Set<T>>(); combinations.add(new HashSet<T>()); return combinations; } // base case ... k == 1 if (k == 1) { Set<Set<T>> combinations = new HashSet<Set<T>>(); for (T t : originalSet) { Set<T> combination = new HashSet<T>(); combination.add(t); combinations.add(combination); } return combinations; } // recursive case T arbitraryElement = (T) CollectionUtils.get(originalSet, 0); Set<T> everythingElse = new HashSet<T>(originalSet); everythingElse.remove(arbitraryElement); Set<Set<T>> combinations = new HashSet<Set<T>>(); // pair arbitraryElelement with combinations of size k-1 from the // everythingElse collection for (Set<T> combinationForEverythingElse : getCombinations(everythingElse, k - 1)) { combinationForEverythingElse.add(arbitraryElement); combinations.add(combinationForEverythingElse); } // get combinations of size k from the everythingElse collection if (k <= everythingElse.size()) { for (Set<T> combinationForEverythingElse : getCombinations(everythingElse, k)) { combinations.add(combinationForEverythingElse); } } return combinations; }
From source file:org.xbmc.kore.ui.hosts.AddHostFragmentFinish.java
/** * Checks wheter PVR is enabled and sets a Preference that controls the items to show on * the navigation drawer accordingly: if PVR is disabled, hide the PVR item, otherwise show it * * This// w ww . j a va 2 s . c o m * * @param context Context */ public static void checkPVREnabledAndSetMenuItems(final Context context, Handler handler) { final HostConnection conn = HostManager.getInstance(context).getConnection(); final int hostId = HostManager.getInstance(context).getHostInfo().getId(); org.xbmc.kore.jsonrpc.method.Settings.GetSettingValue getSettingValue = new org.xbmc.kore.jsonrpc.method.Settings.GetSettingValue( org.xbmc.kore.jsonrpc.method.Settings.PVRMANAGER_ENABLED); getSettingValue.execute(conn, new ApiCallback<JsonNode>() { @Override public void onSuccess(JsonNode result) { // Result is boolean boolean isEnabled = result.asBoolean(false); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Set<String> shownItems = new HashSet<>(Arrays .asList(context.getResources().getStringArray(R.array.entry_values_nav_drawer_items))); if (!isEnabled) shownItems.remove(String.valueOf(NavigationDrawerFragment.ACTIVITY_PVR)); sp.edit().putStringSet(Settings.getNavDrawerItemsPrefKey(hostId), shownItems).apply(); } @Override public void onError(int errorCode, String description) { // Ignore, use defaults } }, handler); }
From source file:com.apptentive.android.sdk.util.JsonDiffer.java
public static JSONObject getDiff(JSONObject original, JSONObject updated) { JSONObject ret = new JSONObject(); Set<String> originalKeys = getKeys(original); Set<String> updatedKeys = getKeys(updated); Iterator<String> it = originalKeys.iterator(); while (it.hasNext()) { String key = it.next();/*from ww w.ja v a 2 s .c om*/ updatedKeys.remove(key); try { Object oldValue = original.opt(key); Object newValue = updated.opt(key); if (isEmpty(oldValue)) { if (!isEmpty(newValue)) { // Old is empty. New is not. Update. ret.put(key, newValue); } } else if (isEmpty(newValue)) { // Old is not empty, but new is empty. Clear value. ret.put(key, JSONObject.NULL); } else if (oldValue instanceof JSONObject && newValue instanceof JSONObject) { // Diff JSONObjects if (!areObjectsEqual(oldValue, newValue)) { ret.put(key, newValue); } } else if (oldValue instanceof JSONArray && newValue instanceof JSONArray) { // Diff JSONArrays // TODO: At least check for strict equality. Right now, we always send nested JSONArrays. ret.put(key, newValue); } else if (!oldValue.equals(newValue)) { // Diff primitives ret.put(key, newValue); } else if (oldValue.equals(newValue)) { // Do nothing. } } catch (JSONException e) { Log.w("Error diffing object with key %s", e, key); } finally { it.remove(); } } // Finally, add in the keys that were added in the new object. it = updatedKeys.iterator(); while (it.hasNext()) { String key = it.next(); try { ret.put(key, updated.get(key)); } catch (JSONException e) { // This can't happen. } } // If there is no difference, return null. if (ret.length() == 0) { ret = null; } Log.v("Generated diff: %s", ret); return ret; }
From source file:com.anathema_roguelike.main.utilities.Utils.java
@SuppressWarnings("unchecked") public static <T> Collection<Class<? extends T>> getSubclasses(Class<T> superclass, boolean includeAbstract, boolean includeSuperclass, Predicate<Class<? extends T>> predicate) { ArrayList<Class<? extends T>> ret = new ArrayList<>(); if (subtypeCache.containsKey(superclass)) { ret = new ArrayList<>((ArrayList<Class<? extends T>>) subtypeCache.get(superclass)); } else {/*from w w w .j a v a 2 s. com*/ Rebound rebound = new Rebound("com.anathema_roguelike", includeAbstract); Set<Class<? extends T>> subTypes = rebound.getSubClassesOf(superclass); if (!includeSuperclass) { subTypes.remove(superclass); } ArrayList<Class<? extends T>> sorted = new ArrayList<>(subTypes); Collections.sort(sorted, new Comparator<Class<? extends T>>() { @Override public int compare(Class<? extends T> o1, Class<? extends T> o2) { return o1.getName().compareTo(o2.getName()); } }); subtypeCache.put((Class<?>) superclass, (ArrayList<Class<? extends T>>) sorted); ret = new ArrayList<>(sorted); } return Collections2.filter(ret, predicate); }
From source file:net.audumla.climate.ClimateDataFactory.java
/** * Replaces the climate data with a readonly version. * * @param cd the existing climate data bean * @return the climate data/* w ww. ja v a 2 s . com*/ */ public static ClimateData convertToReadOnlyClimateData(ClimateData cd) { if (cd == null) { return null; } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass())); interfaces.remove(WritableClimateData.class); return BeanUtils.convertBean(cd, interfaces.toArray(new Class<?>[interfaces.size()])); }
From source file:net.audumla.climate.ClimateDataFactory.java
/** * Replaces the climate observation with a readonly version. * * @param cd the existing climate data bean * @return the climate data//from w ww . j a v a 2 s. c o m */ public static ClimateObservation convertToReadOnlyClimateObservation(ClimateObservation cd) { if (cd == null) { return null; } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass())); interfaces.remove(WritableClimateObservation.class); return BeanUtils.convertBean(cd, interfaces.toArray(new Class<?>[interfaces.size()])); }
From source file:com.hp.autonomy.aci.content.database.Databases.java
/** * Parses a {@code String} of database names in the format used in a <tt>query</tt> or <tt>getcontent</tt> action. * This includes parsing the output of {@link #toString()}. An empty string will be treated as equivalent to * <tt>*</tt>, even though technically there is a slight difference when working with internal databases. * * @param databases The string representation to parse * @return A {@code Databases} object/*from www .ja v a2 s . co m*/ */ public static Databases parse(final String databases) { Validate.notNull(databases, "Databases must not be null"); if (SPACES.matcher(databases).matches()) { return Databases.ALL; } final Set<String> databasesSet = new LinkedHashSet<String>(Arrays.asList(SEPARATORS.split(databases))); databasesSet.remove(""); if (databasesSet.isEmpty()) { return new Databases(); } if ("*".equals(databasesSet.iterator().next())) { return ALL; } databasesSet.remove("*"); databasesSet.remove(MATCH_NOTHING); return new Databases(databasesSet); }
From source file:com.espertech.esper.event.vaevent.PropertyUtility.java
/** * Remove from values all removeValues and build a unique sorted result array. * @param values to consider/*w ww. j a va2s .c om*/ * @param removeValues values to remove from values * @return sorted unique */ protected static String[] uniqueExclusiveSort(String[] values, String[] removeValues) { Set<String> unique = new HashSet<String>(); unique.addAll(Arrays.asList(values)); for (String removeValue : removeValues) { unique.remove(removeValue); } String[] uniqueArr = unique.toArray(new String[unique.size()]); Arrays.sort(uniqueArr); return uniqueArr; }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyCustomFunctionsInitializer.java
private static void registerBitwiseFunctions(final Connection con, String schema) throws SQLException { DatabaseMetaData dbMeta = con.getMetaData(); ResultSet rs = dbMeta.getFunctions(null, null, null); Set<String> functionNames = new HashSet<String>(Arrays.asList(BITWISE_AND, BITWISE_OR)); while (rs.next()) { String schemaName = rs.getString(2); String functionName = rs.getString(3).toUpperCase(); if (schema.equalsIgnoreCase(schemaName) && functionNames.contains(functionName)) { functionNames.remove(functionName); }/*from w ww . j a v a2s . c o m*/ } // at this point, functionNames contains the functions we need to create if (functionNames.size() > 0) { final String sqlTemplate = "CREATE FUNCTION %s.%s( parm1 INTEGER, param2 INTEGER ) " + "RETURNS INTEGER LANGUAGE JAVA DETERMINISTIC PARAMETER STYLE JAVA NO SQL " + "EXTERNAL NAME 'net.solarnetwork.node.dao.jdbc.derby.ext.DerbyBitwiseFunctions.%s'"; if (functionNames.contains(BITWISE_AND)) { final String sql = String.format(sqlTemplate, schema, BITWISE_AND, "bitwiseAnd"); con.createStatement().execute(sql); } if (functionNames.contains(BITWISE_OR)) { final String sql = String.format(sqlTemplate, schema, BITWISE_OR, "bitwiseOr"); con.createStatement().execute(sql); } } }