本文整理汇总了Java中java.util.HashSet类的典型用法代码示例。如果您正苦于以下问题:Java HashSet类的具体用法?Java HashSet怎么用?Java HashSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashSet类属于java.util包,在下文中一共展示了HashSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupDepartments
import java.util.HashSet; //导入依赖的package包/类
public void setupDepartments(EditRoomDeptForm editRoomDeptForm, HttpServletRequest request, Location location) throws Exception {
Collection availableDepts = new Vector();
Collection currentDepts = new HashSet();
Set<Department> departments = Department.getUserDepartments(sessionContext.getUser());
boolean hasControl = false;
for (RoomDept rd: location.getRoomDepts()) {
currentDepts.add(rd.getDepartment());
if (departments.contains(rd.getDepartment()) && rd.isControl())
hasControl = true;
}
Set<Department> set = Department.findAllBeingUsed(location.getSession().getUniqueId());
for (Department d: set) {
if (hasControl || departments.contains(d) || !currentDepts.contains(d))
availableDepts.add(new LabelValueBean(d.getDeptCode() + " - " + d.getName(), d.getUniqueId().toString()));
}
request.setAttribute(Department.DEPT_ATTR_NAME, availableDepts);
}
示例2: logFormRequest
import java.util.HashSet; //导入依赖的package包/类
private void logFormRequest(final Form form) {
if (LOGGER.isDebugEnabled()) {
final Set<String> pairs = new HashSet<String>();
for (final String name : form.getNames()) {
final StringBuilder builder = new StringBuilder();
builder.append(name);
builder.append(": ");
if (!"password".equalsIgnoreCase(name)) {
builder.append(form.getValues(name));
} else {
builder.append("*****");
}
pairs.add(builder.toString());
}
LOGGER.debug(StringUtils.join(pairs, ", "));
}
}
示例3: checkForDuplicateEntries
import java.util.HashSet; //导入依赖的package包/类
/**
* Returns the set of entry names and reports any duplicate entry names in the {@code result}
* as errors.
*/
private static Set<String> checkForDuplicateEntries(
List<CentralDirectoryRecord> cdRecords, Result result) {
Set<String> cdEntryNames = new HashSet<>(cdRecords.size());
Set<String> duplicateCdEntryNames = null;
for (CentralDirectoryRecord cdRecord : cdRecords) {
String entryName = cdRecord.getName();
if (!cdEntryNames.add(entryName)) {
// This is an error. Report this once per duplicate name.
if (duplicateCdEntryNames == null) {
duplicateCdEntryNames = new HashSet<>();
}
if (duplicateCdEntryNames.add(entryName)) {
result.addError(Issue.JAR_SIG_DUPLICATE_ZIP_ENTRY, entryName);
}
}
}
return cdEntryNames;
}
示例4: getItemTypes
import java.util.HashSet; //导入依赖的package包/类
@Override
@RequestMapping(value = ApiConfig.ITEM_TYPE + "/{providerType}", method = RequestMethod.GET,
headers = ApiConfig.API_HEADERS, produces = {ApiConfig.API_PRODUCES})
@ResponseBody
public ItemTypeList getItemTypes(@PathVariable final String providerType,
@CookieValue(value = SessionManager.SESSION_COOKIE, required = false) final String sessionId,
final HttpServletResponse response) {
if (rateLimiter.tryAcquire()) {
modelValidator.validateProviderType(providerType);
sessionManager.getSession(sessionId, response);
if (LOG.isDebugEnabled()) {
LOG.debug("Get all itemTypes for a provider type");
}
return new ItemTypeList(new HashSet<>(itemTypeManager.getItemTypes(providerType)));
} else {
throw new ApiThrottlingException("Exceeded max number of requests per second");
}
}
示例5: computeParentVertices
import java.util.HashSet; //导入依赖的package包/类
/**
*
* @param v
* @return
*/
private Set<Vertex> computeParentVertices(Vertex v) {
HashSet<Vertex> parentVertices = new HashSet<Vertex>();
Edge reverseEdge = reverseEdges.get(v);
Vertex currentVertex = v;
while (reverseEdge != null) {
Vertex parentVertex = reverseEdge.getOppositeVertex(currentVertex);
parentVertices.add(parentVertex);
currentVertex = parentVertex;
reverseEdge = reverseEdges.get(currentVertex);
}
return parentVertices;
}
示例6: ConfusionMatrix
import java.util.HashSet; //导入依赖的package包/类
public ConfusionMatrix(int[] truth, int[] prediction) {
if(truth.length != prediction.length){
throw new IllegalArgumentException(String.format("The vector sizes don't match: %d != %d.", truth.length, prediction.length));
}
Set<Integer> ySet = new HashSet<>();
for(int i = 0; i < truth.length; i++){
ySet.add(truth[i]);
}
matrix = new int[ySet.size()][ySet.size()];
for(int i = 0; i < truth.length; i++){
matrix[truth[i]][prediction[i]] += 1;
}
ySet.clear();
}
示例7: testRenameUnversionedFile_FO
import java.util.HashSet; //导入依赖的package包/类
public void testRenameUnversionedFile_FO() throws Exception {
// init
File fromFile = new File(repositoryLocation, "fromFile");
fromFile.createNewFile();
File toFile = new File(repositoryLocation, "toFile");
// rename
h.setFilesToRefresh(new HashSet<File>(Arrays.asList(fromFile, toFile)));
renameFO(fromFile, toFile);
assertTrue(h.waitForFilesToRefresh());
// test
assertFalse(fromFile.exists());
assertTrue(toFile.exists());
assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fromFile).getStatus());
assertEquals(EnumSet.of(Status.NEW_INDEX_WORKING_TREE, Status.NEW_HEAD_WORKING_TREE), getCache().getStatus(toFile).getStatus());
}
示例8: testGenerateCandidates
import java.util.HashSet; //导入依赖的package包/类
/**
* testGenerateCandidates
*/
public void testGenerateCandidates() throws Exception {
Table catalog_tbl = this.getTable(TM1Constants.TABLENAME_SUBSCRIBER);
Column target_col = this.getColumn(catalog_tbl, "S_ID");
Collection<VerticalPartitionColumn> candidates = VerticalPartitionerUtil.generateCandidates(target_col, info.stats);
assertNotNull(candidates);
assertFalse(candidates.isEmpty());
VerticalPartitionColumn vpc = CollectionUtil.first(candidates);
assertNotNull(vpc);
Collection<Column> expected_cols = CollectionUtil.addAll(new HashSet<Column>(), this.getColumn(catalog_tbl, "SUB_NBR"),
this.getColumn(catalog_tbl, "S_ID"));
assertEquals(expected_cols.size(), vpc.getVerticalMultiColumn().size());
assertTrue(expected_cols + " <=> " + vpc.getVerticalPartitionColumns(), expected_cols.containsAll(vpc.getVerticalPartitionColumns()));
Collection<Statement> expected_stmts = new HashSet<Statement>();
expected_stmts.add(this.getStatement(this.getProcedure(DeleteCallForwarding.class), "query"));
expected_stmts.add(this.getStatement(this.getProcedure(InsertCallForwarding.class), "query1"));
expected_stmts.add(this.getStatement(this.getProcedure(UpdateLocation.class), "getSubscriber"));
assertEquals(expected_stmts.size(), vpc.getOptimizedQueries().size());
assert(expected_stmts.containsAll(vpc.getOptimizedQueries()));
}
示例9: parse
import java.util.HashSet; //导入依赖的package包/类
/**
* Parse string according given class
* @param string Source string
* @param clazz Target class
* @return Parsed class object
*/
private static Object parse(String string, Class clazz) throws IOException {
if (Integer.class.isAssignableFrom(clazz)) {
return (int) Double.parseDouble(string);
}
if (Boolean.class.isAssignableFrom(clazz)) {
return Boolean.parseBoolean(string);
}
if (Double.class.isAssignableFrom(clazz)) {
return Double.parseDouble(string);
}
if (HashSet.class.isAssignableFrom(clazz)) {
return Utils.toHashSet(Utils.tokenize(string, ","));
}
if (File.class.isAssignableFrom(clazz)) {
return new File(string);
}
throw new IOException("Unknown instance: " + clazz.getSimpleName());
}
示例10: testDeleteA_RenameB2A_DO_129805
import java.util.HashSet; //导入依赖的package包/类
public void testDeleteA_RenameB2A_DO_129805() throws Exception {
// init
File fileA = new File(repositoryLocation, "A");
fileA.createNewFile();
File fileB = new File(repositoryLocation, "B");
fileB.createNewFile();
add();
commit();
// delete A
h.setFilesToRefresh(new HashSet<File>(Arrays.asList(fileA, fileB)));
delete(fileA);
// rename B to A
renameDO(fileB, fileA);
assertTrue(h.waitForFilesToRefresh());
// test
assertFalse(fileB.exists());
assertTrue(fileA.exists());
assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fileA).getStatus());
}
示例11: getFactories
import java.util.HashSet; //导入依赖的package包/类
private static Set<Object> getFactories(String serviceName) {
HashSet<Object> result = new HashSet<Object>();
if ((serviceName == null) || (serviceName.length() == 0) ||
(serviceName.endsWith("."))) {
return result;
}
Provider[] provs = Security.getProviders();
Object fac;
for (Provider p : provs) {
Iterator<Service> iter = p.getServices().iterator();
while (iter.hasNext()) {
Service s = iter.next();
if (s.getType().equals(serviceName)) {
try {
fac = loadFactory(s);
if (fac != null) {
result.add(fac);
}
} catch (Exception ignore) {
}
}
}
}
return Collections.unmodifiableSet(result);
}
示例12: doConsume
import java.util.HashSet; //导入依赖的package包/类
private void doConsume() {
try {
consumer.seekToEnd(new HashSet<TopicPartition>());
while (!stopped) {
final ConsumerRecords<String, byte[]> records = consumer.poll(10);
for (final ConsumerRecord<String, byte[]> record : records) {
recordSet.add(record);
LOG.info("Reading record: topic = {}, partition = {}, offset = {}, key = {}, value = {}", record.topic(), record.partition(),
record.offset(), record.key(), new String(record.value()));
}
consumer.commitSync();
Thread.sleep(10);
}
} catch (final InterruptedException e) {
LOG.error("interrupted", e);
} finally {
consumer.close();
consumer.unsubscribe();
consumer = null;
}
}
示例13: registerTopic
import java.util.HashSet; //导入依赖的package包/类
public static void registerTopic(ChannelEntity chn, String topic) {
if (chn == null) {
return;
}
if (topic == null) {
return;
}
Set<String> topicSet = channelTopicMap.get(chn);
if (topicSet == null) {
topicSet = new HashSet<String>(1);
}
topicSet.add(topic);
channelTopicMap.put(chn, topicSet);
Set<ChannelEntity> channelSet = topicChannelMap.get(topic);
if (channelSet == null) {
channelSet = new HashSet<ChannelEntity>(1);
}
channelSet.add(chn);
topicChannelMap.put(topic, channelSet);
}
示例14: initDebuggerManagerListeners
import java.util.HashSet; //导入依赖的package包/类
private void initDebuggerManagerListeners () {
synchronized (loadedListenersLock) {
if (loadedListeners == null) {
loadedListeners = new HashSet<LazyDebuggerManagerListener>();
listenersLookupList = lookup.lookup (null, LazyDebuggerManagerListener.class);
refreshDebuggerManagerListeners(listenersLookupList);
((Customizer) listenersLookupList).addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
refreshDebuggerManagerListeners((List<? extends LazyDebuggerManagerListener>) evt.getSource());
}
});
}
}
}
示例15: reconfigure
import java.util.HashSet; //导入依赖的package包/类
/**
* Apply Bundle matched properties.
*/
public static CloudIotOptions reconfigure(CloudIotOptions original, Bundle bundle) {
try {
if (Log.isLoggable(TAG, Log.INFO)) {
HashSet<String> valid = new HashSet<>(Arrays.asList(new String[] {"project_id",
"registry_id", "device_id","cloud_region", "mqtt_bridge_hostname",
"mqtt_bridge_port"}));
valid.retainAll(bundle.keySet());
Log.i(TAG, "Configuring options using the following intent extras: " + valid);
}
CloudIotOptions result = new CloudIotOptions();
result.projectId = bundle.getString("project_id", original.projectId);
result.registryId = bundle.getString("registry_id", original.registryId);
result.deviceId = bundle.getString("device_id", original.deviceId);
result.cloudRegion = bundle.getString("cloud_region", original.cloudRegion);
result.bridgeHostname = bundle.getString("mqtt_bridge_hostname",
original.bridgeHostname);
result.bridgePort = (short) bundle.getInt("mqtt_bridge_port", original.bridgePort);
return result;
} catch (Exception e) {
throw new IllegalArgumentException("While processing configuration options", e);
}
}