下面列出了java.util.BitSet#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Determine if this set is an (improper) superset of another.
*
* @param source the set we are testing for.
* @param destination the set we are testing against.
* @return source is a superset of destination, yes then return true else
* false
* @throws CDKException
*/
public static boolean isSuperSet(BitSet source, BitSet destination) throws CDKException {
boolean flag = false;
if (source.cardinality() >= destination.cardinality()) {
not_null(source);
/* make a copy of the source set */
BitSet copy_other = (BitSet) source.clone();
/* and or in */
copy_other.and(destination);
/* if it hasn't changed, we were a subset */
flag = copy_other.equals(destination);
// flag = copy_other.equals(destination);
}
return flag;
}
protected void filterGeneralizations(BitSet lhs, int rhs, int currentLhsAttr, BitSet currentLhs) {
if (currentLhs.equals(lhs))
return;
this.rhsFds.clear(rhs);
// Is the dependency already read and we have not yet found a generalization?
if (currentLhsAttr < 0)
return;
if (this.children != null) {
for (int nextLhsAttr = lhs.nextSetBit(currentLhsAttr); nextLhsAttr >= 0; nextLhsAttr = lhs.nextSetBit(nextLhsAttr + 1)) {
if ((this.children[nextLhsAttr] != null) && (this.children[nextLhsAttr].hasRhsAttribute(rhs))) {
currentLhs.set(nextLhsAttr);
this.children[nextLhsAttr].filterGeneralizations(lhs, rhs, lhs.nextSetBit(nextLhsAttr + 1), currentLhs);
currentLhs.clear(nextLhsAttr);
}
}
}
}
/**
* Add an OzoneAcl to existing list of OzoneAcls.
* @param existingAcls
* @param acl
* @return true if current OzoneAcls are changed, false otherwise.
*/
public static boolean addAcl(List<OzoneAcl> existingAcls, OzoneAcl acl) {
if (existingAcls == null || acl == null) {
return false;
}
for (OzoneAcl a: existingAcls) {
if (a.getName().equals(acl.getName()) &&
a.getType().equals(acl.getType()) &&
a.getAclScope().equals(acl.getAclScope())) {
BitSet current = a.getAclBitSet();
BitSet original = (BitSet) current.clone();
current.or(acl.getAclBitSet());
if (current.equals(original)) {
return false;
}
return true;
}
}
existingAcls.add(acl);
return true;
}
/**
* remove OzoneAcl from existing list of OzoneAcls.
* @param existingAcls
* @param acl
* @return true if current OzoneAcls are changed, false otherwise.
*/
public static boolean removeAcl(List<OzoneAcl> existingAcls, OzoneAcl acl) {
if (existingAcls == null || existingAcls.isEmpty() || acl == null) {
return false;
}
for (OzoneAcl a: existingAcls) {
if (a.getName().equals(acl.getName()) &&
a.getType().equals(acl.getType()) &&
a.getAclScope().equals(acl.getAclScope())) {
BitSet current = a.getAclBitSet();
BitSet original = (BitSet) current.clone();
current.andNot(acl.getAclBitSet());
if (current.equals(original)) {
return false;
}
if (current.isEmpty()) {
existingAcls.remove(a);
}
return true;
}
}
return false;
}
/**
* Applies a mapping to a BitSet.
*
* <p>If the mapping does not affect the bit set, returns the original.
* Never changes the original.
*
* @param mapping Mapping
* @param bitSet Bit set
* @return Bit set with mapping applied
*/
public static BitSet apply(Mapping mapping, BitSet bitSet) {
final BitSet newBitSet = new BitSet();
for (int source : BitSets.toIter(bitSet)) {
final int target = mapping.getTarget(source);
newBitSet.set(target);
}
if (newBitSet.equals(bitSet)) {
return bitSet;
}
return newBitSet;
}
public boolean isRepeatFooterValid( final ReportEvent event, final LayouterLevel[] levels ) {
final BitSet bitSet = computeRepeatingFooterValidity( event, levels );
if ( bitSet.equals( lastPrintedRepeatFooterSignature ) ) {
return true;
} else {
this.lastPrintedRepeatFooterSignature.clear();
this.lastPrintedRepeatFooterSignature.or( bitSet );
return false;
}
}
/** Determine if this set intersects another.
* @param other the other set in question.
*/
public boolean intersects(terminal_set other)
throws internal_error
{
not_null(other);
/* make a copy of the other set */
BitSet copy = (BitSet)other._elements.clone();
/* xor out our values */
copy.xor(this._elements);
/* see if its different */
return !copy.equals(other._elements);
}
public boolean hasAccess(OzoneAclInfo acl) {
if (acl == null) {
return false;
}
BitSet aclBitSet = getAcl(acl.getType(), acl.getName());
if (aclBitSet == null) {
return false;
}
BitSet result = BitSet.valueOf(acl.getRights().toByteArray());
result.and(aclBitSet);
return (!result.equals(ZERO_BITSET) || aclBitSet.get(ALL.ordinal()))
&& !aclBitSet.get(NONE.ordinal());
}
private boolean verifyAclRemoved(List<OzoneAcl> acls, OzoneAcl removedAcl) {
for (OzoneAcl acl : acls) {
if (acl.getName().equals(removedAcl.getName()) &&
acl.getType().equals(removedAcl.getType()) &&
acl.getAclScope().equals(removedAcl.getAclScope())) {
BitSet temp = (BitSet) acl.getAclBitSet().clone();
temp.and(removedAcl.getAclBitSet());
return !temp.equals(removedAcl.getAclBitSet());
}
}
return true;
}
private boolean verifyAclAdded(List<OzoneAcl> acls, OzoneAcl newAcl) {
for (OzoneAcl acl : acls) {
if (acl.getName().equals(newAcl.getName()) &&
acl.getType().equals(newAcl.getType()) &&
acl.getAclScope().equals(newAcl.getAclScope())) {
BitSet temp = (BitSet) acl.getAclBitSet().clone();
temp.and(newAcl.getAclBitSet());
return temp.equals(newAcl.getAclBitSet());
}
}
return false;
}
/**
* Applies a mapping to a BitSet.
*
* <p>If the mapping does not affect the bit set, returns the original.
* Never changes the original.
*
* @param mapping Mapping
* @param bitSet Bit set
* @return Bit set with mapping applied
*/
public static BitSet apply(Mapping mapping, BitSet bitSet) {
final BitSet newBitSet = new BitSet();
for (int source : BitSets.toIter(bitSet)) {
final int target = mapping.getTarget(source);
newBitSet.set(target);
}
if (newBitSet.equals(bitSet)) {
return bitSet;
}
return newBitSet;
}
/**
* Applies a mapping to a BitSet.
*
* <p>If the mapping does not affect the bit set, returns the original.
* Never changes the original.
*
* @param mapping Mapping
* @param bitSet Bit set
* @return Bit set with mapping applied
*/
public static BitSet apply(Mapping mapping, BitSet bitSet) {
final BitSet newBitSet = new BitSet();
for (int source : BitSets.toIter(bitSet)) {
final int target = mapping.getTarget(source);
newBitSet.set(target);
}
if (newBitSet.equals(bitSet)) {
return bitSet;
}
return newBitSet;
}
private void processLiveInfo() {
int bbCount = mth.getBasicBlocks().size();
int regsCount = mth.getRegsCount();
BitSet[] liveInBlocks = initBitSetArray(bbCount, regsCount);
List<BlockNode> blocks = mth.getBasicBlocks();
int blocksCount = blocks.size();
int iterationsLimit = blocksCount * 10;
boolean changed;
int k = 0;
do {
changed = false;
for (BlockNode block : blocks) {
int blockId = block.getId();
BitSet prevIn = liveInBlocks[blockId];
BitSet newIn = new BitSet(regsCount);
for (BlockNode successor : block.getSuccessors()) {
newIn.or(liveInBlocks[successor.getId()]);
}
newIn.andNot(defs[blockId]);
newIn.or(uses[blockId]);
if (!prevIn.equals(newIn)) {
changed = true;
liveInBlocks[blockId] = newIn;
}
}
if (k++ > iterationsLimit) {
throw new JadxRuntimeException("Live variable analysis reach iterations limit, blocks count: " + blocksCount);
}
} while (changed);
this.liveIn = liveInBlocks;
}
public void write(BitSet value, String name, BitSet defVal) throws IOException {
if (value == null || value.equals(defVal)) {
return;
}
StringBuilder buf = new StringBuilder();
for (int i = value.nextSetBit(0); i >= 0; i = value.nextSetBit(i + 1)) {
buf.append(i);
buf.append(" ");
}
buf.setLength(Math.max(0, buf.length() - 1));
currentElement.setAttribute(name, buf.toString());
}
private void applySelectionChange(BitSet newSel) {
if (!newSel.equals(mSelection)) {
selectionAboutToChange();
mSelection = newSel;
selectionDidChange();
}
}
/**
* Checks if a potential solution is a real one (not included in a previous
* solution) and add this solution to the solution list in case of success.
*
* @param traversed new potential solution
*/
private void solution(BitSet traversed) throws CDKException {
boolean included = false;
BitSet projG1 = projectG1(traversed);
BitSet projG2 = projectG2(traversed);
// the solution must follows the search constrains
// (must contain the mandatory elements in G1 an G2)
if (isContainedIn(getSourceBitSet(), projG1) && isContainedIn(getTargetBitSet(), projG2)) {
// the solution should not be included in a previous solution
// at the CDKRGraph level. So we check against all previous solution
// On the other hand if a previous solution is included in the
// new one, the previous solution is removed.
for (Iterator<BitSet> i = getSolutionList().listIterator(); i.hasNext() && !included;) {
BitSet sol = i.next();
if (!sol.equals(traversed)) {
// if we asked to save all 'mappings' then keep this mapping
if (isFindAllMap() && (projG1.equals(projectG1(sol)) || projG2.equals(projectG2(sol)))) {
// do nothing
} // if the new solution is included mark maxIterator as included
else if (isContainedIn(projG1, projectG1(sol)) || isContainedIn(projG2, projectG2(sol))) {
included = true;
} // if the previous solution is contained in the new one, remove the previous solution
else if (isContainedIn(projectG1(sol), projG1) || isContainedIn(projectG2(sol), projG2)) {
i.remove();
}
} else {
// solution already exists
included = true;
}
}
if (included == false) {
// if maxIterator is really a new solution add maxIterator to the
// list of current solution
getSolutionList().add(traversed);
}
if (!isFindAllStructure()) {
// if we need only one solution
// stop the search process
// (e.g. substructure search)
this.stop = true;
}
}
}
@Override
public boolean same(BitSet fact1, BitSet fact2) {
return fact1.equals(fact2);
}
public int superset( BitSet n1, BitSet n2 ) {
if ( n1.equals( n2 ) ) {
return 0;
}
return supersetOrEqualset(n1, n2) ? 1 : -1;
}
private static void check(AbstractBlockBase<?> block, BitSet liveIn1, BitSet liveIn2) {
if (!liveIn1.equals(liveIn2)) {
throw JVMCIError.shouldNotReachHere(String.format("%s LiveSet differ: %s vs %s", block, liveIn1, liveIn2));
}
}
public boolean containsAll(GenericBitSet<N> other) {
BitSet temp = (BitSet) other.bitset.clone(); // if contains all, set.bitset will be a subset of our bitset
temp.and(bitset);
return temp.equals(other.bitset);
}