Search in sources :

Example 91 with EnumMap

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

the class RememberMeFilterTest method testUnconfiguredSetup.

@Test
public void testUnconfiguredSetup() throws IOException, ServletException {
    RememberMeFilter rmf = new RememberMeFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Map<Key, String> conf = new EnumMap<>(Key.class);
    conf.put(Key.SETUP_COMPLETE, "false");
    when(configurationRepository.findConfigurationFor(Mockito.<Set<Key>>any())).thenReturn(conf);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    rmf.init(filterConfig);
    rmf.doFilterInternal(request, response, chain);
}
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 92 with EnumMap

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

the class RememberMeFilterTest method testRememberMeTokenNotExists.

@Test
public void testRememberMeTokenNotExists() throws IOException, ServletException {
    RememberMeFilter rmf = new RememberMeFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(AUTH_KEY, false);
    Cookie cookie = new Cookie(CookieNames.getRememberMeCookieName(), "2/056a8421-7448-4753-a932-13dc7e4cd510");
    request.setCookies(cookie);
    Map<Key, String> conf = new EnumMap<>(Key.class);
    conf.put(Key.SETUP_COMPLETE, "true");
    when(userRepository.rememberMeTokenExists(Mockito.eq(2), Mockito.eq("056a8421-7448-4753-a932-13dc7e4cd510"))).thenReturn(Boolean.FALSE);
    when(configurationRepository.findConfigurationFor(Mockito.<Set<Key>>any())).thenReturn(conf);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    rmf.init(filterConfig);
    rmf.doFilterInternal(request, response, chain);
    Mockito.verify(userRepository).rememberMeTokenExists(Mockito.eq(2), Mockito.eq("056a8421-7448-4753-a932-13dc7e4cd510"));
}
Also used : Cookie(javax.servlet.http.Cookie) 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 93 with EnumMap

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

the class MinoRotation method createLeftMap.

private EnumMap<Piece, EnumMap<Rotate, Pattern>> createLeftMap() {
    EnumMap<Piece, EnumMap<Rotate, Pattern>> blockMap = new EnumMap<>(Piece.class);
    for (Piece piece : Piece.values()) {
        EnumMap<Rotate, Pattern> rotateMap = new EnumMap<>(Rotate.class);
        for (Rotate rotate : Rotate.values()) {
            Pattern pattern = getPattern(piece, rotate, rotate.getLeftRotate());
            rotateMap.put(rotate, pattern);
        }
        blockMap.put(piece, rotateMap);
    }
    return blockMap;
}
Also used : Piece(core.mino.Piece) EnumMap(java.util.EnumMap)

Example 94 with EnumMap

use of java.util.EnumMap in project controller by opendaylight.

the class DomInmemoryDataBrokerModule method createInstance.

@Override
public java.lang.AutoCloseable createInstance() {
    // Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
    DOMStore operStore = getOperationalDataStoreDependency();
    if (operStore == null) {
        // we will default to InMemoryDOMDataStore creation
        operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
    }
    DOMStore configStore = getConfigDataStoreDependency();
    if (configStore == null) {
        // we will default to InMemoryDOMDataStore creation
        configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
    }
    final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
    datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
    datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
    /*
         * We use an executor for commit ListenableFuture callbacks that favors reusing available
         * threads over creating new threads at the expense of execution time. The assumption is
         * that most ListenableFuture callbacks won't execute a lot of business logic where we want
         * it to run quicker - many callbacks will likely just handle error conditions and do
         * nothing on success. The executor queue capacity is bounded and, if the capacity is
         * reached, subsequent submitted tasks will block the caller.
         */
    ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(), "CommitFutures", SerializedDOMDataBroker.class);
    final List<AbstractMXBean> mBeans = Lists.newArrayList();
    final DurationStatisticsTracker commitStatsTracker;
    /*
         * We use a single-threaded executor for commits with a bounded queue capacity. If the
         * queue capacity is reached, subsequent commit tasks will be rejected and the commits will
         * fail. This is done to relieve back pressure. This should be an extreme scenario - either
         * there's deadlock(s) somewhere and the controller is unstable or some rogue component is
         * continuously hammering commits too fast or the controller is just over-capacity for the
         * system it's running on.
         */
    ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(getMaxDataBrokerCommitQueueSize(), "WriteTxCommit", SerializedDOMDataBroker.class);
    SerializedDOMDataBroker sdb = new SerializedDOMDataBroker(datastores, new DeadlockDetectingListeningExecutorService(commitExecutor, TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, listenableFutureExecutor));
    commitStatsTracker = sdb.getCommitStatsTracker();
    final AbstractMXBean commitExecutorStatsMXBean = ThreadExecutorStatsMXBeanImpl.create(commitExecutor, "CommitExecutorStats", JMX_BEAN_TYPE, null);
    if (commitExecutorStatsMXBean != null) {
        mBeans.add(commitExecutorStatsMXBean);
    }
    if (commitStatsTracker != null) {
        final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(commitStatsTracker, JMX_BEAN_TYPE);
        commitStatsMXBean.registerMBean();
        mBeans.add(commitStatsMXBean);
    }
    final AbstractMXBean commitFutureStatsMXBean = ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor, "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
    if (commitFutureStatsMXBean != null) {
        mBeans.add(commitFutureStatsMXBean);
    }
    sdb.setCloseable(() -> mBeans.forEach(AbstractMXBean::unregisterMBean));
    return sdb;
}
Also used : AbstractMXBean(org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean) DOMStore(org.opendaylight.controller.sal.core.spi.data.DOMStore) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DurationStatisticsTracker(org.opendaylight.yangtools.util.DurationStatisticsTracker) EnumMap(java.util.EnumMap) SerializedDOMDataBroker(org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) CommitStatsMXBeanImpl(org.opendaylight.controller.md.sal.dom.broker.impl.jmx.CommitStatsMXBeanImpl)

Example 95 with EnumMap

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

the class PieceCounter method getEnumMap.

public EnumMap<Piece, Integer> getEnumMap() {
    EnumMap<Piece, Integer> map = new EnumMap<>(Piece.class);
    for (int index = 0, max = Piece.getSize(); index < max; index++) {
        Piece piece = Piece.getBlock(index);
        long size = (counter >>> 8 * index) & 0xff;
        if (size != 0)
            map.put(piece, (int) size);
    }
    return map;
}
Also used : Piece(core.mino.Piece) EnumMap(java.util.EnumMap)

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