下面列出了java.util.HashSet#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Checks whether there is a loop containing s. (This is sufficient since
* there are never transitions to dead states.)
*/
// TODO: not great that this is recursive... in theory a
// large automata could exceed java's stack
private static boolean isFiniteSlow(Automaton a, int s, HashSet<Integer> path) {
path.add(s);
Transition t = new Transition();
int count = a.initTransition(s, t);
for (int i=0;i<count;i++) {
a.getNextTransition(t);
if (path.contains(t.dest) || !isFiniteSlow(a, t.dest, path)) {
return false;
}
}
path.remove(s);
return true;
}
@Override
public void removeRecipe(Iterator<Recipe> it, Recipe recipe) {
System.out.println("REMOVING: " + recipe.getResult().getType().toString());
Iterator<Recipe> recipes = ProRecipes.getPlugin().getServer().recipeIterator();
HashSet<Recipe> storedRecipes = new HashSet<Recipe>();
while(recipes.hasNext()){
storedRecipes.add(recipes.next());
}
storedRecipes.remove(recipe);
ProRecipes.getPlugin().getServer().clearRecipes();
for(Recipe rec : storedRecipes){
ProRecipes.getPlugin().getServer().addRecipe(rec);
}
System.out.println("REMOVED: " + recipe.getResult().getType().toString());
}
/**
* 设置多选时选中的日期
*
* @param day
* @param flag 多选时flag=true代表选中数据,flag=false代表取消选中
* @param position 代表记录viewpager哪一页的数据
*/
public void setChooseDate(int day, boolean flag, int position) {
if (position == -1) {
position = currentPosition;
}
HashSet<Integer> days = chooseDate.get(position);
if (flag) {
if (days == null) {
days = new HashSet<>();
chooseDate.put(position, days);
}
days.add(day);
positions.add(position);
} else {
days.remove(day);
}
}
/**
* This method validate locales by checking if they are available of they contain wrong letter
* case and adding the valid ones in a clean set.
* @param locales to be checked
* @return valid locales
*/
HashSet<Locale> validateLocales(HashSet<Locale> locales) {
mLogger.debug("Validating given locales..");
for (Locale l:LocalesUtils.getPseudoLocales()) {
if(locales.remove(l)) {
mLogger.info("Pseudo locale '" + l + "' has been removed.");
}
}
HashSet<Locale> cleanLocales = new HashSet<>();
Locale[] androidLocales = Locale.getAvailableLocales();
for (Locale locale: locales) {
if (Arrays.asList(androidLocales).contains(locale)) {
cleanLocales.add(locale);
} else {
mLogger.error("Invalid passed locale: " + locale);
mLogger.warn("Invalid specified locale: '" + locale + "', has been discarded");
}
}
mLogger.debug("passing validated locales.");
return cleanLocales;
}
private void resolveGrps (Group g, Component referrer,
HashSet<NsName> visited)
throws BlinkException
{
NsName name = g.getName ();
if (! visited.add (name))
throw recursionError ("group", name, referrer);
for (Field f : g)
resolveGrpsType (f.getType (), f, g, visited);
if (g.hasSuper ())
{
if (! resolveGrpsRef (g.getSuper (), name.getNs (), g, null, g,
visited))
throw refError ("super", g.getSuper (), name.getNs (), g);
}
visited.remove (g.getName ());
}
public void buildPartial(FrameBlock in) {
if( !isApplicable() )
return;
//ensure allocated partial recode map
if( _rcdMapsPart == null )
_rcdMapsPart = new HashMap<>();
//construct partial recode map (tokens w/o codes)
//iterate over columns for sequential access
for( int j=0; j<_colList.length; j++ ) {
int colID = _colList[j]; //1-based
//allocate column map if necessary
if( !_rcdMapsPart.containsKey(colID) )
_rcdMapsPart.put(colID, new HashSet<>());
HashSet<Object> map = _rcdMapsPart.get(colID);
//probe and build column map
for( int i=0; i<in.getNumRows(); i++ )
map.add(in.get(i, colID-1));
//cleanup unnecessary entries once
map.remove(null);
map.remove("");
}
}
protected void _removeOrphanedTransaction(final Transaction transaction) {
_orphanedTransactionSet.remove(transaction);
for (final TransactionInput transactionInput : transaction.getTransactionInputs()) {
final TransactionOutputIdentifier transactionOutputIdentifier = TransactionOutputIdentifier.fromTransactionInput(transactionInput);
final HashSet<Transaction> queuedTransactions = _orphanedTransactions.get(transactionOutputIdentifier);
if (queuedTransactions == null) { continue; }
queuedTransactions.remove(transaction);
if (queuedTransactions.isEmpty()) {
_orphanedTransactions.remove(transactionOutputIdentifier);
}
}
Logger.debug("Purging old orphaned Transaction: " + transaction.getHash() + " (" + _orphanedTransactionSet.size() + " / " + MAX_ORPHANED_TRANSACTION_COUNT + ")");
}
private void clearAgentEntryOnShutdown() {
HashSet<AgentNode> followers = getFollowers();
try {
if (followers.remove(agentNode)) {
updateFollowersListOnZk();
} else {
String leaderJson = new String(curator.getData().forPath(ZKConstants.AGENT_LEADER_PATH), StandardCharsets.UTF_8);
if((leaderJson != null) && !leaderJson.isEmpty() && (GSON.fromJson(leaderJson, AgentNode.class)).equals(agentNode)) {
curator.setData().forPath(ZKConstants.AGENT_LEADER_PATH, "".getBytes());
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
}
}
@Override
public int deleteModelItem(Long modelId, List<Long> itemIds) {
int count = itemIds == null ? 0 : itemIds.size(); //得到要删除的数量
//取出nonDrugIdList 解析并删除所需
DmsNonDrugModel dmsNonDrugModel = dmsNonDrugModelMapper.selectByPrimaryKey(modelId);
HashSet<Long> itemIdSet=toItemIdSet(dmsNonDrugModel.getNonDrugIdList());
if (null != dmsNonDrugModel && !CollectionUtils.isEmpty(itemIdSet) && !CollectionUtils.isEmpty(itemIds)) {
for (Long id : itemIds) {
if( itemIdSet.contains(id)) {
itemIdSet.remove(id);
}
}
}
dmsNonDrugModel=new DmsNonDrugModel();
dmsNonDrugModel.setId(modelId);
dmsNonDrugModel.setNonDrugIdList(toItemIdListStr(new ArrayList<Long>(itemIdSet)));
dmsNonDrugModelMapper.updateByPrimaryKeySelective(dmsNonDrugModel);
return count;
}
/**
* This creates a deep copy of a function program block. The central reference to singletons of function program blocks
* poses the need for explicit copies in order to prevent conflicting writes of temporary variables (see ExternalFunctionProgramBlock.
*
* @param namespace function namespace
* @param oldName ?
* @param pid ?
* @param IDPrefix ?
* @param prog runtime program
* @param fnStack ?
* @param fnCreated ?
* @param plain ?
*/
public static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain)
{
//fpb guaranteed to be non-null (checked inside getFunctionProgramBlock)
FunctionProgramBlock fpb = prog.getFunctionProgramBlock(namespace, oldName);
String fnameNew = (plain)? oldName :(oldName+Lop.CP_CHILD_THREAD+pid);
String fnameNewKey = DMLProgram.constructFunctionKey(namespace,fnameNew);
if( prog.getFunctionProgramBlocks().containsKey(fnameNewKey) )
return; //prevent redundant deep copy if already existent
//create deep copy
FunctionProgramBlock copy = null;
ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
if( fpb.getInputParams()!= null )
tmp1.addAll(fpb.getInputParams());
if( fpb.getOutputParams()!= null )
tmp2.addAll(fpb.getOutputParams());
if( !fnStack.contains(fnameNewKey) ) {
fnStack.add(fnameNewKey);
copy = new FunctionProgramBlock(prog, tmp1, tmp2);
copy.setChildBlocks( rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, fpb.isRecompileOnce()) );
copy.setRecompileOnce( fpb.isRecompileOnce() );
copy.setThreadID(pid);
fnStack.remove(fnameNewKey);
}
else //stop deep copy for recursive function calls
copy = fpb;
//copy.setVariables( (LocalVariableMap) fpb.getVariables() ); //implicit cloning
//note: instructions not used by function program block
//put
prog.addFunctionProgramBlock(namespace, fnameNew, copy);
fnCreated.add(DMLProgram.constructFunctionKey(namespace, fnameNew));
}
@SuppressWarnings("CollectionIncompatibleType")
public static void main(String[] args) {
HashSet<Short> s = new HashSet<>();
for (int i = 0; i < 10; i++) {
// s.add(i);
s.remove(i);
}
System.out.println(s.size());
}
/**
* Subtract the common tables from the tables provided
*/
private Set<String> subtractTable(Collection<String> tables, Collection<String> commonTables) {
HashSet<String> resultOfSubtraction = Sets.newHashSet(tables);
for (String tableToRemove : commonTables) {
resultOfSubtraction.remove(tableToRemove);
}
return resultOfSubtraction;
}
public static HashSet<String> getDisabledSignals(StgModel stg, Signal.Type type) {
HashSet<String> result = new HashSet<>(stg.getSignalReferences(type));
for (SignalTransition signalTransition : stg.getSignalTransitions(type)) {
String signalRef = stg.getSignalReference(signalTransition);
if (stg.isEnabled(signalTransition) || hasPresetDummy(stg, signalTransition)) {
result.remove(signalRef);
}
}
return result;
}
/**
*
* @param m
* @param checked
* <code>true</code> add or <code>false</code> remove
* @since 3.1
*/
public void addOrRemoveExecutiveDoctorWorkingFor(Mandant m, boolean checked){
HashSet<Mandant> hashSet = new HashSet<Mandant>(getExecutiveDoctorsWorkingFor());
if (checked) {
hashSet.add(m);
} else {
hashSet.remove(m);
}
List<String> edList = hashSet.stream().map(p -> p.getLabel()).collect(Collectors.toList());
setExtInfoStoredObjectByKey(FLD_EXTINFO_MANDATORS, edList.isEmpty() ? "" : ts(edList));
}
private void resolveGrpsDef (Define d, Component referrer, Field f,
HashSet<NsName> visited)
throws BlinkException
{
if (! visited.add (d.getName ()))
throw recursionError ("type", d.getName (), referrer);
resolveGrpsType (d.getType (), f, d, visited);
visited.remove (d.getName ());
}
/**
* Determine the custom claims in the set
*
* @param claimNames - the current set of claim names in this token
* @return the possibly empty set of names for non-Claims claims
*/
protected Set<String> filterCustomClaimNames(Collection<String> claimNames) {
HashSet<String> customNames = new HashSet<>(claimNames);
for (Claims claim : Claims.values()) {
customNames.remove(claim.name());
}
return customNames;
}
private void ssaStatements(DirectGraph dgraph, HashSet<String> updated, boolean calcLiveVars) {
for (DirectNode node : dgraph.nodes) {
updated.remove(node.id);
mergeInVarMaps(node, dgraph);
SFormsFastMapDirect varmap = new SFormsFastMapDirect(inVarVersions.get(node.id));
SFormsFastMapDirect[] varmaparr = new SFormsFastMapDirect[]{varmap, null};
if (node.exprents != null) {
for (Exprent expr : node.exprents) {
processExprent(expr, varmaparr, node.statement, calcLiveVars);
}
}
if (varmaparr[1] == null) {
varmaparr[1] = varmaparr[0];
}
// quick solution: 'dummy' field variables should not cross basic block borders (otherwise problems e.g. with finally loops - usage without assignment in a loop)
// For the full solution consider adding a dummy assignment at the entry point of the method
boolean allow_field_propagation = node.succs.isEmpty() || (node.succs.size() == 1 && node.succs.get(0).preds.size() == 1);
if (!allow_field_propagation && varmaparr[0] != null) {
varmaparr[0].removeAllFields();
varmaparr[1].removeAllFields();
}
boolean this_updated = !mapsEqual(varmaparr[0], outVarVersions.get(node.id))
|| (outNegVarVersions.containsKey(node.id) && !mapsEqual(varmaparr[1], outNegVarVersions.get(node.id)));
if (this_updated) {
outVarVersions.put(node.id, varmaparr[0]);
if (dgraph.mapNegIfBranch.containsKey(node.id)) {
outNegVarVersions.put(node.id, varmaparr[1]);
}
for (DirectNode nd : node.succs) {
updated.add(nd.id);
}
}
}
}
@Test
public void simpleTest() {
// HashMap rootObject1 = new HashMap();
// rootObject1.put(2, 2);
// rootObject1.put(3, 3);
// rootObject1.put(4, 4);
// rootObject1.put(1, 1);
// rootObject1.put("new dog", "new dog");
//
// HashMap rootObject2 = new HashMap();
// rootObject2.put(1, 1);
// rootObject2.put(4, 4);
// rootObject2.put("new dog", "new dog");
// rootObject2.put(2, 2);
// rootObject2.put(3, 3);
// Object rootObject1 = new LinkedHashSet(Arrays.asList(2, 3, 4, 1, "new dog"));
// Object rootObject2 = new LinkedHashSet(Arrays.asList(1, 4, "new dog", 2, 3));
// Object rootObject1 = new HashSet(Arrays.asList(2, 3, 4, 1, "new dog"));
// Object rootObject2 = new HashSet(Arrays.asList(1, 4, "new dog", 2, 3));
// Object rootObject1 = new HashSet(Arrays.asList(2, 3, 4, 1, "new dog", 17));
// Object rootObject2 = new HashSet(Arrays.asList(17, 1, 4, "new dog", 2, 3));
HashSet rootObject1 = new HashSet(Arrays.asList(2, 3, 4, 1, "new dog", 17));
HashSet rootObject2 = new HashSet(Arrays.asList(2, 3, 4, 1, "new dog"));
rootObject2.add(17);
rootObject2.add(15);
rootObject2.remove(15);
assertEquals(rootObject2, rootObject2);
System.out.println(ObjectGraphMeasurer.measure(rootObject1));
System.out.println(ObjectGraphMeasurer.measure(rootObject2));
System.out.print("\n\n\n");
System.out.println(ObjectSerializer.measure(rootObject1));
System.out.print("\n\n\n");
System.out.println(ObjectSerializer.measure(rootObject2));
}
public void testGFRecordReaderNHop1Split() throws Exception {
cluster = super.initMiniCluster(CLUSTER_PORT, 1);
int entryCount = 2;
int bucketCount = 3;
HashSet<String> keySet = new HashSet<String>();
for (int j = 0; j < bucketCount; j++) {
HdfsSortedOplogOrganizer bucket = new HdfsSortedOplogOrganizer(
regionManager, j);
ArrayList<TestEvent> items = new ArrayList<TestEvent>();
for (int i = 0; i < entryCount; i++) {
String key = "key - " + j + " : " + i;
items.add(new TestEvent(key, ("value-" + System.nanoTime())));
keySet.add(key);
}
bucket.flush(items.iterator(), entryCount);
}
assertEquals(entryCount * bucketCount, keySet.size());
Configuration conf = hdfsStore.getFileSystem().getConf();
GFInputFormat gfInputFormat = new GFInputFormat();
Job job = Job.getInstance(conf, "test");
conf = job.getConfiguration();
conf.set(GFInputFormat.INPUT_REGION, getName());
conf.set(GFInputFormat.HOME_DIR, testDataDir.getName());
conf.setBoolean(GFInputFormat.CHECKPOINT, false);
List<InputSplit> splits = gfInputFormat.getSplits(job);
assertEquals(1, splits.size());
CombineFileSplit split = (CombineFileSplit) splits.get(0);
assertEquals(bucketCount, split.getNumPaths());
TaskAttemptContext context = new TaskAttemptContextImpl(conf,
new TaskAttemptID());
RecordReader<GFKey, PersistedEventImpl> reader = gfInputFormat
.createRecordReader(split, context);
reader.initialize(split, context);
while (reader.nextKeyValue()) {
keySet.remove(reader.getCurrentKey().getKey());
}
assertEquals(0, keySet.size());
reader.close();
}
private String source(ExecutionContext cx, HashSet<ScriptObject> stack, Object value) {
switch (Type.of(value)) {
case Null:
return "null";
case Boolean:
return Type.booleanValue(value) ? "true" : "false";
case String:
return Strings.quote(Type.stringValue(value).toString());
case Symbol:
return Type.symbolValue(value).toString();
case Number:
return ToFlatString(cx, value);
case BigInt:
return ToFlatString(cx, value) + "n";
case SIMD:
return Type.simdValue(value).toString();
case Object:
ScriptObject objValue = Type.objectValue(value);
if (IsCallable(objValue)) {
return ((Callable) objValue).toSource(cx);
}
if (stack.contains(objValue) || stack.size() > maxStackDepth) {
return "« ... »";
}
stack.add(objValue);
try {
if (objValue instanceof DateObject) {
return DatePrototype.Properties.toString(cx, value).toString();
} else if (objValue instanceof RegExpObject) {
return RegExpPrototype.Properties.toString(cx, value).toString();
} else if (objValue instanceof ArrayObject) {
return arrayToSource(cx, stack, objValue);
} else {
return objectToSource(cx, stack, objValue);
}
} finally {
stack.remove(objValue);
}
case Undefined:
default:
return "(void 0)";
}
}