下面列出了java.util.HashSet#removeAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Parse the dc string argument and return a map of dc -> DcZkInfo for every datacenter that is enabled.
* @param dcs the string argument for dcs.
* @param zkLayoutPath the path to the zkLayout file.
* @return a map of dc -> {@link com.github.ambry.clustermap.ClusterMapUtils.DcZkInfo} for every enabled dc.
* @throws IOException if there is an IO error reading the zkLayout file.
*/
static Map<String, ClusterMapUtils.DcZkInfo> parseAndUpdateDcInfoFromArg(String dcs, String zkLayoutPath)
throws IOException {
Map<String, ClusterMapUtils.DcZkInfo> dataCenterToZkAddress =
ClusterMapUtils.parseDcJsonAndPopulateDcInfo(Utils.readStringFromFile(zkLayoutPath));
// nothing to do for cloud datacenters in the tool.
dataCenterToZkAddress.values().removeIf(dcZkInfo -> dcZkInfo.getReplicaType() == ReplicaType.CLOUD_BACKED);
Set<String> parsedDcSet;
if (Utils.isNullOrEmpty(dcs)) {
throw new IllegalArgumentException("dcs string cannot be null or empty.");
}
if (dcs.equalsIgnoreCase(ALL)) {
parsedDcSet = new HashSet<>(dataCenterToZkAddress.keySet());
} else {
parsedDcSet = Arrays.stream(dcs.replaceAll("\\p{Space}", "").split(",")).collect(Collectors.toSet());
HashSet<String> diff = new HashSet<>(parsedDcSet);
diff.removeAll(dataCenterToZkAddress.keySet());
if (!diff.isEmpty()) {
throw new IllegalArgumentException("Unknown datacenter(s) supplied" + diff);
}
}
dataCenterToZkAddress.entrySet().removeIf(e -> !parsedDcSet.contains(e.getKey()));
return dataCenterToZkAddress;
}
public synchronized static void resetCSG(DatFile df, boolean useLowQuality) {
df.setOptimizingCSG(true);
if (useLowQuality) {
quality = 12;
} else {
quality = 16;
}
HashSet<GDataCSG> ref = new HashSet<GDataCSG>(registeredData.putIfAbsent(df, new HashSet<GDataCSG>()));
ref.removeAll(parsedData.putIfAbsent(df, new HashSet<GDataCSG>()));
clearPolygonCache.putIfAbsent(df, true);
fullClearPolygonCache.putIfAbsent(df, true);
deleteAndRecompile = !ref.isEmpty();
if (deleteAndRecompile) {
globalExtruderConfig.put(df, new PathTruderSettings());
registeredData.get(df).clear();
registeredData.get(df).add(null);
linkedCSG.putIfAbsent(df, new HashMap<String, CSG>()).clear();
idToGDataCSG.putIfAbsent(df, new HashBiMap<Integer, GDataCSG>()).clear();
}
parsedData.get(df).clear();
}
/** check if some result covers some nugger
* @param result the result String
* @param nugget the nugget string
* @return the tokens of the specified nugget String not contained in the specified result String
*/
private String[] covers(String result, String nugget) {
String[] rTokens = NETagger.tokenize(result);
HashSet<String> rSet = new HashSet<String>();
for (String r : rTokens)
if (!FunctionWords.lookup(r) && (r.length() > 1))
rSet.add(SnowballStemmer.stem(r).toLowerCase());
String[] nTokens = NETagger.tokenize(nugget);
HashSet<String> nSet = new HashSet<String>();
for (String n : nTokens)
if (!FunctionWords.lookup(n) && (n.length() > 1))
nSet.add(SnowballStemmer.stem(n).toLowerCase());
nSet.removeAll(rSet);
ArrayList<String> remaining = new ArrayList<String>(nSet);
return remaining.toArray(new String[remaining.size()]);
}
private void checkSearchedMembers(Set<String> pids, Map<String, Item> memberSearchMap) throws RestException {
if (!pids.equals(memberSearchMap.keySet())) {
HashSet<String> notMembers = new HashSet<String>(pids);
notMembers.removeAll(memberSearchMap.keySet());
HashSet<String> missingPids = new HashSet<String>(memberSearchMap.keySet());
missingPids.removeAll(pids);
throw RestException.plainNotFound(DigitalObjectResourceApi.MEMBERS_ITEM_PID,
"Not member PIDs: " + notMembers.toString()
+ "\nMissing PIDs: " + missingPids.toString());
}
}
/**
* Return a set of all elements that have been added since the last call
* to {@link #sync()}
* @return the elements that were added since the last call to {@link #sync()}
*/
public Set<RhnSetElement> getAdded() {
if (synced == null) {
throw new IllegalStateException("The set must be marked first");
}
HashSet<RhnSetElement> result = new HashSet<RhnSetElement>(elements);
result.removeAll(synced);
return Collections.unmodifiableSet(result);
}
private HashSet<State> checkReversibility(final Fsm fsm) {
State initialState = fsm.getInitialState();
HashSet<State> forwardStates = getForwardReachableStates(fsm, initialState);
HashSet<State> backwardStates = getBackwardReachableStates(fsm, initialState);
HashSet<State> ireversibleStates = new HashSet<>(forwardStates);
ireversibleStates.removeAll(backwardStates);
return ireversibleStates;
}
@Nonnull
public static Set<String> getMacroNames(Element root, @Nullable PathMacroFilter filter, @Nonnull final PathMacros pathMacros) {
final PathMacrosCollectorImpl collector = new PathMacrosCollectorImpl();
collector.substitute(root, true, false, filter);
final HashSet<String> result = new HashSet<String>(collector.myMacroMap.keySet());
result.removeAll(pathMacros.getSystemMacroNames());
result.removeAll(pathMacros.getLegacyMacroNames());
for (Macro macro : MacroManager.getInstance().getMacros()) {
result.remove(macro.getName());
}
result.removeAll(MacroManager.getInstance().getMacros());
result.removeAll(pathMacros.getIgnoredMacroNames());
return result;
}
public static boolean isExitComponent(List<Statement> lst) {
HashSet<Statement> set = new HashSet<>();
for (Statement stat : lst) {
set.addAll(stat.getNeighbours(StatEdge.TYPE_REGULAR, Statement.DIRECTION_FORWARD));
}
set.removeAll(lst);
return (set.size() == 0);
}
private static Set<FunctionDesc> unmatchedAggregations(Collection<FunctionDesc> aggregations, CubeInstance cube) {
HashSet<FunctionDesc> result = Sets.newHashSet(aggregations);
CubeDesc cubeDesc = cube.getDescriptor();
List<FunctionDesc> definedFuncs = cubeDesc.listAllFunctions();
// check normal aggregations
result.removeAll(definedFuncs);
// check dynamic aggregations
Iterator<FunctionDesc> funcIterator = result.iterator();
while (funcIterator.hasNext()) {
FunctionDesc entry = funcIterator.next();
if (entry instanceof DynamicFunctionDesc) {
DynamicFunctionDesc dynFunc = (DynamicFunctionDesc) entry;
// Filter columns cannot be derived
Collection<TblColRef> definedCols = dynFunc.ifFriendlyForDerivedFilter()
? cubeDesc.listDimensionColumnsIncludingDerived()
: cubeDesc.listDimensionColumnsExcludingDerived(true);
Set<TblColRef> filterCols = Sets.newHashSet(dynFunc.getRuntimeDimensions());
filterCols.removeAll(definedCols);
if (!filterCols.isEmpty()) {
continue;
}
// All inner funcs should be defined
Set<FunctionDesc> innerFuncSet = Sets.newHashSet(dynFunc.getRuntimeFuncMap().values());
innerFuncSet.removeAll(definedFuncs);
if (!innerFuncSet.isEmpty()) {
continue;
}
funcIterator.remove();
}
}
return result;
}
@Override
public void run() {
int selectedCount = getSelectedCount();
if (selectedCount > 0) {
// Build list of all selected ids that are still present.
List<Long> selectedIds = new ArrayList<>(selectedCount);
for (int i = 0; i < mAdapter.getItemCount(); i++) {
long id = mAdapter.getItemId(i);
if (isSelected(id)) {
selectedIds.add(id);
}
}
// Build set of missing ids.
HashSet<Long> missingIds = new HashSet<>(selectedCount);
for (long previouslySelectedId : getSelectedIds()) {
missingIds.add(previouslySelectedId);
}
missingIds.removeAll(selectedIds);
// Unselect all missing ids.
mNotifyItemChanges = false;
for (Long missingId : missingIds) {
setSelected(missingId, false);
}
mNotifyItemChanges = true;
}
}
/**
* Process the Dataset in chunks, as defined by the <code>spanType</code> parameter.
* The Spans denoted by spanType must each contain Words belonging to a single sentence.
*
*/
@Override
public void validatedProcess(Dataset dataset, String spanTypeOfSentenceUnit){
// if (dataset.getPerformedNLPTasks().contains(getTask())){
// Framework.error("This dataset has already been tagged with POS.");
// return;
// }
//check if prerequisites are satisfied
if (!dataset.getPerformedNLPTasks().containsAll(prerequisites)){
HashSet<NLPTask> missingTasks = new HashSet<>();
missingTasks.addAll(prerequisites);
missingTasks.removeAll(dataset.getPerformedNLPTasks());
Framework.error("This dataset does not meet the requirements to use this component! Missing tasks: " + missingTasks);
return;
}
Properties prop1 = new Properties();
prop1.setProperty("annotators", "pos");
StanfordCoreNLP pipeline = new StanfordCoreNLP(prop1, false);
for (Span span : dataset.getSpans(spanTypeOfSentenceUnit)){
HashMap<Integer, Word> wordIndex = new HashMap<>();
Annotation a = CoreNLPHelper.reconstructStanfordAnnotations(span, wordIndex);
if (a == null){
System.out.println(a);
}
pipeline.annotate(a);
List<CoreMap> sentenceAnnotations = a.get(SentencesAnnotation.class);
for (CoreMap sentence : sentenceAnnotations){
for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
Word w = wordIndex.get(token.get(CharacterOffsetBeginAnnotation.class));
String tempPos = token.get(PartOfSpeechAnnotation.class);
if (w.hasAnnotation("URI")){
w.putAnnotation("pos", "NNP");
} else {
w.putAnnotation("pos", tempPos);
}
// System.out.println(w.getAnnotations());
}
}
}
}
protected void rFindAndUnfoldRecursiveFunction( OptNode n, ParForProgramBlock parfor, HashSet<ParForProgramBlock> recPBs, LocalVariableMap vars )
{
//unfold if found
if( n.getNodeType() == NodeType.FUNCCALL && n.isRecursive())
{
boolean exists = rContainsNode(n, parfor);
if( exists )
{
String fnameKey = n.getParam(ParamType.OPSTRING);
String[] names = fnameKey.split(Program.KEY_DELIM);
String fnamespace = names[0];
String fname = names[1];
String fnameNew = FUNCTION_UNFOLD_NAMEPREFIX + fname;
//unfold function
FunctionOp fop = (FunctionOp) OptTreeConverter.getAbstractPlanMapping().getMappedHop(n.getID());
Program prog = parfor.getProgram();
DMLProgram dmlprog = parfor.getStatementBlock().getDMLProg();
FunctionProgramBlock fpb = prog.getFunctionProgramBlock(fnamespace, fname);
FunctionProgramBlock copyfpb = ProgramConverter.createDeepCopyFunctionProgramBlock(fpb, new HashSet<String>(), new HashSet<String>());
prog.addFunctionProgramBlock(fnamespace, fnameNew, copyfpb);
dmlprog.addFunctionStatementBlock(fnamespace, fnameNew, (FunctionStatementBlock)copyfpb.getStatementBlock());
//replace function names in old subtree (link to new function)
rReplaceFunctionNames(n, fname, fnameNew);
//recreate sub opttree
String fnameNewKey = fnamespace + Program.KEY_DELIM + fnameNew;
OptNode nNew = new OptNode(NodeType.FUNCCALL);
OptTreeConverter.getAbstractPlanMapping().putHopMapping(fop, nNew);
nNew.setExecType(ExecType.CP);
nNew.addParam(ParamType.OPSTRING, fnameNewKey);
long parentID = OptTreeConverter.getAbstractPlanMapping().getMappedParentID(n.getID());
OptTreeConverter.getAbstractPlanMapping().getOptNode(parentID).exchangeChild(n, nNew);
HashSet<String> memo = new HashSet<>();
memo.add(fnameKey); //required if functionop not shared (because not replaced yet)
memo.add(fnameNewKey); //requied if functionop shared (indirectly replaced)
for( int i=0; i<copyfpb.getChildBlocks().size() /*&& i<len*/; i++ )
{
ProgramBlock lpb = copyfpb.getChildBlocks().get(i);
StatementBlock lsb = lpb.getStatementBlock();
nNew.addChild( OptTreeConverter.rCreateAbstractOptNode(lsb,lpb,vars,false, memo) );
}
//compute delta for recPB set (use for removing parfor)
recPBs.removeAll( rGetAllParForPBs(n, new HashSet<ParForProgramBlock>()) );
recPBs.addAll( rGetAllParForPBs(nNew, new HashSet<ParForProgramBlock>()) );
//replace function names in new subtree (recursive link to new function)
rReplaceFunctionNames(nNew, fname, fnameNew);
}
//else, we can return anyway because we will not find that parfor
return;
}
//recursive invocation (only for non-recursive functions)
if( !n.isLeaf() )
for( OptNode c : n.getChilds() )
rFindAndUnfoldRecursiveFunction(c, parfor, recPBs, vars);
}
public void showOnly(final Set<Integer> nodes) {
HashSet<Integer> allNodes = new HashSet<Integer>(getModel().getGraphToView().getGroup().getAllNodes());
allNodes.removeAll(nodes);
updateHiddenNodes(allNodes, true);
}
/**
* Do a simple erosion.
*
* @param validList will be updated after erosion
* @param arrayToErode eroded array.
* @param buffer temporary buffer, same size of the arrayToErode.
* @param skip quality skip 1/skip values.
* @param invalidValue value to fill the invalid states
* @param size size of the arrayToErode
*/
public static void erodePoints2(HashSet<Integer> validList,
byte[] arrayToErode,
byte[] buffer,
int skip, byte invalidValue,
WithSize size) {
Arrays.fill(buffer, invalidValue);
ArrayList<Integer> toRemove = new ArrayList<>();
for (Integer idx : validList) {
int sum = 0;
int x = idx % size.getWidth();
int y = idx / size.getWidth();
byte value = arrayToErode[idx];
// for (int j = y * size.getWidth() - skip; j <= y * size.getWidth() + skip; j += size.getWidth() * skip) {
// for (int i = x - skip; i <= x + skip; i += skip) {
for (int j = -skip; j <= skip; j += skip) {
for (int i = -skip; i <= skip; i += skip) {
if (x + i >= 0 && x + i < size.getWidth()
&& j + y >= 0 && j + y < size.getHeight()) {
int currentIdx = (x + i) + (j + y) * size.getWidth();
sum += arrayToErode[currentIdx] == value ? 1 : 0;
}
}
}
if (sum <= 8) {
buffer[idx] = invalidValue;
toRemove.add(idx);
} else {
buffer[idx] = value;
}
}
validList.removeAll(toRemove);
System.arraycopy(buffer, 0, arrayToErode, 0, arrayToErode.length);
// erodePoints(depthData.validPointsMask);
}
@Override
public Set<Connector> getAvailableConnectors(Set<? extends Connector> existingConnections, boolean isOutput) {
HashSet<Connector> filteredConnectors = new HashSet<>(getAllConnectors());
filteredConnectors.removeAll(existingConnections);
return filteredConnectors;
}
/**
* Get Set of pass members which haven't been assigned a position in the
* pass.
*/
public Set<DetectorFactory> getUnpositionedMembers() {
HashSet<DetectorFactory> result = new HashSet<>(memberSet);
result.removeAll(orderedFactoryList);
return result;
}
/** Generare a normalized score.
*
*/
//TODO divide by passage length containing the matches, not the full passage length
public double scorePassage(Phrase q, Answer a, Passage p) {
boolean verbose = true;
// Tokenize the text, necessary for simple and NLP searches
List<List<String>> ca_sentences = tokenizeParagraph(a.text);
List<List<String>> q_sentences = tokenizeParagraph(q.text);
List<List<String>> passage_sentences = tokenizeParagraph(p.text);
// Run NLP on the question and candidate answer
List<Parse> ca_children = getAllChildren(parseParagraph(ca_sentences));
List<Parse> q_children = getAllChildren(parseParagraph(q_sentences));
List<Parse> p_children = new ArrayList<>();
// Speedup: Look for these tokens before running NLP
HashSet<String> target_tokens = flatten(ca_sentences);
//target_tokens.addAll(flatten(q_sentences));
// Free stop filtering (costs no more than what we were
// already doing)
target_tokens.removeAll(Arrays.asList(new String[]{
"i", "me", "you", "he", "she", "him", "they", "them",
"his", "her", "hers", "my", "mine", "your", "yours", "their", "theirs",
"of", "a", "the",
"and", "or", "not", "but",
"this", "that", "these", "those",
"on", "in", "from", "to", "over", "under", "with", "by", "for",
"without", "beside", "between",
"has", "have", "had", "will", "would", "gets", "get", "got",
"be", "am", "been", "was", "were", "being", "is",
".", ",", ":", ";", "[", "{", "}", "]", "(", ")", "<", ">",
"?", "/", "\\", "-", "_", "=", "+", "~", "`", "@", "#", "$",
"%", "^", "&", "*"
}));
for (List<String> sentence : passage_sentences) {
// Does it have the right tokens?
for (String word : sentence) {
if (target_tokens.contains(word.toLowerCase())) {
// Found a common word. Now compare the sentences.
p_children.addAll(getAllChildren(parseSentence(sentence)));
break;
}
}
}
double q_score = compareParseChunks(
q_children,
p_children,
verbose);
double ca_score = compareParseChunks(
ca_children,
p_children,
verbose);
return q_score*ca_score/p.text.length();
}
public void showOnly(final Set<Integer> nodes) {
HashSet<Integer> allNodes = new HashSet<Integer>(getModel().getGraphToView().getGroup().getAllNodes());
allNodes.removeAll(nodes);
updateHiddenNodes(allNodes, true);
}
/**
* Returns the maximally specific superinterface methods
* of a given method signature.
*
* @param classFile a {@link ClassFile}.
* @param methodSignature the {@link Signature} of a method declared in {@code classFile}.
* Only the name and the descriptor are considered.
* @param nonAbstract a {@code boolean}.
* @return a {@link Set}{@code <}{@link ClassFile}{@code >} of classes containing maximally-specific
* superinterface methods of {@code classFile}
* for {@code methodSignature.}{@link Signature#getDescriptor() getDescriptor()}
* and {@code methodSignature.}{@link Signature#getName() getName()},
* as for JVMS v8, section 5.4.3.3. If {@code nonAbstract == true}, such set
* contains all and only the maximally-specific superinterface methods that are
* not abstract. If {@code nonAbstract == false}, it contains exactly all the
* maximally-specific superinterface methods.
*/
private Set<ClassFile> maximallySpecificSuperinterfaceMethods(ClassFile classFile, Signature methodSignature, boolean nonAbstract) {
final HashSet<ClassFile> maximalSet = new HashSet<>();
final HashSet<ClassFile> nextSet = new HashSet<>();
final HashSet<ClassFile> dominatedSet = new HashSet<>();
//initializes next with all the superinterfaces of methodSignature's class
nextSet.addAll(classFile.getSuperInterfaces());
while (!nextSet.isEmpty()) {
//picks a superinterface from the next set
final ClassFile superinterface = nextSet.iterator().next();
nextSet.remove(superinterface);
//determine all the (strict) superinterfaces of the superinterface
final Set<ClassFile> superinterfaceSuperinterfaces =
stream(superinterface.superinterfaces())
.collect(Collectors.toSet());
superinterfaceSuperinterfaces.remove(superinterface);
//look for a method declaration of methodSignature in the superinterface
try {
if (superinterface.hasMethodDeclaration(methodSignature) && !superinterface.isMethodPrivate(methodSignature) && !superinterface.isMethodStatic(methodSignature)) {
//method declaration found: add the superinterface
//to maximalSet...
maximalSet.add(superinterface);
//...remove the superinterface's strict superinterfaces
//from maximalSet, and add them to dominatedSet
maximalSet.removeAll(superinterfaceSuperinterfaces);
dominatedSet.addAll(superinterfaceSuperinterfaces);
} else if (!dominatedSet.contains(superinterface)) {
//no method declaration: add to nextSet all the direct
//superinterfaces of the superinterface that are not
//dominated; skips this step if the superinterface is
//itself dominated
nextSet.addAll(superinterface.getSuperInterfaces());
nextSet.removeAll(dominatedSet);
}
} catch (MethodNotFoundException e) {
//this should never happen
throw new UnexpectedInternalException(e);
}
}
return maximalSet;
}
public void showOnly(final Set<Integer> nodes) {
HashSet<Integer> allNodes = new HashSet<Integer>(getModel().getGraphToView().getGroup().getAllNodes());
allNodes.removeAll(nodes);
updateHiddenNodes(allNodes, true);
}