Search in sources :

Example 36 with EnumMap

use of java.util.EnumMap in project EnrichmentMapApp by BaderLab.

the class DataSetResolver method guessDataSets.

public static List<DataSetParameters> guessDataSets(Path rootFolder, CancelStatus cancelStatus) {
    if (cancelStatus == null) {
        cancelStatus = new CancelStatus() {

            @Override
            public boolean isCancelled() {
                return false;
            }

            @Override
            public void cancel() {
            }
        };
    }
    // First test if rootFolder is itself a GSEA results folder
    Optional<DataSetParameters> dataset = GSEAResolver.resolveGSEAResultsFolder(rootFolder);
    if (dataset.isPresent())
        return ImmutableList.of(dataset.get());
    if (cancelStatus.isCancelled())
        return Collections.emptyList();
    try (Stream<Path> contents = Files.list(rootFolder)) {
        Map<Type, List<Path>> types = new EnumMap<>(Type.class);
        for (Type type : Type.values()) {
            types.put(type, new ArrayList<>());
        }
        for (Path path : (Iterable<Path>) contents::iterator) {
            if (cancelStatus.isCancelled())
                return Collections.emptyList();
            Type type = guessType(path);
            types.get(type).add(path);
        }
        if (cancelStatus.isCancelled())
            return Collections.emptyList();
        return createDataSets(types);
    } catch (IOException e) {
        e.printStackTrace();
        return Collections.emptyList();
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EnumMap(java.util.EnumMap)

Example 37 with EnumMap

use of java.util.EnumMap in project zxing by zxing.

the class CommandLineEncoder method main.

public static void main(String[] args) throws Exception {
    EncoderConfig config = new EncoderConfig();
    JCommander jCommander = new JCommander(config, args);
    jCommander.setProgramName(CommandLineEncoder.class.getSimpleName());
    if (config.help) {
        jCommander.usage();
        return;
    }
    String outFileString = config.outputFileBase;
    if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
        outFileString += '.' + config.imageFormat.toLowerCase(Locale.ENGLISH);
    }
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    if (config.errorCorrectionLevel != null) {
        hints.put(EncodeHintType.ERROR_CORRECTION, config.errorCorrectionLevel);
    }
    BitMatrix matrix = new MultiFormatWriter().encode(config.contents.get(0), config.barcodeFormat, config.width, config.height, hints);
    MatrixToImageWriter.writeToPath(matrix, config.imageFormat, Paths.get(outFileString));
}
Also used : EncodeHintType(com.google.zxing.EncodeHintType) MultiFormatWriter(com.google.zxing.MultiFormatWriter) JCommander(com.beust.jcommander.JCommander) BitMatrix(com.google.zxing.common.BitMatrix) EnumMap(java.util.EnumMap)

Example 38 with EnumMap

use of java.util.EnumMap in project zxing by zxing.

the class PDF417WriterTestCase method testDataMatrixImageWriter.

@Test
public void testDataMatrixImageWriter() throws WriterException {
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    hints.put(EncodeHintType.MARGIN, 0);
    int size = 64;
    PDF417Writer writer = new PDF417Writer();
    BitMatrix matrix = writer.encode("Hello Google", BarcodeFormat.PDF_417, size, size, hints);
    assertNotNull(matrix);
    String expected = "X X X X X X X X   X   X   X       X X X X   X   X   X X X X         X X   X   X           X X         X X X X   X X     X     X X X     X X   X           X       X X     X X X X X   X   X   X X X X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X   X X X X         X X   X   X           X X         X X X X   X X     X     X X X     X X   X           X       X X     X X X X X   X   X   X X X X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X   X X X X         X X   X   X           X X         X X X X   X X     X     X X X     X X   X           X       X X     X X X X X   X   X   X X X X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X   X X X X         X X   X   X           X X         X X X X   X X     X     X X X     X X   X           X       X X     X X X X X   X   X   X X X X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X         X         X   X X     X     X X X X X X     X X X           X   X X       X   X X X   X           X X     X     X X X X X X   X   X   X X X       X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X         X         X   X X     X     X X X X X X     X X X           X   X X       X   X X X   X           X X     X     X X X X X X   X   X   X X X       X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X         X         X   X X     X     X X X X X X     X X X           X   X X       X   X X X   X           X X     X     X X X X X X   X   X   X X X       X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X   X   X         X         X   X X     X     X X X X X X     X X X           X   X X       X   X X X   X           X X     X     X X X X X X   X   X   X X X       X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X     X X X X             X   X X X       X       X X       X     X X   X X     X X X X       X X       X X X X X     X     X   X   X   X         X X X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X     X X X X             X   X X X       X       X X       X     X X   X X     X X X X       X X       X X X X X     X     X   X   X   X         X X X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X     X X X X             X   X X X       X       X X       X     X X   X X     X X X X       X X       X X X X X     X     X   X   X   X         X X X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X     X X X X             X   X X X       X       X X       X     X X   X X     X X X X       X X       X X X X X     X     X   X   X   X         X X X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X X X X     X X X X       X         X X       X X     X     X   X     X X X X       X X X X   X       X X       X X         X   X X   X   X X X X     X X X X X   X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X X X X     X X X X       X         X X       X X     X     X   X     X X X X       X X X X   X       X X       X X         X   X X   X   X X X X     X X X X X   X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X X X X     X X X X       X         X X       X X     X     X   X     X X X X       X X X X   X       X X       X X         X   X X   X   X X X X     X X X X X   X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X   X   X X X X     X X X X       X         X X       X X     X     X   X     X X X X       X X X X   X       X X       X X         X   X X   X   X X X X     X X X X X   X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X   X   X X X           X       X X     X       X X X     X       X X X X X X   X X   X     X X     X   X X X   X     X X X X X       X X X   X   X X X     X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X   X   X X X           X       X X     X       X X X     X       X X X X X X   X X   X     X X     X   X X X   X     X X X X X       X X X   X   X X X     X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X   X   X X X           X       X X     X       X X X     X       X X X X X X   X X   X     X X     X   X X X   X     X X X X X       X X X   X   X X X     X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X   X   X X X           X       X X     X       X X X     X       X X X X X X   X X   X     X X     X   X X X   X     X X X X X       X X X   X   X X X     X X         X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X X   X   X X X X   X X     X           X   X       X X X X   X       X   X         X X X X     X           X X X   X       X X   X X X X   X   X X X X X   X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X X   X   X X X X   X X     X           X   X       X X X X   X       X   X         X X X X     X           X X X   X       X X   X X X X   X   X X X X X   X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X X   X   X X X X   X X     X           X   X       X X X X   X       X   X         X X X X     X           X X X   X       X X   X X X X   X   X X X X X   X X     X X X X X X X   X       X   X     X \n" + "X X X X X X X X   X   X   X       X X X X X   X   X X X X   X X     X           X   X       X X X X   X       X   X         X X X X     X           X X X   X       X X   X X X X   X   X X X X X   X X     X X X X X X X   X       X   X     X \n";
    assertEquals(expected, matrix.toString());
}
Also used : EncodeHintType(com.google.zxing.EncodeHintType) BitMatrix(com.google.zxing.common.BitMatrix) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 39 with EnumMap

use of java.util.EnumMap in project zxing by zxing.

the class AbstractBlackBoxTestCase method decode.

private boolean decode(BinaryBitmap source, float rotation, String expectedText, Map<?, ?> expectedMetadata, boolean tryHarder) throws ReaderException {
    String suffix = String.format(" (%srotation: %d)", tryHarder ? "try harder, " : "", (int) rotation);
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    if (tryHarder) {
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    }
    // Try in 'pure' mode mostly to exercise PURE_BARCODE code paths for exceptions;
    // not expected to pass, generally
    Result result = null;
    try {
        Map<DecodeHintType, Object> pureHints = new EnumMap<>(hints);
        pureHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
        result = barcodeReader.decode(source, pureHints);
    } catch (ReaderException re) {
    // continue
    }
    if (result == null) {
        result = barcodeReader.decode(source, hints);
    }
    if (expectedFormat != result.getBarcodeFormat()) {
        log.info(String.format("Format mismatch: expected '%s' but got '%s'%s", expectedFormat, result.getBarcodeFormat(), suffix));
        return false;
    }
    String resultText = result.getText();
    if (!expectedText.equals(resultText)) {
        log.info(String.format("Content mismatch: expected '%s' but got '%s'%s", expectedText, resultText, suffix));
        return false;
    }
    Map<ResultMetadataType, ?> resultMetadata = result.getResultMetadata();
    for (Map.Entry<?, ?> metadatum : expectedMetadata.entrySet()) {
        ResultMetadataType key = ResultMetadataType.valueOf(metadatum.getKey().toString());
        Object expectedValue = metadatum.getValue();
        Object actualValue = resultMetadata == null ? null : resultMetadata.get(key);
        if (!expectedValue.equals(actualValue)) {
            log.info(String.format("Metadata mismatch for key '%s': expected '%s' but got '%s'", key, expectedValue, actualValue));
            return false;
        }
    }
    return true;
}
Also used : DecodeHintType(com.google.zxing.DecodeHintType) ResultMetadataType(com.google.zxing.ResultMetadataType) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 40 with EnumMap

use of java.util.EnumMap in project zxing by zxing.

the class AbstractNegativeBlackBoxTestCase method checkForFalsePositives.

/**
   * Make sure ZXing does NOT find a barcode in the image.
   *
   * @param image The image to test
   * @param rotationInDegrees The amount of rotation to apply
   * @return true if nothing found, false if a non-existent barcode was detected
   */
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
    BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
    LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    try {
        result = getReader().decode(bitmap);
        log.info(String.format("Found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
        return false;
    } catch (ReaderException re) {
    // continue
    }
    // Try "try harder" getMode
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    try {
        result = getReader().decode(bitmap, hints);
        log.info(String.format("Try harder found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
        return false;
    } catch (ReaderException re) {
    // continue
    }
    return true;
}
Also used : LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) DecodeHintType(com.google.zxing.DecodeHintType) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) EnumMap(java.util.EnumMap) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Aggregations

EnumMap (java.util.EnumMap)156 Map (java.util.Map)30 HashMap (java.util.HashMap)23 Collection (java.util.Collection)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)18 DecodeHintType (com.google.zxing.DecodeHintType)17 List (java.util.List)14 IOException (java.io.IOException)12 EncodeHintType (com.google.zxing.EncodeHintType)11 BitMatrix (com.google.zxing.common.BitMatrix)11 Set (java.util.Set)11 Occur (org.apache.lucene.search.BooleanClause.Occur)10 Iterator (java.util.Iterator)9 ImmutableMap (com.google.common.collect.ImmutableMap)7 TreeMap (java.util.TreeMap)7 NoSuchElementException (java.util.NoSuchElementException)6 Bundle (android.os.Bundle)5 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)5 URL (java.net.URL)5