Example usage for java.util BitSet get

List of usage examples for java.util BitSet get

Introduction

In this page you can find the example usage for java.util BitSet get.

Prototype

public boolean get(int bitIndex) 

Source Link

Document

Returns the value of the bit with the specified index.

Usage

From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper.java

@Override
public void mapFromRusCorpora(RusCorporaWordform srcWf, com.textocat.textokit.morph.fs.Wordform targetWf) {
    Word wordAnno = targetWf.getWord();//  w  ww. j  av a 2 s. co m
    delegate.mapFromRusCorpora(srcWf, targetWf);
    // first - check whether tag is in tagset
    final BitSet wfTag = toGramBits(gm, FSUtils.toList(targetWf.getGrammems()));
    // skip INIT as a whole new category
    if (wfTag.get(gm.getGrammemNumId(RNCMorphConstants.RNC_INIT))) {
        // skip
        return;
    }
    //
    if (!dict.containsGramSet(wfTag)) {
        // if there is no such tag in dictionary then look the word in it
        String wordStr = wordAnno.getCoveredText();
        List<Wordform> dictWfs = dict.getEntries(normalizeToDictionaryForm(wordStr));
        if (dictWfs == null || dictWfs.isEmpty()) {
            onUnknownWord(wordAnno, wfTag);
            return;
        }
        // search for a unique dictionary entry that has a tag extending the given one
        List<Wordform> wfExtensions = Lists.newLinkedList();
        for (Wordform dictWf : dictWfs) {
            BitSet dictWfTag = getAllGramBits(dictWf, dict);
            if (contains(dictWfTag, wfTag)) {
                wfExtensions.add(dictWf);
            }
        }
        if (wfExtensions.isEmpty()) {
            onConflictingTag(wordAnno, wfTag);
        } else if (wfExtensions.size() > 1) {
            onAmbiguousWordform(wordAnno, wfTag);
        } else {
            BitSet newTag = getAllGramBits(wfExtensions.get(0), dict);
            List<String> newTagStr = gm.toGramSet(newTag);
            targetWf.setGrammems(FSUtils.toStringArray(getCAS(targetWf), newTagStr));
            onTagExtended(wordAnno, wfTag, newTag);
        }
    }
}

From source file:org.apache.tez.dag.utils.TaskSpecificLaunchCmdOption.java

/**
 * Find if task specific launch command options have to be added.
 *
 * @param vertexName//from   ww  w.jav a 2s.  c  o m
 * @param taskId
 * @return boolean
 */
public boolean addTaskSpecificLaunchCmdOption(String vertexName, int taskId) {
    if (tasksMap == null || taskId < 0) {
        return false;
    }
    BitSet taskSet = tasksMap.get(vertexName);
    // profile all tasks in the vertex, if taskSet is empty
    return (taskSet == null) ? false : ((taskSet.isEmpty()) ? true : taskSet.get(taskId));
}

From source file:org.apache.tez.dag.utils.JavaProfilerOptions.java

/**
 * Find if the JVM needs profiling/*from w  w  w.ja va2s. c o  m*/
 *
 * @param vertexName
 * @param taskId
 * @return boolean
 */
public boolean shouldProfileJVM(String vertexName, int taskId) {
    if (tasksToProfileMap == null || taskId < 0) {
        return false;
    }
    BitSet taskSet = tasksToProfileMap.get(vertexName);
    // profile all tasks in the vertex, if taskSet is empty
    return (taskSet == null) ? false : ((taskSet.isEmpty()) ? true : taskSet.get(taskId));
}

From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper2.java

@Override
public void mapFromRusCorpora(RusCorporaWordform srcWf, com.textocat.textokit.morph.fs.Wordform targetWf) {
    Word wordAnno = targetWf.getWord();//from   w  w  w  . j  a  v a 2  s  .co  m
    delegate.mapFromRusCorpora(srcWf, targetWf);
    // first - check whether tag is in tagset
    final BitSet wfTag = toGramBits(gm, FSUtils.toList(targetWf.getGrammems()));
    // skip INIT as a whole new category
    if (wfTag.get(gm.getGrammemNumId(RNCMorphConstants.RNC_INIT))) {
        return;
    }
    if (wfTag.intersects(rncDistortionsMask)) {
        wfTag.andNot(rncDistortionsMask);
        if (!dict.containsGramSet(wfTag)) {
            onDistortedWordWithUnknownTag(wordAnno, wfTag);
        }
        return;
    }
    //
    // if there is no such tag in dictionary then look the word in it
    String wordStr = wordAnno.getCoveredText();
    List<Wordform> dictWfs = dict.getEntries(normalizeToDictionaryForm(wordStr));
    if (dictWfs == null || dictWfs.isEmpty()) {
        // wfTag.isEmpty => NON-LEX
        if (!wfTag.isEmpty() && !dict.containsGramSet(wfTag)) {
            onUnknownWordWithUnknownTag(wordAnno, wfTag);
        }
        return;
    }
    // retain only the gram categories that are represented in RNC tagset
    Set<BitSet> dictTags = rncTrimmer.trimAndMerge(Lists.transform(dictWfs, allGramBitsFunction(dict)));
    // search for a unique dictionary entry that has a tag extending the given one
    List<BitSet> wfExtensions = Lists.newLinkedList();
    for (BitSet dTag : dictTags) {
        if (contains(dTag, wfTag)) {
            wfExtensions.add(dTag);
        }
    }
    if (wfExtensions.isEmpty()) {
        onConflictingTag(wordAnno, wfTag);
    } else if (wfExtensions.size() > 1) {
        onAmbiguousWordform(wordAnno, wfTag);
    } else {
        BitSet newTag = wfExtensions.get(0);
        if (newTag.cardinality() > wfTag.cardinality()) {
            List<String> newTagStr = gm.toGramSet(newTag);
            targetWf.setGrammems(FSUtils.toStringArray(getCAS(targetWf), newTagStr));
            onTagExtended(wordAnno, wfTag, newTag);
        }
    }
}

From source file:com.asakusafw.runtime.io.csv.CsvEmitter.java

private boolean isEscapeTarget() {
    BitSet mask = forceEscapeMask;
    return mask != null && mask.get(columnIndex);
}

From source file:jlg.jade.test.asterix.cat062.Cat062LargeSampleTest.java

@Test
@Description("Used only for printing byte information that can help with developing the tool")
@Ignore/* ww  w .  j a  v  a 2 s.c  om*/
public void with_one_packet_should_print_bytes() throws IOException {
    try (InputStream is = TestHelper.getFileInputStreamFromResource("final_frame_062_one_packet_sample2.FF")) {
        FinalFrameReader ffReader = new FinalFrameReader();
        while (is.available() > 0) {
            byte[] ffPayload = ffReader.read(is);
            if (ffPayload != null) {
                System.out.println("DATA BLOCK START");
                for (int i = 0; i < ffPayload.length; i++) {
                    BitSet bs = BitSet.valueOf(new byte[] { ffPayload[i] });
                    System.out.print("ORIGINAL [ ");
                    for (int j = 0; j < 8; j++) {
                        if (bs.get(j)) {
                            System.out.print(1 + " ");
                        } else {
                            System.out.print(0 + " ");
                        }
                    }
                    System.out.print("]");

                    System.out.print("   REVERSE [ ");
                    for (int j = 8; j > 0; j--) {
                        if (bs.get(j)) {
                            System.out.print(1 + " ");
                        } else {
                            System.out.print(0 + " ");
                        }
                    }
                    System.out.print("]   ");
                    int unsignedValue = Byte.toUnsignedInt(ffPayload[i]);

                    System.out.println(unsignedValue);

                    if (i == 0 || i == 2) {
                        System.out.println("----------------------------------------------------------------");
                    }
                }
            }
            System.out.println("DATA BLOCK END");
            System.out.println(System.lineSeparator());
        }
    }
}

From source file:com.laxser.blitz.web.ControllerInterceptorAdapter.java

/**
 * true??/*from  ww w. j  a v a2s . c  o  m*/
 * 
 * @param controllerClazz
 * @param actionMethod
 * @return
 */
protected final boolean checkDenyAnnotations(Class<?> controllerClazz, Method actionMethod) {
    List<Class<? extends Annotation>> denyAnnotations = getDenyAnnotationClasses();
    if (denyAnnotations == null || denyAnnotations.size() == 0) {
        return false;
    }
    for (Class<? extends Annotation> denyAnnotation : denyAnnotations) {
        if (denyAnnotation == null) {
            continue;
        }
        BitSet scopeSet = getAnnotationScope(denyAnnotation);
        if (scopeSet.get(AnnotationScope.METHOD.ordinal())) {
            if (actionMethod.isAnnotationPresent(denyAnnotation)) {
                return checkAnnotation(actionMethod.getAnnotation(denyAnnotation));
            }
        }
        if (scopeSet.get(AnnotationScope.CLASS.ordinal())) {
            if (controllerClazz.isAnnotationPresent(denyAnnotation)) {
                return checkAnnotation(actionMethod.getAnnotation(denyAnnotation));
            }
        }
        if (scopeSet.get(AnnotationScope.ANNOTATION.ordinal())) {
            for (Annotation annotation : actionMethod.getAnnotations()) {
                if (annotation.annotationType().isAnnotationPresent(denyAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(denyAnnotation));
                }
            }
            for (Annotation annotation : controllerClazz.getAnnotations()) {
                if (annotation.annotationType().isAnnotationPresent(denyAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(denyAnnotation));
                }
            }
        }
    }
    return false;
}

From source file:com.joliciel.jochre.graphics.ShapeFillerImpl.java

BitSet fillBitSet(Shape shape, BitSet bitset, int neighbourBirthCount) {
    BitSet newBitSet = new BitSet(bitset.size());
    int baseIndex = 0;
    for (int y = 0; y < shape.getHeight(); y++) {
        for (int x = 0; x < shape.getWidth(); x++) {
            int index = baseIndex + x;
            if (bitset.get(index))
                newBitSet.set(index);//from   w w  w . ja  va 2s .c o  m
            else {
                int surroundingCount = 0;
                if (y > 0) {
                    if (x > 0)
                        surroundingCount += bitset.get(index - (shape.getWidth() + 1)) ? 1 : 0;
                    surroundingCount += bitset.get(index - (shape.getWidth())) ? 1 : 0;
                    if (x < shape.getWidth() - 1)
                        surroundingCount += bitset.get(index - (shape.getWidth() - 1)) ? 1 : 0;
                }
                if (x > 0)
                    surroundingCount += bitset.get(index - 1) ? 1 : 0;
                if (x < shape.getWidth() - 1)
                    surroundingCount += bitset.get(index + 1) ? 1 : 0;
                if (y < shape.getHeight() - 1) {
                    if (x > 0)
                        surroundingCount += bitset.get(index + (shape.getWidth() - 1)) ? 1 : 0;
                    surroundingCount += bitset.get(index + (shape.getWidth())) ? 1 : 0;
                    if (x < shape.getWidth() - 1)
                        surroundingCount += bitset.get(index + (shape.getWidth() + 1)) ? 1 : 0;
                }
                // if at least NEIGHBOUR_COUNT_BIRTH out of 8 surrounding pixels are on,
                // assume this one should be on
                if (surroundingCount >= NEIGHBOUR_COUNT_BIRTH)
                    newBitSet.set(index);
            }
        }
        baseIndex += shape.getWidth();
    }
    return newBitSet;
}

From source file:com.laxser.blitz.web.ControllerInterceptorAdapter.java

/**
 * false?/*from   ww  w . jav  a 2  s. co  m*/
 * 
 * @param controllerClazz
 *            
 * @param actionMethod
 *            ?
 * @return
 */
protected final boolean checkRequiredAnnotations(Class<?> controllerClazz, Method actionMethod) {
    List<Class<? extends Annotation>> requiredAnnotations = getRequiredAnnotationClasses();
    if (requiredAnnotations == null || requiredAnnotations.size() == 0) {
        return true;
    }
    for (Class<? extends Annotation> requiredAnnotation : requiredAnnotations) {
        if (requiredAnnotation == null) {
            continue;
        }
        BitSet scopeSet = getAnnotationScope(requiredAnnotation);
        if (scopeSet.get(AnnotationScope.METHOD.ordinal())) {
            if (actionMethod.isAnnotationPresent(requiredAnnotation)) {
                return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
            }
        }
        if (scopeSet.get(AnnotationScope.CLASS.ordinal())) {
            if (controllerClazz.isAnnotationPresent(requiredAnnotation)) {
                return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
            }
        }
        if (scopeSet.get(AnnotationScope.ANNOTATION.ordinal())) {
            for (Annotation annotation : actionMethod.getAnnotations()) {
                if (annotation.annotationType().isAnnotationPresent(requiredAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                }
            }
            for (Annotation annotation : controllerClazz.getAnnotations()) {
                if (annotation.annotationType().isAnnotationPresent(requiredAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                }
            }
        }
    }
    return false;
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

public static <T extends Enum<T>> EnumDistribution<T> // Immutable
        create(Class<T> token, String sourceFile) throws IOException {
    if (token == null)
        throw new NullArgumentException();
    if (!token.isEnum())
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum.");
    if (token.getEnumConstants().length == 0)
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum.");
    EnumDistribution<T> result = new EnumDistribution<T>();
    result.values = token.getEnumConstants();
    result.probabilities = new EnumMap<T, Double>(token);
    Map<String, T> converter = new HashMap<String, T>();
    final int numberOfValues = result.values.length;
    int[] valueIndices = new int[numberOfValues];
    double[] valueProbabilities = new double[numberOfValues];
    BitSet valueIsComitted = new BitSet(numberOfValues);
    {//from  ww w  . ja  v a2 s  .c om
        int counter = 0;
        for (T value : result.values) {
            valueIndices[counter] = counter++;
            result.probabilities.put(value, 0.);
            converter.put(value.name(), value);
        }
    }
    BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
    try {
        String newLine;
        while ((newLine = reader.readLine()) != null) {
            if (newLine.isEmpty())
                continue;
            StringTokenizer tokenizer = new StringTokenizer(newLine);
            final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t");
            if (tokenizer.hasMoreTokens())
                throw new ParseException(
                        "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0);
            final double p = Double.parseDouble(pStr);
            if (p < 0. || p > 1.)
                throw new IOException(pStr + " is not a valid probability for the value " + name);
            result.probabilities.put(converter.get(name), p);
            final int ordinal = converter.get(name).ordinal();
            if (valueIsComitted.get(ordinal))
                throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0);
            valueProbabilities[converter.get(name).ordinal()] = p;
            valueIsComitted.set(ordinal, true);
        }
        { // Check sum of probabilities
            double sum = 0.;
            for (double p : valueProbabilities)
                sum += p;
            if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.))
                throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting "
                        + "probaility sum (value " + sum + ") is not equal to 1.");
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    } finally {
        reader.close();
    }
    result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities);
    return result;
}