/** * Copies setA to receiver, without changing latter's capacity. In other words, when passed * another Bitset, the values that it contains are copied into _this_ Bitset's byte array. If the * parameter set is larger than this set, an error message is printed and the program halts. * * @param setA The set that will be copied to this one. * @return This Bitset containing the new values */ Bitset getSet(Bitset setA) { if (byteArray.length < setA.byteArray.length) error("getSet: source set larger than dest. set"); clear(); int nbyte = setA.byteArray.length; for (int i = 0; i < nbyte; i++) // copy byteArray from arg. byteArray[i] = setA.byteArray[i]; return this; // return receiver, updated }
/** * This method checks first that a Bitset has a byte array, and if so it clears, or zeroes out, * the existing array. */ public void clear() { if (byteArray == null) error("clear: Can't clear a set that hasn't been constructed!"); for (int i = 0; i < byteArray.length; i++) byteArray[i] = 0; }
/** * This method removes the parameter element from the set, after ensuring that it is within the * allowable limits of the set elements. If it was not previously present, the set remains * unchanged. * * @param i The value to remove from the set */ public void exclude(int i) { if (i >= maxSize) error("exclude: " + i + " is too large be inside the set"); clearBit(i); }
/** * This method will ensure that the parameter is within the allowable values for the set, then * will add it to the set. If it was already present, it remains so. * * @param i The element to add to the set */ public void include(int i) { if (i >= maxSize) error("include: " + i + " is too large to fit inside the set"); setBit(i); }