Java Code Examples for java.util.HashSet#remove()

The following examples show how to use java.util.HashSet#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DmsNonDrugModelServiceImpl.java    From HIS with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: AutomatonTestUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: AgentLeaderElector.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
	}
}
 
Example 4
Source File: OrphanedTransactionsCache.java    From bitcoin-verde with MIT License 6 votes vote down vote up
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 + ")");
}
 
Example 5
Source File: EncoderRecode.java    From systemds with Apache License 2.0 6 votes vote down vote up
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("");
	}
}
 
Example 6
Source File: NBTChecker_v1_12_R1.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
@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());
	
}
 
Example 7
Source File: Schema.java    From jblink with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 ());
}
 
Example 8
Source File: LocalesDetector.java    From rosetta with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: CalendarView.java    From CalendarView with Apache License 2.0 6 votes vote down vote up
/**
 * 设置多选时选中的日期
 *
 * @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);
    }
}
 
Example 10
Source File: Anwender.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @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));
}
 
Example 11
Source File: DefaultJWTCallerPrincipal.java    From smallrye-jwt with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: Schema.java    From jblink with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 ());
}
 
Example 13
Source File: EnablednessUtils.java    From workcraft with MIT License 5 votes vote down vote up
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;
}
 
Example 14
Source File: DataSetHomology.java    From morf with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: ShortSet.java    From JavaSCR with MIT License 5 votes vote down vote up
@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());
	}
 
Example 16
Source File: ProgramConverter.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 17
Source File: SSAUConstructorSparseEx.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
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);
                }
            }
        }
    }
 
Example 18
Source File: SourceBuilder.java    From es6draft with MIT License 4 votes vote down vote up
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)";
    }
}
 
Example 19
Source File: GFRecordReaderJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 20
Source File: ObjectSerializerTest.java    From memory-measurer with Apache License 2.0 4 votes vote down vote up
@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));
	}