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();
}
}
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));
}
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());
}
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;
}
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;
}
Aggregations