Java Code Examples for java.util.BitSet#clone()

The following examples show how to use java.util.BitSet#clone() . 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: AbstractCladeImportanceDistribution.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Checks if clade i contains clade j.
 *
 * @param i - the parent clade
 * @param j - the child clade
 * @return true, if i contains j
 */
protected boolean containsClade(BitSet i, BitSet j) {
    BitSet tmpI = (BitSet) i.clone();

    // just set the bits which are either in j but not in i or in i but not
    // in j
    tmpI.xor(j);
    int numberOfBitsInEither = tmpI.cardinality();
    // which bits are just in i
    tmpI.and(i);
    int numberIfBitJustInContaining = tmpI.cardinality();

    // if the number of bits just in i is equal to the number of bits just
    // in one of i or j
    // then i contains j
    return numberOfBitsInEither == numberIfBitJustInContaining;
}
 
Example 2
Source File: OzoneAclUtil.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: CDKRGraph.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test if set sourceBitSet is contained in set targetBitSet.
 *
 * @param sourceBitSet a bitSet
 * @param targetBitSet a bitSet
 * @return true if sourceBitSet is contained in targetBitSet
 */
private boolean isContainedIn(BitSet sourceBitSet, BitSet targetBitSet) {
    boolean result = false;

    if (sourceBitSet.isEmpty()) {
        return true;
    }

    BitSet setA = (BitSet) sourceBitSet.clone();
    setA.and(targetBitSet);

    if (setA.equals(sourceBitSet)) {
        result = true;
    }

    return result;
}
 
Example 4
Source File: TaneAlgorithmFilterTreeEnd.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether all subsets of X (with length of X - 1) are part of the last level.
 * Only if this check return true X is added to the new level.
 *
 * @param X
 * @return
 */
private boolean checkSubsets(BitSet X) {
    boolean xIsValid = true;

    // clone of X for usage in the following loop
    BitSet Xclone = (BitSet) X.clone();

    for (int l = X.nextSetBit(0); l >= 0; l = X.nextSetBit(l + 1)) {
        Xclone.clear(l);
        if (!level0.containsKey(Xclone)) {
            xIsValid = false;
            break;
        }
        Xclone.set(l);
    }

    return xIsValid;
}
 
Example 5
Source File: LeftHandSideGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private boolean checkJoinCondition(BitSet p, BitSet q) {

        if (p.length() >= q.length()) {
            return false;
        }
        
        BitSet intersection = (BitSet) p.clone();
        intersection.and(q);
        
        return p.cardinality() == intersection.cardinality() && 
        		q.cardinality() == intersection.cardinality();
    }
 
Example 6
Source File: CodeListSet.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if this set contains all the elements of the given collection.
 *
 * @param  c  the collection to be checked for containment in this set.
 * @return {@code true} if this set contains all elements of the given collection.
 */
@Override
public boolean containsAll(final Collection<?> c) {
    if (c instanceof CodeListSet) {
        final CodeListSet<?> o = (CodeListSet<?>) c;
        if (elementType == o.elementType) {
            if (values == (values | o.values)) {
                /*
                 * Code below this point checks for the rare cases
                 * where there is more than 64 code list elements.
                 */
                final BitSet s = supplementary;
                final BitSet os = o.supplementary;
                if (( s == null ||  s.isEmpty()) &&
                    (os == null || os.isEmpty()))
                {
                    return true;
                }
                if (s != null && os != null) {
                    final BitSet tmp = (BitSet) os.clone();
                    tmp.andNot(s);
                    return tmp.isEmpty();
                }
            }
        }
        return false;
    }
    return super.containsAll(c);
}
 
Example 7
Source File: LazyListModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Removes specified amount of bits from the set.
 */
private static BitSet removeAt (BitSet b, int at, int len, int newSize) {
    BitSet clone = (BitSet)b.clone ();
    
    int max = b.length ();
    while (at < max) {
        clone.set (at, b.get (at + len));
        at++;
    }
    clone.set (newSize, b.size (), false);
    return clone;
}
 
Example 8
Source File: LhsUtils.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static List<BitSet> generateLhsSubsets(BitSet lhs) {
    List<BitSet> results = new LinkedList<>();
    for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) {
        BitSet subset = (BitSet) lhs.clone();
        subset.flip(i);
        if (subset.cardinality() > 0) {
            results.add(subset);
        }
    }
    return results;
}
 
Example 9
Source File: Validator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private BitSet extendWith(BitSet ucc, int extensionAttr) {
		if (ucc.get(extensionAttr))
			return null;
		
		BitSet childUCC = (BitSet) ucc.clone();
		childUCC.set(extensionAttr);
		
		if (this.posCover.containsUCCOrGeneralization(childUCC))
			return null;
		
//		if (this.negCover.containsUCCOrSpecialization(childUCC)) // TODO: May be needed?
//			return null;
		
		return childUCC;
	}
 
Example 10
Source File: Inductor.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public void updatePositiveCover(FDList nonFds) {
/*		if (nonFds.isEmpty())
			return;
		
		// Sort the negative cover
		Logger.getInstance().writeln("Sorting FD-violations ...");
		Collections.sort(nonFds, new Comparator<BitSet>() {
			@Override
			public int compare(BitSet o1, BitSet o2) {
				return (int)(o1.cardinality() - o2.cardinality());
			}
		});
*/		// THE SORTING IS NOT NEEDED AS THE UCCSet SORTS THE NONUCCS BY LEVEL ALREADY
		
		de.metanome.algorithms.cfdfinder.utils.Logger.getInstance().writeln("Inducing FD candidates ...");
		for (int i = nonFds.getFdLevels().size() - 1; i >= 0; i--) {
			if (i >= nonFds.getFdLevels().size()) // If this level has been trimmed during iteration
				continue;
			
			List<BitSet> nonFdLevel = nonFds.getFdLevels().get(i);
			for (BitSet lhs : nonFdLevel) {
				
				BitSet fullRhs = (BitSet) lhs.clone();
				fullRhs.flip(0, this.posCover.getNumAttributes());
				
				for (int rhs = fullRhs.nextSetBit(0); rhs >= 0; rhs = fullRhs.nextSetBit(rhs + 1))
					this.specializePositiveCover(lhs, rhs, nonFds);
			}
			nonFdLevel.clear();
		}
	}
 
Example 11
Source File: BitSets.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns a BitSet that is the union of the given BitSets. Does not modify
 * any of the inputs. */
public static BitSet union(BitSet set0, BitSet... sets) {
  final BitSet s = (BitSet) set0.clone();
  for (BitSet set : sets) {
    s.or(set);
  }
  return s;
}
 
Example 12
Source File: FDTreeElement.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public void grow(BitSet lhs, FDTree fdTree) {
	// Add specializations of all nodes an mark them as isFD, but if specialization exists, then it is invalid and should not be marked; only add specializations of nodes not marked as isFD!
	BitSet rhs = this.rhsAttributes;
	
	BitSet invalidRhs = (BitSet) rhs.clone();
	invalidRhs.andNot(this.rhsFds);
	
	// Add specializations that are not invalid
	if (invalidRhs.cardinality() > 0) {
		for (int extensionAttr = 0; extensionAttr < this.numAttributes; extensionAttr++) {
			if (lhs.get(extensionAttr) || rhs.get(extensionAttr))
				continue;
			
			lhs.set(extensionAttr);
			fdTree.addFunctionalDependencyIfNotInvalid(lhs, invalidRhs);
			lhs.clear(extensionAttr);
		}
	}
	
	// Traverse children and let them add their specializations
	if (this.children != null) {
		for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) {
			FDTreeElement element = this.children[childAttr];
			if (element != null) {
				lhs.set(childAttr);
				element.grow(lhs, fdTree);
				lhs.clear(childAttr);
			}
		}
	}
}
 
Example 13
Source File: DefaultMXBeanMappingFactory.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static boolean subset(BitSet sub, BitSet sup) {
    BitSet subcopy = (BitSet) sub.clone();
    subcopy.andNot(sup);
    return subcopy.isEmpty();
}
 
Example 14
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static boolean subset(BitSet sub, BitSet sup) {
    BitSet subcopy = (BitSet) sub.clone();
    subcopy.andNot(sup);
    return subcopy.isEmpty();
}
 
Example 15
Source File: DefaultMXBeanMappingFactory.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static boolean subset(BitSet sub, BitSet sup) {
    BitSet subcopy = (BitSet) sub.clone();
    subcopy.andNot(sup);
    return subcopy.isEmpty();
}
 
Example 16
Source File: Utils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static int andNotCount(BitSet base, BitSet not) {
	BitSet andNotSet = (BitSet) base.clone();
	andNotSet.andNot(not);
	return andNotSet.cardinality();
}
 
Example 17
Source File: TaneAlgorithmFilterTreeEnd.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private void computeDependencies(int l) throws AlgorithmExecutionException {
    initializeCplusForLevel();

    // iterate through the combinations of the level
    for (BitSet X : level1.keySet()) {
        // Build the intersection between X and C_plus(X)
        BitSet C_plus = level1.get(X).getRhsCandidates();
        BitSet intersection = (BitSet) X.clone();
        intersection.and(C_plus);

        // clone of X for usage in the following loop
        BitSet Xclone = (BitSet) X.clone();

        // iterate through all elements (A) of the intersection
        for (int A = intersection.nextSetBit(0); A >= 0; A = intersection.nextSetBit(A + 1)) {
            Xclone.clear(A);

            // check if X\A -> A is valid
            StrippedPartition spXwithoutA = level0.get(Xclone).getPartition();
            StrippedPartition spX = level1.get(X).getPartition();

            if (spX.getError() == spXwithoutA.getError()) {
                // add fd to FDTree. Filter the tree at the end of the algorithm.
                dependencies.addFunctionalDependency(Xclone, A);


                // remove A from C_plus(X)
                level1.get(X).getRhsCandidates().clear(A);

                // remove all B in R\X from C_plus(X)
                BitSet RwithoutX = new BitSet();
                // set to R
                RwithoutX.set(1, numberAttributes + 1);
                // remove X
                RwithoutX.andNot(X);

                for (int i = RwithoutX.nextSetBit(0); i >= 0; i = RwithoutX.nextSetBit(i + 1)) {
                    level1.get(X).getRhsCandidates().clear(i);
                }

            }
            Xclone.set(A);
        }
    }
}
 
Example 18
Source File: DefaultMXBeanMappingFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private static boolean subset(BitSet sub, BitSet sup) {
    BitSet subcopy = (BitSet) sub.clone();
    subcopy.andNot(sup);
    return subcopy.isEmpty();
}
 
Example 19
Source File: ScatterSearchV1.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
public Subset(BitSet subset, double merit){
  this.subset =(BitSet)subset.clone ();
  this.merit =merit;
}
 
Example 20
Source File: TaneAlgorithmFilterTreeDirect.java    From metanome-algorithms with Apache License 2.0 2 votes vote down vote up
/**
 * Get prefix of BitSet by copying it and removing the last Bit.
 *
 * @param bitset
 * @return
 */
private BitSet getPrefix(BitSet bitset) {
    BitSet prefix = (BitSet) bitset.clone();
    prefix.clear(getLastSetBitIndex(prefix));
    return prefix;
}