Examples of MutableInt


Examples of org.apache.commons.lang.mutable.MutableInt

        xpath.addNamespace("m1", "http://services.samples/xsd2");
        return xpath;
    }

    private void test(ValidateMediator validate, MessageContext synCtx, boolean expectFail) {
        final MutableInt onFailInvoked = new MutableInt();
        TestMediator testMediator = new TestMediator();
        testMediator.setHandler(
                new TestMediateHandler() {
                    public void handle(MessageContext synCtx) {
                        onFailInvoked.setValue(1);
                    }
                });
        // set dummy mediator to be called on fail
        validate.addChild(testMediator);
        validate.mediate(synCtx);
        if (expectFail) {
            assertTrue("Expected ValidateMediator to trigger fail sequence",
                    onFailInvoked.intValue() == 1);
        } else {
            assertTrue("ValidateMediator unexpectedly triggered fail sequence",
                    onFailInvoked.intValue() == 0);
        }
    }
View Full Code Here

Examples of org.apache.commons.lang.mutable.MutableInt

    for (Entry<ByteBuffer,
        ? extends Collection<LoadQueueItem>> e: regionGroups.asMap().entrySet()) {
      final Collection<LoadQueueItem> lqis =  e.getValue();
      HashMap<byte[], MutableInt> filesMap = new HashMap<byte[], MutableInt>();
      for (LoadQueueItem lqi: lqis) {
        MutableInt count = filesMap.get(lqi.family);
        if (count == null) {
          count = new MutableInt();
          filesMap.put(lqi.family, count);
        }
        count.increment();
        if (count.intValue() > maxFilesPerRegionPerFamily) {
          LOG.error("Trying to load more than " + maxFilesPerRegionPerFamily
            + " hfiles to family " + Bytes.toStringBinary(lqi.family)
            + " of region with start key "
            + Bytes.toStringBinary(e.getKey()));
          return false;
View Full Code Here

Examples of org.apache.commons.lang.mutable.MutableInt

/** <p>Tests {@link CachingRecommender}.</p> */
public final class CachingRecommenderTest extends TasteTestCase {

  @Test
  public void testRecommender() throws Exception {
    MutableInt recommendCount = new MutableInt();
    Recommender mockRecommender = new MockRecommender(recommendCount);

    Recommender cachingRecommender = new CachingRecommender(mockRecommender);
    cachingRecommender.recommend(1, 1);
    assertEquals(1, recommendCount.intValue());
    cachingRecommender.recommend(2, 1);
    assertEquals(2, recommendCount.intValue());
    cachingRecommender.recommend(1, 1);
    assertEquals(2, recommendCount.intValue());
    cachingRecommender.recommend(2, 1);
    assertEquals(2, recommendCount.intValue());
    cachingRecommender.refresh(null);
    cachingRecommender.recommend(1, 1);
    assertEquals(3, recommendCount.intValue());
    cachingRecommender.recommend(2, 1);
    assertEquals(4, recommendCount.intValue());
    cachingRecommender.recommend(3, 1);
    assertEquals(5, recommendCount.intValue());

    // Results from this recommend() method can be cached...
    IDRescorer rescorer = NullRescorer.getItemInstance();
    cachingRecommender.refresh(null);
    cachingRecommender.recommend(1, 1, rescorer);
    assertEquals(6, recommendCount.intValue());
    cachingRecommender.recommend(2, 1, rescorer);
    assertEquals(7, recommendCount.intValue());
    cachingRecommender.recommend(1, 1, rescorer);
    assertEquals(7, recommendCount.intValue());
    cachingRecommender.recommend(2, 1, rescorer);
    assertEquals(7, recommendCount.intValue());

    // until you switch Rescorers
    cachingRecommender.recommend(1, 1, null);
    assertEquals(8, recommendCount.intValue());
    cachingRecommender.recommend(2, 1, null);
    assertEquals(9, recommendCount.intValue());

    cachingRecommender.refresh(null);
    cachingRecommender.estimatePreference(1, 1);
    assertEquals(10, recommendCount.intValue());
    cachingRecommender.estimatePreference(1, 2);
    assertEquals(11, recommendCount.intValue());
    cachingRecommender.estimatePreference(1, 2);
    assertEquals(11, recommendCount.intValue());
  }
View Full Code Here

Examples of org.apache.commons.lang.mutable.MutableInt

   * Submit a log split task to executor service
   * @param curTask
   * @param curTaskZKVersion
   */
  void submitTask(final String curTask, final int curTaskZKVersion, final int reportPeriod) {
    final MutableInt zkVersion = new MutableInt(curTaskZKVersion);

    CancelableProgressable reporter = new CancelableProgressable() {
      private long last_report_at = 0;

      @Override
      public boolean progress() {
        long t = EnvironmentEdgeManager.currentTimeMillis();
        if ((t - last_report_at) > reportPeriod) {
          last_report_at = t;
          int latestZKVersion =
              attemptToOwnTask(false, watcher, serverName, curTask, zkVersion.intValue());
          if (latestZKVersion < 0) {
            LOG.warn("Failed to heartbeat the task" + curTask);
            return false;
          }
          zkVersion.setValue(latestZKVersion);
        }
        return true;
      }
    };
   
View Full Code Here

Examples of org.apache.commons.lang.mutable.MutableInt

    for (Entry<ByteBuffer,
        ? extends Collection<LoadQueueItem>> e: regionGroups.asMap().entrySet()) {
      final Collection<LoadQueueItem> lqis =  e.getValue();
      HashMap<byte[], MutableInt> filesMap = new HashMap<byte[], MutableInt>();
      for (LoadQueueItem lqi: lqis) {
        MutableInt count = filesMap.get(lqi.family);
        if (count == null) {
          count = new MutableInt();
          filesMap.put(lqi.family, count);
        }
        count.increment();
        if (count.intValue() > maxFilesPerRegionPerFamily) {
          LOG.error("Trying to load more than " + maxFilesPerRegionPerFamily
            + " hfiles to family " + Bytes.toStringBinary(lqi.family)
            + " of region with start key "
            + Bytes.toStringBinary(e.getKey()));
          return false;
View Full Code Here

Examples of org.apache.commons.lang.mutable.MutableInt

    for (Entry<ByteBuffer,
        ? extends Collection<LoadQueueItem>> e: regionGroups.asMap().entrySet()) {
      final Collection<LoadQueueItem> lqis =  e.getValue();
      HashMap<byte[], MutableInt> filesMap = new HashMap<byte[], MutableInt>();
      for (LoadQueueItem lqi: lqis) {
        MutableInt count = filesMap.get(lqi.family);
        if (count == null) {
          count = new MutableInt();
          filesMap.put(lqi.family, count);
        }
        count.increment();
        if (count.intValue() > maxFilesPerRegionPerFamily) {
          LOG.error("Trying to load more than " + maxFilesPerRegionPerFamily
            + " hfiles to family " + Bytes.toStringBinary(lqi.family)
            + " of region with start key "
            + Bytes.toStringBinary(e.getKey()));
          return false;
View Full Code Here

Examples of org.apache.commons.lang3.mutable.MutableInt

     */
    public static <T> T mode(T... items) {
        if (ArrayUtils.isNotEmpty(items)) {
            HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(items.length);
            for (T t : items) {
                MutableInt count = occurrences.get(t);
                if (count == null) {
                    occurrences.put(t, new MutableInt(1));
                } else {
                    count.increment();
                }
            }
            T result = null;
            int max = 0;
            for (Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
View Full Code Here

Examples of org.apache.commons.lang3.mutable.MutableInt

     */
    public static <T> T mode(final T... items) {
        if (ArrayUtils.isNotEmpty(items)) {
            final HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(items.length);
            for (final T t : items) {
                final MutableInt count = occurrences.get(t);
                if (count == null) {
                    occurrences.put(t, new MutableInt(1));
                } else {
                    count.increment();
                }
            }
            T result = null;
            int max = 0;
            for (final Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
View Full Code Here

Examples of org.apache.commons.lang3.mutable.MutableInt

     */
    public static <T> T mode(final T... items) {
        if (ArrayUtils.isNotEmpty(items)) {
            final HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(items.length);
            for (final T t : items) {
                final MutableInt count = occurrences.get(t);
                if (count == null) {
                    occurrences.put(t, new MutableInt(1));
                } else {
                    count.increment();
                }
            }
            T result = null;
            int max = 0;
            for (final Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
View Full Code Here

Examples of org.apache.commons.lang3.mutable.MutableInt

        if (isEmpty(array) || isEmpty(values)) {
            return clone(array);
        }
        final HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(values.length);
        for (final T v : values) {
            final MutableInt count = occurrences.get(v);
            if (count == null) {
                occurrences.put(v, new MutableInt(1));
            } else {
                count.increment();
            }
        }
        final BitSet toRemove = new BitSet();
        for (final Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
            final T v = e.getKey();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.