Search in sources :

Example 86 with EnumMap

use of java.util.EnumMap in project incubator-weex by apache.

the class OneDReader method doDecode.

/**
 * We're going to examine rows from the middle outward, searching alternately above and below the
 * middle, and farther out each time. rowStep is the number of rows between each successive
 * attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then
 * middle + rowStep, then middle - (2 * rowStep), etc.
 * rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily
 * decided that moving up and down by about 1/16 of the image is pretty good; we try more of the
 * image if "trying harder".
 *
 * @param image The image to decode
 * @param hints Any hints that were requested
 * @return The contents of the decoded barcode
 * @throws NotFoundException Any spontaneous errors which occur
 */
private Result doDecode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException {
    int width = image.getWidth();
    int height = image.getHeight();
    BitArray row = new BitArray(width);
    int middle = height >> 1;
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    int rowStep = Math.max(1, height >> (tryHarder ? 8 : 5));
    int maxLines;
    if (tryHarder) {
        // Look at the whole image, not just the center
        maxLines = height;
    } else {
        // 15 rows spaced 1/32 apart is roughly the middle half of the image
        maxLines = 15;
    }
    for (int x = 0; x < maxLines; x++) {
        // Scanning from the middle out. Determine which row we're looking at next:
        int rowStepsAboveOrBelow = (x + 1) / 2;
        // i.e. is x even?
        boolean isAbove = (x & 0x01) == 0;
        int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
        if (rowNumber < 0 || rowNumber >= height) {
            // Oops, if we run off the top or bottom, stop
            break;
        }
        // Estimate black point for this row and load it:
        try {
            row = image.getBlackRow(rowNumber, row);
        } catch (NotFoundException ignored) {
            continue;
        }
        // handle decoding upside down barcodes.
        for (int attempt = 0; attempt < 2; attempt++) {
            if (attempt == 1) {
                // trying again?
                // reverse the row and continue
                row.reverse();
                // that start on the center line.
                if (hints != null && hints.containsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) {
                    Map<DecodeHintType, Object> newHints = new EnumMap<>(DecodeHintType.class);
                    newHints.putAll(hints);
                    newHints.remove(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
                    hints = newHints;
                }
            }
            try {
                // Look for a barcode
                Result result = decodeRow(rowNumber, row, hints);
                // We found our barcode
                if (attempt == 1) {
                    // But it was upside down, so note that
                    result.putMetadata(ResultMetadataType.ORIENTATION, 180);
                    // And remember to flip the result points horizontally.
                    ResultPoint[] points = result.getResultPoints();
                    if (points != null) {
                        points[0] = new ResultPoint(width - points[0].getX() - 1, points[0].getY());
                        points[1] = new ResultPoint(width - points[1].getX() - 1, points[1].getY());
                    }
                }
                return result;
            } catch (ReaderException re) {
            // continue -- just couldn't decode this row
            }
        }
    }
    throw NotFoundException.getNotFoundInstance();
}
Also used : ResultPoint(com.google.zxing.ResultPoint) DecodeHintType(com.google.zxing.DecodeHintType) NotFoundException(com.google.zxing.NotFoundException) BitArray(com.google.zxing.common.BitArray) EnumMap(java.util.EnumMap) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 87 with EnumMap

use of java.util.EnumMap in project sonar-java by SonarSource.

the class MyClass method compliant.

public void compliant() {
    Map<COLOR, String> enummap = new EnumMap<COLOR, String>(COLOR.class);
    Map<String, String> otherMap = new HashMap<String, String>();
    Map<java.lang.String, String> otherMap2 = new HashMap<>();
    Map otherMap3 = new HashMap();
    Map otherMap4;
    Map otherMap5 = otherMap3;
    otherMap4 = new HashMap<>();
    new HashMap<String, String>();
    int a = 5;
    a = 3;
    foo(moodMapWithNullKey);
    Object o = this.moodMapWithNullKey;
    moodMapWithNullKey.put(COLOR.BLUE, "blue");
    moodMapWithNullKey.get(COLOR.BLUE);
    moodMapWithNullKey.put(null, "null");
}
Also used : HashMap(java.util.HashMap) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 88 with EnumMap

use of java.util.EnumMap in project solution-finder by knewjade.

the class BuildUp method existsValidByOrder.

// block順番で組み立てられる手順が存在するかチェックする
// operationsで使用するミノとblocksが一致していること
public static boolean existsValidByOrder(Field field, Stream<MinoOperationWithKey> operations, List<Piece> pieces, int height, Reachable reachable) {
    EnumMap<Piece, LinkedList<MinoOperationWithKey>> eachBlocks = operations.sequential().collect(() -> new EnumMap<Piece, LinkedList<MinoOperationWithKey>>(Piece.class), (blockLinkedListEnumMap, operationWithKey) -> {
        Piece piece = operationWithKey.getPiece();
        LinkedList<MinoOperationWithKey> operationWithKeys = blockLinkedListEnumMap.computeIfAbsent(piece, b -> new LinkedList<>());
        operationWithKeys.add(operationWithKey);
    }, EnumMap::putAll);
    return existsValidByOrder(field.freeze(height), eachBlocks, pieces, height, reachable, 0);
}
Also used : MinoOperationWithKey(common.datastore.MinoOperationWithKey) Piece(core.mino.Piece) EnumMap(java.util.EnumMap) LinkedList(java.util.LinkedList)

Example 89 with EnumMap

use of java.util.EnumMap in project lavagna by digitalfondue.

the class AnonymousUserFilterTest method testAnonymousUserEnabled.

@Test
public void testAnonymousUserEnabled() throws IOException, ServletException {
    AnonymousUserFilter auf = new AnonymousUserFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Map<Key, String> conf = new EnumMap<>(Key.class);
    conf.put(Key.SETUP_COMPLETE, "true");
    conf.put(Key.ENABLE_ANON_USER, "true");
    when(configurationRepository.findConfigurationFor(Mockito.<Set<Key>>any())).thenReturn(conf);
    when(sessionHandler.isUserAuthenticated(request)).thenReturn(Boolean.FALSE);
    when(users.findUserByName("system", "anonymous")).thenReturn(user);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    auf.init(filterConfig);
    auf.doFilterInternal(request, response, chain);
    Mockito.verify(users).findUserByName("system", "anonymous");
    Mockito.verify(sessionHandler).isUserAuthenticated(request);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.MockFilterChain) EnumMap(java.util.EnumMap) Key(io.lavagna.model.Key) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 90 with EnumMap

use of java.util.EnumMap in project lavagna by digitalfondue.

the class AnonymousUserFilterTest method testAnonymousUserNotEnabled.

@Test
public void testAnonymousUserNotEnabled() throws IOException, ServletException {
    AnonymousUserFilter auf = new AnonymousUserFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Map<Key, String> conf = new EnumMap<>(Key.class);
    conf.put(Key.SETUP_COMPLETE, "true");
    conf.put(Key.ENABLE_ANON_USER, "false");
    when(configurationRepository.findConfigurationFor(Mockito.<Set<Key>>any())).thenReturn(conf);
    when(sessionHandler.isUserAuthenticated(request)).thenReturn(Boolean.TRUE);
    when(sessionHandler.isUserAnonymous(request)).thenReturn(Boolean.TRUE);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    auf.init(filterConfig);
    auf.doFilterInternal(request, response, chain);
    Mockito.verify(sessionHandler).isUserAuthenticated(request);
    Mockito.verify(sessionHandler).isUserAnonymous(request);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.MockFilterChain) EnumMap(java.util.EnumMap) Key(io.lavagna.model.Key) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

EnumMap (java.util.EnumMap)389 Map (java.util.Map)73 ArrayList (java.util.ArrayList)70 List (java.util.List)61 HashMap (java.util.HashMap)60 Test (org.junit.Test)46 IOException (java.io.IOException)38 Collection (java.util.Collection)35 DecodeHintType (com.google.zxing.DecodeHintType)30 HashSet (java.util.HashSet)26 Set (java.util.Set)26 EncodeHintType (com.google.zxing.EncodeHintType)17 File (java.io.File)17 BitMatrix (com.google.zxing.common.BitMatrix)15 BookID (biblemulticonverter.data.BookID)14 Iterator (java.util.Iterator)14 URL (java.net.URL)12 TreeMap (java.util.TreeMap)12 Header (com.jsql.model.bean.util.Header)10 Request (com.jsql.model.bean.util.Request)10