Java Code Examples for java.util.BitSet

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android_8, under directory /src/com/google/gson/.

Source file: DefaultTypeAdapters.java

  18 
vote

@Override public BitSet deserialize(JsonElement json,Type typeOfT,JsonDeserializationContext context) throws JsonParseException {
  if (!json.isJsonArray()) {
    throw new JsonParseException("Expected an array of bits.");
  }
  BitSet result=new BitSet();
  JsonArray array=json.getAsJsonArray();
  for (int i=0; i < array.size(); i++) {
    JsonElement element=array.get(i);
    if (element.getAsBoolean()) {
      result.set(i);
    }
  }
  return result;
}
 

Example 2

From project ANNIS, under directory /annis-widgets/src/main/java/annis/gui/widgets/grid/.

Source file: Row.java

  18 
vote

/** 
 * Adds an event to this row
 * @param e
 * @return False if could not be added because the event is overlapping another event in the row.
 */
public boolean addEvent(GridEvent e){
  BitSet eventOccupance=new BitSet(e.getRight());
  eventOccupance.set(e.getLeft(),e.getRight() + 1,true);
  if (occupancySet.intersects(eventOccupance)) {
    return false;
  }
  occupancySet.or(eventOccupance);
  events.add(e);
  return true;
}
 

Example 3

From project aviator, under directory /src/main/java/com/googlecode/aviator/asm/commons/.

Source file: JSRInlinerAdapter.java

  18 
vote

/** 
 * Walks the method and determines which internal subroutine(s), if any, each instruction is a method of.
 */
private void markSubroutines(){
  BitSet anyvisited=new BitSet();
  markSubroutineWalk(mainSubroutine,0,anyvisited);
  for (Iterator it=subroutineHeads.entrySet().iterator(); it.hasNext(); ) {
    Map.Entry entry=(Map.Entry)it.next();
    LabelNode lab=(LabelNode)entry.getKey();
    Subroutine sub=(Subroutine)entry.getValue();
    int index=instructions.indexOf(lab);
    markSubroutineWalk(sub,index,anyvisited);
  }
}
 

Example 4

From project Bioclipse.clustering, under directory /src/net/bioclipse/chem/clustering/clusterhandling/.

Source file: MoleculeDistAlgo.java

  18 
vote

@Override public double calculateElementDistance(CDKMolecule cdkm1,CDKMolecule cdkm2) throws BioclipseException {
  Property urgency=Property.USE_CACHED;
  CDKManager cdk=new CDKManager();
  BitSet bs1=cdkm1.getFingerprint(urgency);
  BitSet bs2=cdkm2.getFingerprint(urgency);
  return cdk.calculateTanimoto(bs1,bs2);
}
 

Example 5

From project Blitz, under directory /src/com/laxser/blitz/web/.

Source file: ControllerInterceptorAdapter.java

  18 
vote

public static BitSet getMethodAndClassScope(){
  BitSet bitSet=new BitSet();
  bitSet.set(METHOD.ordinal());
  bitSet.set(CLASS.ordinal());
  return bitSet;
}
 

Example 6

From project BSPAN---Bluetooth-Sensor-Processing-for-Android, under directory /AndroidBTService/src/com/t2/biofeedback/device/.

Source file: SerialBTDevice.java

  18 
vote

public static BitSet byteArrayToBitSet(byte[] bytes){
  BitSet bits=new BitSet(bytes.length * 8);
  for (int i=0; i < bytes.length * 8; i++) {
    if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) {
      bits.set(i);
    }
  }
  return bits;
}
 

Example 7

From project CDKHashFingerPrint, under directory /test/fingerprints/.

Source file: HashedBloomFingerprinterTest.java

  18 
vote

/** 
 * Test of HashedBloomFingerprinter method
 * @throws InvalidSmilesException
 * @throws CDKException
 */
@Test public void testGenerateFingerprint() throws InvalidSmilesException, CDKException {
  String smiles="CCCCC1C(=O)N(N(C1=O)C1=CC=CC=C1)C1=CC=CC=C1";
  SmilesParser smilesParser=new SmilesParser(DefaultChemObjectBuilder.getInstance());
  IAtomContainer molecule=smilesParser.parseSmiles(smiles);
  System.out.println("Atom count " + molecule.getAtomCount());
  IFingerprinter fingerprint=new HashedBloomFingerprinter(1024);
  BitSet fingerprint1;
  fingerprint1=fingerprint.getBitFingerprint(molecule).asBitSet();
  System.out.println("fp " + fingerprint1.toString());
}
 

Example 8

From project DeuceSTM, under directory /src/java/org/deuce/objectweb/asm/commons/.

Source file: JSRInlinerAdapter.java

  18 
vote

/** 
 * Walks the method and determines which internal subroutine(s), if any, each instruction is a method of.
 */
private void markSubroutines(){
  BitSet anyvisited=new BitSet();
  markSubroutineWalk(mainSubroutine,0,anyvisited);
  for (Iterator it=subroutineHeads.entrySet().iterator(); it.hasNext(); ) {
    Map.Entry entry=(Map.Entry)it.next();
    LabelNode lab=(LabelNode)entry.getKey();
    Subroutine sub=(Subroutine)entry.getValue();
    int index=instructions.indexOf(lab);
    markSubroutineWalk(sub,index,anyvisited);
  }
}
 

Example 9

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: HandleNfcContact.java

  18 
vote

public static BitSet fromByteArray(byte[] bytes){
  BitSet bits=new BitSet();
  for (int i=0; i < bytes.length * 8; i++) {
    if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) {
      bits.set(i);
    }
  }
  return bits;
}
 

Example 10

From project enclojure, under directory /org-enclojure-ide/src/main/java/org/enclojure/ide/asm/commons/.

Source file: JSRInlinerAdapter.java

  18 
vote

/** 
 * Walks the method and determines which internal subroutine(s), if any, each instruction is a method of.
 */
private void markSubroutines(){
  BitSet anyvisited=new BitSet();
  markSubroutineWalk(mainSubroutine,0,anyvisited);
  for (Iterator it=subroutineHeads.entrySet().iterator(); it.hasNext(); ) {
    Map.Entry entry=(Map.Entry)it.next();
    LabelNode lab=(LabelNode)entry.getKey();
    Subroutine sub=(Subroutine)entry.getValue();
    int index=instructions.indexOf(lab);
    markSubroutineWalk(sub,index,anyvisited);
  }
}
 

Example 11

From project flyingsaucer, under directory /flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/property/.

Source file: PrimitivePropertyBuilders.java

  18 
vote

private static BitSet setFor(IdentValue[] values){
  BitSet result=new BitSet(IdentValue.getIdentCount());
  for (int i=0; i < values.length; i++) {
    IdentValue ident=values[i];
    result.set(ident.FS_ID);
  }
  return result;
}
 

Example 12

From project FML, under directory /client/cpw/mods/fml/client/.

Source file: SpriteHelper.java

  18 
vote

private static void initMCSpriteMaps(){
  BitSet slots=SpriteHelper.toBitSet("0000000000000000" + "0000000000110000" + "0000000001100000"+ "0000000001100000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000011111111"+ "0000000011111000"+ "0000000111111100"+ "0000000111111000"+ "0000000000000000");
  spriteInfo.put("/terrain.png",slots);
  slots=SpriteHelper.toBitSet("0000000000000000" + "0000000000000000" + "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000000000000000"+ "0000001000000000"+ "0000001110000000"+ "0000001000000000"+ "1111101010000000"+ "1111101010000000"+ "1111101110000000"+ "1111111111110000"+ "1111111111111111"+ "1111111111111111"+ "0000000000000000");
  spriteInfo.put("/gui/items.png",slots);
}
 

Example 13

From project gansenbang, under directory /s4-managerV2/src/io/s4/manager/thrift/.

Source file: Machine.java

  18 
vote

@Override public void read(org.apache.thrift.protocol.TProtocol prot,Machine struct) throws org.apache.thrift.TException {
  TTupleProtocol iprot=(TTupleProtocol)prot;
  BitSet incoming=iprot.readBitSet(2);
  if (incoming.get(0)) {
    struct.hostport=iprot.readString();
    struct.setHostportIsSet(true);
  }
  if (incoming.get(1)) {
    struct.status=iprot.readString();
    struct.setStatusIsSet(true);
  }
}
 

Example 14

From project google-gson, under directory /src/main/java/com/google/gson/.

Source file: DefaultTypeAdapters.java

  18 
vote

public BitSet deserialize(JsonElement json,Type typeOfT,JsonDeserializationContext context) throws JsonParseException {
  if (!json.isJsonArray()) {
    throw new JsonParseException("Expected an array of bits.");
  }
  BitSet result=new BitSet();
  JsonArray array=json.getAsJsonArray();
  for (int i=0; i < array.size(); i++) {
    JsonElement element=array.get(i);
    if (element.getAsBoolean()) {
      result.set(i);
    }
  }
  return result;
}
 

Example 15

From project gson, under directory /gson/src/main/java/com/google/gson/.

Source file: DefaultTypeAdapters.java

  18 
vote

public BitSet deserialize(JsonElement json,Type typeOfT,JsonDeserializationContext context) throws JsonParseException {
  if (!json.isJsonArray()) {
    throw new JsonParseException("Expected an array of bits.");
  }
  BitSet result=new BitSet();
  JsonArray array=json.getAsJsonArray();
  for (int i=0; i < array.size(); i++) {
    JsonElement element=array.get(i);
    if (element.getAsBoolean()) {
      result.set(i);
    }
  }
  return result;
}
 

Example 16

From project gxa, under directory /atlas-data-storage/src/main/java/uk/ac/ebi/gxa/data/.

Source file: StatisticsCursor.java

  18 
vote

private BitSet getAssaysForEFV(Pair<String,String> efv) throws AtlasDataException {
  final String name=efv.getFirst();
  final String value=efv.getSecond();
  BitSet assays=new BitSet(factorValues.length);
  for (int i=0; i < factors.length; i++) {
    if (name.equals(factors[i])) {
      for (int j=0; j < factorValues[i].length; j++) {
        assays.set(j,value.equals(factorValues[i][j]));
      }
    }
  }
  return assays;
}
 

Example 17

From project hank, under directory /src/java/com/rapleaf/hank/generated/.

Source file: PartitionServer.java

  18 
vote

@Override public void read(org.apache.thrift.protocol.TProtocol prot,get_args struct) throws org.apache.thrift.TException {
  TTupleProtocol iprot=(TTupleProtocol)prot;
  BitSet incoming=iprot.readBitSet(2);
  if (incoming.get(0)) {
    struct.domain_id=iprot.readI32();
    struct.set_domain_id_isSet(true);
  }
  if (incoming.get(1)) {
    struct.key=iprot.readBinary();
    struct.set_key_isSet(true);
  }
}
 

Example 18

From project avro, under directory /lang/java/thrift/src/test/java/org/apache/avro/thrift/test/.

Source file: Foo.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 19

From project bioclipse.speclipse, under directory /plugins/net.bioclipse.spectrum/src/spok/utils/.

Source file: SpectrumUtils.java

  17 
vote

public static BitSet createSpectrumFingerprint(CMLElements peakList){
  double[] xValues=new double[peakList.size()];
  for (int i=0; i < peakList.size(); i++) {
    CMLPeak peak=(CMLPeak)peakList.get(i);
    xValues[i]=peak.getXValue();
  }
  Arrays.sort(xValues);
  double maxPeak=xValues[xValues.length - 1];
  BitSet fingerprint=new BitSet();
  for (int i=0; i < Math.ceil(maxPeak / 2.0); i++) {
    int base=i * 2;
    int end=base + 4;
    if (isSignalInRange(xValues,base,end)) {
      fingerprint.set(i + 1);
    }
  }
  return fingerprint;
}
 

Example 20

From project boilerpipe, under directory /boilerpipe-core/src/main/de/l3s/boilerpipe/sax/.

Source file: HTMLHighlighter.java

  17 
vote

void process(final TextDocument doc,final InputSource is) throws BoilerpipeProcessingException {
  for (  TextBlock block : doc.getTextBlocks()) {
    if (block.isContent()) {
      final BitSet bs=block.getContainedTextElements();
      if (bs != null) {
        contentBitSet.or(bs);
      }
    }
  }
  try {
    parse(is);
  }
 catch (  SAXException e) {
    throw new BoilerpipeProcessingException(e);
  }
catch (  IOException e) {
    throw new BoilerpipeProcessingException(e);
  }
}
 

Example 21

From project boilerpipe_1, under directory /boilerpipe-core/src/main/de/l3s/boilerpipe/sax/.

Source file: HTMLHighlighter.java

  17 
vote

void process(final TextDocument doc,final InputSource is) throws BoilerpipeProcessingException {
  for (  TextBlock block : doc.getTextBlocks()) {
    if (block.isContent()) {
      final BitSet bs=block.getContainedTextElements();
      if (bs != null) {
        contentBitSet.or(bs);
      }
    }
  }
  try {
    parse(is);
  }
 catch (  SAXException e) {
    throw new BoilerpipeProcessingException(e);
  }
catch (  IOException e) {
    throw new BoilerpipeProcessingException(e);
  }
}
 

Example 22

From project brut.apktool.smali, under directory /baksmali/src/main/java/org/jf/baksmali/Adaptors/.

Source file: PostInstructionRegisterInfoMethodItem.java

  17 
vote

@Override public boolean writeTo(IndentingWriter writer) throws IOException {
  int registerInfo=baksmali.registerInfo;
  int registerCount=analyzedInstruction.getRegisterCount();
  BitSet registers=new BitSet(registerCount);
  if ((registerInfo & main.ALL) != 0) {
    registers.set(0,registerCount);
  }
 else {
    if ((registerInfo & main.ALLPOST) != 0) {
      registers.set(0,registerCount);
    }
 else     if ((registerInfo & main.DEST) != 0) {
      addDestRegs(registers,registerCount);
    }
  }
  return writeRegisterInfo(writer,registers);
}
 

Example 23

From project C-Cat, under directory /wordnet/src/main/java/gov/llnl/ontology/wordnet/feature/.

Source file: OntologicalFeatureMaker.java

  17 
vote

/** 
 * Disambiguates each leaf node in the hierarchy by removing features shared by alternative word senses for each  {@link Synset}.
 */
private void disambiguateLeafNodes(Set<Synset> leafNodes){
  OntologyReader wordnet=WordNetCorpusReader.getWordNet();
  for (  Synset leaf : leafNodes) {
    BitSet parentFeature=new BitSet();
    DoubleVectorAttribute attribute=(DoubleVectorAttribute)leaf.getAttribute(semanticAttributeName);
    if (attribute == null)     continue;
    DoubleVector leafVector=attribute.object();
    for (    Synset parent : leaf.getParents()) {
      attribute=(DoubleVectorAttribute)parent.getAttribute(semanticAttributeName);
      DoubleVector parentVector=attribute.object();
      if (parentVector instanceof SparseVector) {
        SparseVector sv=(SparseVector)parentVector;
        for (        int index : sv.getNonZeroIndices())         parentFeature.set(index);
      }
 else {
        for (int index=0; index < parentVector.length(); ++index)         if (parentVector.get(index) != 0d)         parentFeature.set(index);
      }
    }
    PartsOfSpeech pos=leaf.getPartOfSpeech();
    List<Lemma> lemmas=leaf.getLemmas();
    for (    Lemma lemma : lemmas) {
      Synset[] alternatives=wordnet.getSynsets(lemma.getLemmaName(),pos);
      for (      Synset alternative : alternatives) {
        for (        Synset altParent : alternative.getParents()) {
          Attribute altAttribute=altParent.getAttribute(semanticAttributeName);
          if (altAttribute == null)           continue;
          DoubleVector altVector=(DoubleVector)altAttribute.object();
          if (altVector instanceof SparseVector) {
            SparseVector sv=(SparseVector)altVector;
            for (            int index : sv.getNonZeroIndices())             if (!parentFeature.get(index))             leafVector.set(index,0);
          }
 else {
            for (int index=0; index < altVector.length(); ++index)             if (altVector.get(index) != 0d && !parentFeature.get(index))             leafVector.set(index,0);
          }
        }
      }
    }
  }
}
 

Example 24

From project collector, under directory /src/test/java/com/ning/metrics/collector/endpoint/.

Source file: OpsAlert.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 25

From project commons-pool, under directory /src/test/org/apache/commons/pool/impl/.

Source file: TestStackKeyedObjectPool.java

  17 
vote

public void testPoolWithNullFactory() throws Exception {
  KeyedObjectPool pool=new StackKeyedObjectPool(10);
  for (int i=0; i < 10; i++) {
    pool.returnObject("X",new Integer(i));
  }
  for (int j=0; j < 3; j++) {
    Integer[] borrowed=new Integer[10];
    BitSet found=new BitSet();
    for (int i=0; i < 10; i++) {
      borrowed[i]=(Integer)(pool.borrowObject("X"));
      assertNotNull(borrowed);
      assertTrue(!found.get(borrowed[i].intValue()));
      found.set(borrowed[i].intValue());
    }
    for (int i=0; i < 10; i++) {
      pool.returnObject("X",borrowed[i]);
    }
  }
  pool.invalidateObject("X",pool.borrowObject("X"));
  pool.invalidateObject("X",pool.borrowObject("X"));
  pool.clear("X");
  pool.clear();
}
 

Example 26

From project crunch, under directory /crunch/src/main/java/org/apache/crunch/lib/.

Source file: Sort.java

  17 
vote

private static <S>Schema createOrderedTupleSchema(PType<S> ptype,ColumnOrder[] orders){
  String tupleName="tuple" + UUID.randomUUID().toString().replace('-','x');
  Schema schema=Schema.createRecord(tupleName,"","crunch",false);
  List<Schema.Field> fields=Lists.newArrayList();
  AvroType<S> parentAvroType=(AvroType<S>)ptype;
  Schema parentAvroSchema=parentAvroType.getSchema();
  BitSet orderedColumns=new BitSet();
  for (  ColumnOrder columnOrder : orders) {
    int index=columnOrder.column - 1;
    AvroType<?> atype=(AvroType<?>)ptype.getSubTypes().get(index);
    Schema fieldSchema=Schema.createUnion(ImmutableList.of(atype.getSchema(),Schema.create(Type.NULL)));
    String fieldName=parentAvroSchema.getFields().get(index).name();
    fields.add(new Schema.Field(fieldName,fieldSchema,"",null,Schema.Field.Order.valueOf(columnOrder.order.name())));
    orderedColumns.set(index);
  }
  for (int i=0; i < ptype.getSubTypes().size(); i++) {
    if (orderedColumns.get(i)) {
      continue;
    }
    AvroType<?> atype=(AvroType<?>)ptype.getSubTypes().get(i);
    Schema fieldSchema=Schema.createUnion(ImmutableList.of(atype.getSchema(),Schema.create(Type.NULL)));
    String fieldName=parentAvroSchema.getFields().get(i).name();
    fields.add(new Schema.Field(fieldName,fieldSchema,"",null,Schema.Field.Order.IGNORE));
  }
  schema.setFields(fields);
  return schema;
}
 

Example 27

From project datasalt-utils, under directory /src/main/java/com/datasalt/utils/commons/.

Source file: BloomFilter.java

  17 
vote

/** 
 * Constructs an empty Bloom filter. The total length of the Bloom filter will be c*n.
 * @param c is the number of bits used per element.
 * @param n is the expected number of elements the filter will contain.
 * @param k is the number of hash functions used.
 */
public BloomFilter(double c,int n,int k){
  this.expectedNumberOfFilterElements=n;
  if (k == 0) {
    k=1;
  }
  this.k=k;
  this.bitsPerElement=c;
  this.bitSetSize=(int)Math.ceil(c * n);
  numberOfAddedElements=0;
  this.bitset=new BitSet(bitSetSize);
}
 

Example 28

From project eventtracker, under directory /scribe/src/test/java/com/ning/metrics/eventtracker/.

Source file: Click.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 29

From project extramuros, under directory /java/src/extramuros/java/jobs/clustering/proclus/algorithm/.

Source file: ProClusSampler.java

  17 
vote

public VectorWritable[] drawRandomVectors(int toDraw) throws IOException, IllegalAccessException, InstantiationException {
  totalLines=countLines();
  log.debug("TOTAL LINES:" + totalLines);
  log.debug("LINES to DRAW:" + toDraw);
  VectorWritable[] toReturn=new VectorWritable[toDraw];
  long[] selectedLines=new long[toDraw];
  log.debug("DRAWING " + toDraw + " from "+ totalLines);
  RandomSampler.sample(toDraw,totalLines - 1,toDraw,0,selectedLines,0,RandomUtils.getRandom());
  BitSet randomSel=new BitSet(totalLines);
  for (  long selectedLine : selectedLines) {
    randomSel.set((int)selectedLine + 1);
  }
  int pos=0;
  int count=0;
  Iterator<org.apache.mahout.common.Pair<Writable,Writable>> iterator=TableUtils.directorySeqIterator(input,config);
  while (iterator.hasNext()) {
    VectorWritable value=(VectorWritable)iterator.next().getSecond();
    pos++;
    if (randomSel.get(pos)) {
      toReturn[count]=value;
      count++;
    }
  }
  log.info("Drawn " + count + "/"+ pos+ " lines.");
  return toReturn;
}
 

Example 30

From project FlipDroid, under directory /tika-thrift/src/main/java/it/tika/.

Source file: TikaRequest.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 31

From project floodlight, under directory /lib/gen-java/net/floodlightcontroller/packetstreamer/thrift/.

Source file: PacketStreamer.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 32

From project flume, under directory /flume-ng-legacy-sources/flume-thrift-source/src/main/java/com/cloudera/flume/handlers/thrift/.

Source file: ThriftFlumeEvent.java

  17 
vote

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    __isset_bit_vector=new BitSet(1);
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  }
 catch (  org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 

Example 33

From project g414-hash, under directory /src/main/java/com/g414/hash/bloom/.

Source file: BloomFilter.java

  17 
vote

/** 
 * Construct a new Bloom Filter using the specified Hash implementation, maximum size (in # of elements inserted), and bits per item.
 * @param hash
 * @param maxSize
 * @param bitsPerItem
 * @param longHash
 */
public BloomFilter(LongHash hash,long maxSize,int bitsPerItem,boolean longHash){
  this.hash=hash;
  this.k=(int)Math.ceil(K_FACTOR * (double)(bitsPerItem));
  this.maxSize=maxSize;
  this.bitSet=new BitSet[NUM_BITSETS];
  this.bitSetLength=(int)((this.maxSize * bitsPerItem) / NUM_BITSETS);
  for (int i=0; i < NUM_BITSETS; i++) {
    this.bitSet[i]=new BitSet(this.bitSetLength);
  }
  this.longHash=longHash;
}
 

Example 34

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DataOptionDialog.java

  16 
vote

private boolean setBitmask(){
  boolean isAll=false, isNothing=false;
  if (bitmaskButtons == null) {
    bitmask=null;
    return true;
  }
  if (!(applyBitmaskButton.isSelected() || extractBitButton.isSelected())) {
    bitmask=null;
    return true;
  }
  int len=bitmaskButtons.length;
  for (int i=0; i < len; i++) {
    isAll=(isAll && bitmaskButtons[i].isSelected());
    isNothing=(isNothing && !bitmaskButtons[i].isSelected());
  }
  if (isAll || isNothing) {
    bitmask=null;
    return true;
  }
  if (bitmask == null)   bitmask=new BitSet(len);
  for (int i=0; i < len; i++) {
    bitmask.set(i,bitmaskButtons[i].isSelected());
  }
  return true;
}
 

Example 35

From project cipango, under directory /cipango-util/src/main/java/org/cipango/util/.

Source file: StringUtil.java

  15 
vote

public static String quoteIfNeeded(String s,BitSet bs){
  if (s == null)   return null;
  if (s.length() == 0)   return "\"\"";
  for (int i=0; i < s.length(); i++) {
    char c=s.charAt(i);
    if (c == '\\' || c == '"' || !bs.get(c)) {
      StringBuilder sb=new StringBuilder(s.length() + 4);
      quote(s,sb);
      return sb.toString();
    }
  }
  return s;
}
 

Example 36

From project core_4, under directory /impl/src/main/java/org/ajax4jsf/util/base64/.

Source file: URLCodec.java

  15 
vote

/** 
 * Encodes an array of bytes into an array of URL safe 7-bit <p/> characters. Unsafe characters are escaped.
 * @param urlsafe bitset of characters deemed URL safe
 * @param bytes array of bytes to convert to URL safe characters
 * @return array of bytes containing URL safe characters
 */
public static final byte[] encodeUrl(BitSet urlsafe,byte[] bytes){
  if (bytes == null) {
    return null;
  }
  if (urlsafe == null) {
    urlsafe=WWW_FORM_URL;
  }
  ByteArrayOutputStream buffer=new ByteArrayOutputStream();
  for (int i=0; i < bytes.length; i++) {
    int b=bytes[i];
    if (b < 0) {
      b=256 + b;
    }
    if (urlsafe.get(b)) {
      if (b == ' ') {
        b='+';
      }
      buffer.write(b);
    }
 else {
      buffer.write('%');
      char hex1=Character.toUpperCase(Character.forDigit((b >> 4) & 0xF,16));
      char hex2=Character.toUpperCase(Character.forDigit(b & 0xF,16));
      buffer.write(hex1);
      buffer.write(hex2);
    }
  }
  return buffer.toByteArray();
}
 

Example 37

From project frascati-studio-social, under directory /src/org/apache/commons/codec/net/.

Source file: QuotedPrintableCodec.java

  15 
vote

/** 
 * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. <p> This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in RFC 1521 and is suitable for encoding binary data and unformatted text. </p>
 * @param printable bitset of characters deemed quoted-printable
 * @param bytes array of bytes to be encoded
 * @return array of bytes containing quoted-printable data
 */
public static final byte[] encodeQuotedPrintable(BitSet printable,byte[] bytes){
  if (bytes == null) {
    return null;
  }
  if (printable == null) {
    printable=PRINTABLE_CHARS;
  }
  ByteArrayOutputStream buffer=new ByteArrayOutputStream();
  for (  byte c : bytes) {
    int b=c;
    if (b < 0) {
      b=256 + b;
    }
    if (printable.get(b)) {
      buffer.write(b);
    }
 else {
      encodeQuotedPrintable(b,buffer);
    }
  }
  return buffer.toByteArray();
}