本文整理汇总了Java中java.util.Set类的典型用法代码示例。如果您正苦于以下问题:Java Set类的具体用法?Java Set怎么用?Java Set使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Set类属于java.util包,在下文中一共展示了Set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCorrect
import java.util.Set; //导入依赖的package包/类
/**
* Checks that the given core is unsatisfiable with respect to the given
* bounds.
*
* @return true if the core is correct; false otherwise
*/
static boolean checkCorrect(Set<Formula> core, Bounds bounds) {
System.out.print("checking correctness ... ");
final long start = System.currentTimeMillis();
Solver solver = solver();
solver.options().setSolver(SATFactory.MiniSat);
final Solution sol = solver.solve(Formula.and(core), bounds);
final long end = System.currentTimeMillis();
if (sol.instance() == null) {
System.out.println("correct (" + (end - start) + " ms).");
return true;
} else {
System.out.println("incorrect! (" + (end - start) + " ms). The core is satisfiable:");
System.out.println(sol);
return false;
}
}
示例2: getInstancesOfAnnotation
import java.util.Set; //导入依赖的package包/类
public static <T> List<T> getInstancesOfAnnotation(ASMDataTable asmDataTable, Class annotationClass, Class<T> instanceClass) {
String annotationClassName = annotationClass.getCanonicalName();
Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationClassName);
List<T> instances = new ArrayList<>();
for (ASMDataTable.ASMData asmData : asmDatas) {
try {
Class<?> asmClass = Class.forName(asmData.getClassName());
Class<? extends T> asmInstanceClass = asmClass.asSubclass(instanceClass);
T instance = asmInstanceClass.newInstance();
instances.add(instance);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | LinkageError e) {
HarshenCastle.LOGGER.error("Failed to load: {}", asmData.getClassName(), e);
}
}
return instances;
}
示例3: buildQuery
import java.util.Set; //导入依赖的package包/类
public static String buildQuery(Map<String, String> params, String charset) throws IOException {
if (params == null || params.isEmpty()) {
return null;
}
StringBuilder query = new StringBuilder();
Set<Entry<String, String>> entries = params.entrySet();
boolean hasParam = false;
for (Entry<String, String> entry : entries) {
String name = entry.getKey();
String value = entry.getValue();
// 忽略参数名或参数值为空的参数
if (StringUtils.isAnyEmpty(name, value)) {
if (hasParam) {
query.append("&");
} else {
hasParam = true;
}
query.append(name).append("=").append(URLEncoder.encode(value, charset));
}
}
return query.toString();
}
示例4: executeWithThrowException
import java.util.Set; //导入依赖的package包/类
private void executeWithThrowException(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
RegionFunctionContext rfContext = (RegionFunctionContext) context;
LogWriter logger = ds.getLogWriter();
logger.fine("Executing executeWithThrowException in TestFunction on Member : "
+ ds.getDistributedMember() + "with Context : " + context);
if (context.getArguments() instanceof Boolean) {
logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
throw new MyFunctionExecutionException("I have been thrown from TestFunction");
} else if (rfContext.getArguments() instanceof Set) {
Set origKeys = (Set) rfContext.getArguments();
for (Iterator i = origKeys.iterator(); i.hasNext();) {
Region r = PartitionRegionHelper.getLocalDataForContext(rfContext);
Object key = i.next();
Object val = r.get(key);
if (val != null) {
throw new MyFunctionExecutionException("I have been thrown from TestFunction");
}
}
} else {
logger.fine("Result sent back :" + Boolean.FALSE);
rfContext.getResultSender().lastResult(Boolean.FALSE);
}
}
示例5: getExtraOptionsLD
import java.util.Set; //导入依赖的package包/类
public Set <String> getExtraOptionsLD( boolean debug, boolean coreCopied ) {
String chipkitCoreDirectory = data.get("build.core.path");
String chipkitVariantDirectory = data.get("build.variant.path");
String ldScriptDirectory = data.get("build.ldscript_dir.path");
String ldscript = debug ? data.get("ldscript-debug") : data.get("ldscript");
String ldcommon = data.get("ldcommon");
Set <String> optionSet = new LinkedHashSet<>();
parseOptions( optionSet, data.get("compiler.c.elf.flags") );
removeRedundantCompilerOptions(optionSet);
removeRedundantLinkerOptions(optionSet);
optionSet.add("-mnewlib-libc");
if ( coreCopied ) {
optionSet.add("-T\"" + ldscript + "\"");
optionSet.add("-T\"" + ldcommon + "\"");
} else {
Path ldcommonPath = Paths.get( chipkitCoreDirectory, ldcommon );
Path ldscriptPath = Paths.get( debug && !ldScriptDirectory.isEmpty() ? ldScriptDirectory : chipkitCoreDirectory, ldscript );
if ( !Files.exists(ldscriptPath) && !debug ) {
ldscriptPath = Paths.get( chipkitVariantDirectory, ldscript );
}
optionSet.add("-T\"" + ldscriptPath.toString() + "\"");
optionSet.add("-T\"" + ldcommonPath.toString() + "\"");
}
return optionSet;
}
示例6: testBasicSubprojects
import java.util.Set; //导入依赖的package包/类
public void testBasicSubprojects() throws Exception {
Set subprojects = simpleSubprojects.getSubprojects();
assertTrue("no subprojects for simple", subprojects.isEmpty());
assertEquals("no subprojects for simple", Collections.EMPTY_SET, subprojects);
assertTrue("no subprojects for simple", subprojects.isEmpty());
subprojects = extsrcrootSubprojects.getSubprojects();
assertFalse("extsrcroot has simple as a subproject", subprojects.isEmpty());
assertEquals("extsrcroot has simple as a subproject", Collections.singleton(simple), subprojects);
assertFalse("extsrcroot has simple as a subproject", subprojects.isEmpty());
subprojects = simple2Subprojects.getSubprojects();
assertTrue("no subprojects for simple", subprojects.isEmpty());
assertEquals("no subprojects for simple", Collections.EMPTY_SET, subprojects);
assertTrue("no subprojects for simple", subprojects.isEmpty());
}
示例7: diff
import java.util.Set; //导入依赖的package包/类
private static boolean diff(PrintWriter writer, PgDiffArguments arguments)
throws InterruptedException, IOException, URISyntaxException {
PgDiffScript script;
try (PrintWriter encodedWriter = getDiffWriter(arguments)) {
script = PgDiff.createDiff(encodedWriter != null ? encodedWriter : writer, arguments);
}
if (arguments.isSafeMode()) {
Set<DangerStatement> dangerTypes = script.findDangers(arguments.getAllowedDangers());
if (!dangerTypes.isEmpty()) {
String msg = MessageFormat.format(Messages.Main_danger_statements,
dangerTypes.stream().map(DangerStatement::name)
.collect(Collectors.joining(", ")));
writer.println(msg);
try (PrintWriter encodedWriter = getDiffWriter(arguments)) {
if (encodedWriter != null) {
encodedWriter.println("-- " + msg);
}
}
return false;
}
}
return true;
}
示例8: checkIfGivenExpressionIsValid
import java.util.Set; //导入依赖的package包/类
private void checkIfGivenExpressionIsValid(Map<String, Class<?>> inputSchemaFields, Set<String> errors,
ExpressionData expressionData, ErrorLogTableViewer errorLogTableViewer) {
if(StringUtils.isBlank(expressionData.getExpressionEditorData().getExpression())){
errors.add(Messages.EXPRESSION_IS_BLANK);
}
else{
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
ExpressionEditorUtil.validateExpression(expressionData.getExpressionEditorData().getExpression(),
inputSchemaFields,expressionData.getExpressionEditorData());
if(!expressionData.getExpressionEditorData().isValid()){
errors.add(Messages.EXPRESSION_IS_INVALID);
errorLogTableViewer.refresh();
}
}
});
}
}
示例9: PKIXParameters
import java.util.Set; //导入依赖的package包/类
/**
* Creates an instance of {@code PKIXParameters} that
* populates the set of most-trusted CAs from the trusted
* certificate entries contained in the specified {@code KeyStore}.
* Only keystore entries that contain trusted {@code X509Certificates}
* are considered; all other certificate types are ignored.
*
* @param keystore a {@code KeyStore} from which the set of
* most-trusted CAs will be populated
* @throws KeyStoreException if the keystore has not been initialized
* @throws InvalidAlgorithmParameterException if the keystore does
* not contain at least one trusted certificate entry
* @throws NullPointerException if the keystore is {@code null}
*/
public PKIXParameters(KeyStore keystore)
throws KeyStoreException, InvalidAlgorithmParameterException
{
if (keystore == null)
throw new NullPointerException("the keystore parameter must be " +
"non-null");
Set<TrustAnchor> hashSet = new HashSet<TrustAnchor>();
Enumeration<String> aliases = keystore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keystore.isCertificateEntry(alias)) {
Certificate cert = keystore.getCertificate(alias);
if (cert instanceof X509Certificate)
hashSet.add(new TrustAnchor((X509Certificate)cert, null));
}
}
setTrustAnchors(hashSet);
this.unmodInitialPolicies = Collections.<String>emptySet();
this.certPathCheckers = new ArrayList<PKIXCertPathChecker>();
this.certStores = new ArrayList<CertStore>();
}
示例10: resolve
import java.util.Set; //导入依赖的package包/类
@Override
public List<String> resolve(Context context, List<String> expressions) {
IndicesOptions options = context.getOptions();
MetaData metaData = context.getState().metaData();
if (options.expandWildcardsClosed() == false && options.expandWildcardsOpen() == false) {
return expressions;
}
if (isEmptyOrTrivialWildcard(expressions)) {
return resolveEmptyOrTrivialWildcard(options, metaData, true);
}
Set<String> result = innerResolve(context, expressions, options, metaData);
if (result == null) {
return expressions;
}
if (result.isEmpty() && !options.allowNoIndices()) {
IndexNotFoundException infe = new IndexNotFoundException((String)null);
infe.setResources("index_or_alias", expressions.toArray(new String[0]));
throw infe;
}
return new ArrayList<>(result);
}
示例11: createPoolManager
import java.util.Set; //导入依赖的package包/类
private static ResourcePoolManager createPoolManager(Set<Archive> archives,
Map<String, List<Entry>> entriesForModule,
ByteOrder byteOrder,
BasicImageWriter writer) throws IOException {
ResourcePoolManager resources = new ResourcePoolManager(byteOrder, new StringTable() {
@Override
public int addString(String str) {
return writer.addString(str);
}
@Override
public String getString(int id) {
return writer.getString(id);
}
});
for (Archive archive : archives) {
String mn = archive.moduleName();
entriesForModule.get(mn).stream()
.map(e -> new ArchiveEntryResourcePoolEntry(mn,
e.getResourcePoolEntryName(), e))
.forEach(resources::add);
}
return resources;
}
示例12: findContainers
import java.util.Set; //导入依赖的package包/类
public Set<String> findContainers(Collection<EClass> collection, String selectedType) {
Set<String> result = new HashSet<String>();
SigTrace typeTrace;
try {
typeTrace = getSigTraceByType(selectedType);
} catch (TraceException e1) {
return result;
}
EList<EClass> superTypes = typeTrace.getEClass().getEAllSuperTypes();
for (EClass eClass : collection) {
for (EReference eReference : eClass.getEAllReferences()) {
if (eReference.isContainment()) {
try {
if (superTypes.stream()
.anyMatch(s -> s.getName().equals(eReference.getEReferenceType().getName()))) {
result.add(getSigTraceByClassName(eClass.getName()).getSigType());
}
} catch (TraceException e) {
// no need to handle
}
}
}
}
return result;
}
示例13: computeNodeWildcard
import java.util.Set; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Result computeNodeWildcard(Wildcard expr) {
Result result = new Result();
LabelVar var = expr.getWildcardId();
Set<@NonNull TypeNode> candidates = new HashSet<>();
if (var.hasName()) {
candidates.addAll((Collection<@NonNull TypeNode>) this.varTyping.get(var));
} else {
candidates.addAll(this.typeGraph.nodeSet());
}
TypeGuard guard = expr.getWildcardGuard();
for (TypeNode typeNode : guard.filter(candidates)) {
result.add(typeNode, typeNode);
}
return result;
}
示例14: delegate
import java.util.Set; //导入依赖的package包/类
@Override
protected Set<TypeToken<? super T>> delegate() {
ImmutableSet<TypeToken<? super T>> result = classes;
if (result == null) {
@SuppressWarnings({"unchecked", "rawtypes"})
ImmutableList<TypeToken<? super T>> collectedTypes =
(ImmutableList)
TypeCollector.FOR_GENERIC_TYPE.classesOnly().collectTypes(TypeToken.this);
return (classes =
FluentIterable.from(collectedTypes)
.filter(TypeFilter.IGNORE_TYPE_VARIABLE_OR_WILDCARD)
.toSet());
} else {
return result;
}
}
示例15: createPublicGroup
import java.util.Set; //导入依赖的package包/类
public Response createPublicGroup(GroupCreateRequest request) {
Set<Long> permissions = request.permissions.stream().
map(permission -> permission.getId()).collect(Collectors.toSet());
Set<Long> roles = request.roles.stream().
map(role -> role.getId()).collect(Collectors.toSet());
String error = validateCreateRequest(request.name, permissions, roles);
if (StringUtils.isNoneEmpty(error)) {
throw new WebApplicationException(
error,
Response.Status.BAD_REQUEST);
}
Group group = new Group(request.name);
return updateOrCreateGroup(group, permissions, roles);
}