本文整理汇总了Java中java.util.HashSet.contains方法的典型用法代码示例。如果您正苦于以下问题:Java HashSet.contains方法的具体用法?Java HashSet.contains怎么用?Java HashSet.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashSet
的用法示例。
在下文中一共展示了HashSet.contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteUnknownLibs
import java.util.HashSet; //导入方法依赖的package包/类
private static void deleteUnknownLibs(Context context, PxAll all) {
HashSet<String> names = new HashSet<>();
for (PluginInfo p : all.getPlugins()) {
names.add(p.getNativeLibsDir().getName());
}
File dir = context.getDir(AppConstant.LOCAL_PLUGIN_DATA_LIB_DIR, 0);
File files[] = dir.listFiles();
if (files != null) {
for (File f : files) {
if (names.contains(f.getName())) {
continue;
}
if (LOG) {
LogDebug.d(PLUGIN_TAG, "delete unknown libs=" + f.getAbsolutePath());
}
try {
FileUtils.forceDelete(f);
} catch (IOException e) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "can't delete unknown libs=" + f.getAbsolutePath(), e);
}
}
}
}
}
示例2: getTypedWordAndPreviousSuggestions
import java.util.HashSet; //导入方法依赖的package包/类
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
@Nonnull final SuggestedWordInfo typedWordInfo,
@Nonnull final SuggestedWords previousSuggestions) {
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<>();
final HashSet<String> alreadySeen = new HashSet<>();
suggestionsList.add(typedWordInfo);
alreadySeen.add(typedWordInfo.mWord);
final int previousSize = previousSuggestions.size();
for (int index = 1; index < previousSize; index++) {
final SuggestedWordInfo prevWordInfo = previousSuggestions.getInfo(index);
final String prevWord = prevWordInfo.mWord;
// Filter out duplicate suggestions.
if (!alreadySeen.contains(prevWord)) {
suggestionsList.add(prevWordInfo);
alreadySeen.add(prevWord);
}
}
return suggestionsList;
}
示例3: getCommonPrefix
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns the longest string that is a prefix of all accepted strings and
* visits each state at most once. The automaton must be deterministic.
*
* @return common prefix
*/
public static String getCommonPrefix(Automaton a) {
if (a.isDeterministic() == false) {
throw new IllegalArgumentException("input automaton must be deterministic");
}
StringBuilder b = new StringBuilder();
HashSet<Integer> visited = new HashSet<>();
int s = 0;
boolean done;
Transition t = new Transition();
do {
done = true;
visited.add(s);
if (a.isAccept(s) == false && a.getNumTransitions(s) == 1) {
a.getTransition(s, 0, t);
if (t.min == t.max && !visited.contains(t.dest)) {
b.appendCodePoint(t.min);
s = t.dest;
done = false;
}
}
} while (!done);
return b.toString();
}
示例4: checkRecovery
import java.util.HashSet; //导入方法依赖的package包/类
public static boolean checkRecovery() {
HashSet<String> projectNames = loadProjectsNames();
boolean ret = false;
if(projectNames.isEmpty()){
// For debug purposes
System.out.println("No projects to load");
}else{
System.out.println("Loading projects");
for (String s : projectNames) {
if(s.contains(Projet.FORMAT)) {
if(projectNames.contains(Projet.RECOVERY+s)) {
ret=true;
break;
}
}
}
}
return ret;
}
示例5: loadPages
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Loads pages from the specified directory.
*
* @param directory The directory.
* @param destinations Already added pages destinations.
*
* @return A set of files that are not going to be copied because they already exist in the destination.
*
* @throws LoadException If the specified file is not a directory.
*/
private final HashSet<String> loadPages(final File directory, final HashSet<String> destinations) throws LoadException {
if(!directory.isDirectory()) {
throw new LoadException("The file \"" + directory + "\" is not a directory.");
}
final HashSet<String> alreadyExist = new HashSet<String>();
for(final File child : directory.listFiles()) {
if(child.isDirectory()) {
loadPages(child, destinations);
continue;
}
if(FilenameUtils.getExtension(child.getName()).equalsIgnoreCase("md")) {
final DocsPage page = new DocsPage(this, child);
final String path = page.getBuildDestinationPath();
if(destinations.contains(path)) {
alreadyExist.add(path);
continue;
}
destinations.add(path);
addPages(page);
}
}
return alreadyExist;
}
示例6: containsAnyUuid
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns true if there any common ParcelUuids in uuidA and uuidB.
*
* @param uuidA - List of ParcelUuids
* @param uuidB - List of ParcelUuids
*/
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
if (uuidA == null && uuidB == null) return true;
if (uuidA == null) {
return uuidB.length == 0;
}
if (uuidB == null) {
return uuidA.length == 0;
}
HashSet<ParcelUuid> uuidSet = new HashSet<>(Arrays.asList(uuidA));
for (ParcelUuid uuid : uuidB) {
if (uuidSet.contains(uuid)) return true;
}
return false;
}
示例7: scanMissingAddons
import java.util.HashSet; //导入方法依赖的package包/类
/**
* The sdk manager only lists valid addons. However here we also want to find "broken"
* addons, i.e. addons that failed to load for some reason.
* <p/>
* Find any other sub-directories under the /add-ons root that hasn't been visited yet
* and assume they contain broken addons.
*/
private void scanMissingAddons(SdkManager sdkManager,
HashSet<File> visited,
ArrayList<Package> packages,
ILogger log) {
File addons = new File(new File(sdkManager.getLocation()), SdkConstants.FD_ADDONS);
for (File dir : listFilesNonNull(addons)) {
if (dir.isDirectory() && !visited.contains(dir)) {
Pair<Map<String, String>, String> infos =
parseAddonProperties(dir, sdkManager.getTargets(), log);
Properties sourceProps =
parseProperties(new File(dir, SdkConstants.FN_SOURCE_PROP));
Map<String, String> addonProps = infos.getFirst();
String error = infos.getSecond();
try {
Package pkg = AddonPackage.createBroken(dir.getAbsolutePath(),
sourceProps,
addonProps,
error);
packages.add(pkg);
visited.add(dir);
} catch (Exception e) {
log.error(e, null);
}
}
}
}
示例8: eval
import java.util.HashSet; //导入方法依赖的package包/类
private BigDecimal eval(Interpreter interpreter, HashMap<String, BigDecimal> arguments, HashSet<String> reserved) throws SyntaxException, ArithmeticException, StackOverflowError {
if (value == null) {
BigDecimal l = left.eval(interpreter, arguments);
BigDecimal r = right.eval(interpreter, arguments);
switch (operator) {
case '-': return l.subtract(r);
case '+': return l.add(r);
case '*': return l.multiply(r);
case '%': return l.remainder(r);
case '/': return l.divide(r, interpreter.getInternalRounding(), RoundingMode.HALF_UP);
case '^': return l.pow(r.intValue());
}
}
if (reserved.contains(value))
throw new SyntaxException("Variable '" + value + "' is reserved");
if(arguments.containsKey(value))
return arguments.get(value);
HashMap<String, BigDecimal> variables = interpreter.getVariables();
if(variables.containsKey(value))
return variables.get(value);
if (value.contains("(")) {
HashMap<String, Function> functions = interpreter.getFunctions();
String name = value.split("\\(")[0];
if(!functions.containsKey(name)) throw new SyntaxException("Function '" + name + "' not defined");
String args = value.substring(name.length() + 1, value.length() - 1);
return functions.get(name).eval(interpreter, arguments, args);
}
if(value.matches("[0-9]+(\\.[0-9]*)?"))
return new BigDecimal(value);
throw new SyntaxException("Variable '" + value + "' not defined");
}
示例9: chooseNewValue
import java.util.HashSet; //导入方法依赖的package包/类
private Object chooseNewValue(HashSet<Object> usedValues, Object[] allValues) {
Object newValue = null;
// if we do not have any constant values for the requested type, we
// return null
if (null == allValues || allValues.length == 0) {
return null;
}
// if we havent used any values, just pick one
if (null == usedValues || usedValues.size() == 0) {
newValue = allValues[DeterministicRandom.theRandom.nextInt(allValues.length)];
} else {
if (!RETURN_DUPLICATES) {
// if all values have been tried -> return null == out of values
if (usedValues.size() == allValues.length) {
return null;
}
do {
newValue = allValues[DeterministicRandom.theRandom.nextInt(allValues.length)];
} while (usedValues.contains(newValue));
} else {
// just choose one and dont care about duplicates
newValue = allValues[DeterministicRandom.theRandom.nextInt(allValues.length)];
}
}
return newValue;
}
示例10: getStreamedSectors
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Додає в масив сектори відображення, які пов’язані між собою одним потоком
* і знаходяться на одному функціональному блоці.
*
* @param sector - сектор, для якого будуть знайдені пов’язані.
* @param v Вектор в який будуть додані сектори відображення.
*/
public void getStreamedSectors(final PaintSector sector, final HashSet v) {
getStreamedSectors(sector.getSector(), sector.getStart(), v, true);
getStreamedSectors(sector.getSector(), sector.getEnd(), v, true);
if (!v.contains(sector))
v.add(sector);
}
示例11: removeNetworkComponentsInverse
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Removes all network components if not in the specified list.
* @param networkComponentsToKeep the network components to keep when deleting network components
*/
public HashSet<NetworkComponent> removeNetworkComponentsInverse(HashSet<NetworkComponent> networkComponentsToKeep) {
HashSet<NetworkComponent> removed = new HashSet<NetworkComponent>();
HashSet<String> networkComponentIDs = this.getNetworkComponentsIDs(networkComponentsToKeep);
for (NetworkComponent networkComponent : new ArrayList<NetworkComponent>(this.networkComponents.values())) {
if (networkComponentIDs.contains(networkComponent.getId())==false) {
removeNetworkComponent(networkComponent, true, false);
removed.add(networkComponent);
}
}
this.refreshGraphElements();
return removed;
}
示例12: configureMetaData
import java.util.HashSet; //导入方法依赖的package包/类
void configureMetaData() throws DataSetException {
try {
ResultSetMetaData e = this.getCachedResultSet().getMetaData();
LinkedList columnNames = new LinkedList();
LinkedList columnTypes = new LinkedList();
HashSet usedNames = new HashSet();
for(int columnIndex = 1; columnIndex <= e.getColumnCount(); ++columnIndex) {
String dbColumnName = e.getColumnLabel(columnIndex);
String columnName = dbColumnName;
int valueType;
if(usedNames.contains(dbColumnName)) {
valueType = 1;
do {
columnName = dbColumnName + "_" + valueType;
++valueType;
} while(usedNames.contains(columnName));
}
usedNames.add(columnName);
columnNames.add(columnName);
valueType = DatabaseHandler.getRapidMinerTypeIndex(e.getColumnType(columnIndex));
columnTypes.add(ResultSetAdapterUtils.transformValueType(valueType));
}
this.metaData = new DefaultDataSetMetaData(columnNames, columnTypes);
} catch (SQLException var9) {
throw new DataSetException(var9.getMessage(), var9);
}
}
示例13: removeDublicates
import java.util.HashSet; //导入方法依赖的package包/类
public void removeDublicates() {
HashSet<RowArrayHolder> arrayHolders = new HashSet<RowArrayHolder>();
List<Row[]> newRows = new ArrayList<Row[]>();
for (Row[] rows : this.rows) {
RowArrayHolder holder = new RowArrayHolder(rows);
if (!arrayHolders.contains(holder)) {
arrayHolders.add(holder);
newRows.add(rows);
}
}
rows = newRows;
}
示例14: mergeHashSet
import java.util.HashSet; //导入方法依赖的package包/类
@SafeVarargs
public static HashSet<String> mergeHashSet(HashSet<String>... list) {
HashSet<String> mergedHashSet = new HashSet<>();
for (HashSet<String> hashSet : list) {
for(String str : hashSet)
if(!mergedHashSet.contains(str))
mergedHashSet.add(str);
}
return mergedHashSet;
}
示例15: asString
import java.util.HashSet; //导入方法依赖的package包/类
public static String asString(HashSet<String> relevantRecipeNames, ArrayList<Recipe> allRecipes){
//TODO: store recipes in hash instead
StringBuilder recipes = new StringBuilder();
for(Recipe recipe:allRecipes){
if(relevantRecipeNames.contains(recipe.getName())){
recipe.print(false);
recipes.append(recipe.all());
}
}
return recipes.toString();
}