• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Builder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Builder类属于com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap包,在下文中一共展示了Builder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setMaxInMemory

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
public void setMaxInMemory(int newInMemory) {
    this.maxInMemory = newInMemory;
    Map<Object, CacheLine<V>> oldmap = this.memoryTable;

    if (newInMemory > 0) {
        if (this.memoryTable instanceof ConcurrentLinkedHashMap<?, ?>) {
            ((ConcurrentLinkedHashMap<?, ?>) this.memoryTable).setCapacity(newInMemory);
            return;
        } else {
            this.memoryTable =new Builder<Object, CacheLine<V>>()
                .maximumWeightedCapacity(newInMemory)
                .build();
        }
    } else {
        this.memoryTable = new ConcurrentHashMap<Object, CacheLine<V>>();
    }

    this.memoryTable.putAll(oldmap);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:20,代码来源:UtilCache.java


示例2: concurrency

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder")
public void concurrency(Builder<Integer, Integer> builder) {
  List<Integer> keys = newArrayList();
  Random random = new Random();
  for (int i = 0; i < iterations; i++) {
    keys.add(random.nextInt(iterations / 100));
  }
  final List<List<Integer>> sets = shuffle(threads, keys);
  final ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(capacity())
      .concurrencyLevel(threads)
      .build();
  executeWithTimeOut(map, new Callable<Long>() {
    @Override public Long call() throws Exception {
      return timeTasks(threads, new Thrasher(map, sets));
    }
  });
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:19,代码来源:MultiThreadedTest.java


示例3: weightedConcurrency

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder")
public void weightedConcurrency(Builder<Integer, List<Integer>> builder) {
  final ConcurrentLinkedHashMap<Integer, List<Integer>> map = builder
      .weigher(Weighers.<Integer>list())
      .maximumWeightedCapacity(threads)
      .concurrencyLevel(threads)
      .build();
  final Queue<List<Integer>> values = new ConcurrentLinkedQueue<List<Integer>>();
  for (int i = 1; i <= threads; i++) {
    Integer[] array = new Integer[i];
    Arrays.fill(array, Integer.MIN_VALUE);
    values.add(Arrays.asList(array));
  }
  executeWithTimeOut(map, new Callable<Long>() {
    @Override public Long call() throws Exception {
      return timeTasks(threads, new Runnable() {
        @Override public void run() {
          List<Integer> value = values.poll();
          for (int i = 0; i < iterations; i++) {
            map.put(i % 10, value);
          }
        }
      });
    }
  });
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:27,代码来源:MultiThreadedTest.java


示例4: evict_weighted

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder")
public void evict_weighted(Builder<Integer, Collection<Integer>> builder) {
  ConcurrentLinkedHashMap<Integer, Collection<Integer>> map = builder
      .weigher(Weighers.<Integer>collection())
      .maximumWeightedCapacity(10)
      .build();

  map.put(1, asList(1, 2));
  map.put(2, asList(3, 4, 5, 6, 7));
  map.put(3, asList(8, 9, 10));
  assertThat(map.weightedSize(), is(10L));

  // evict (1)
  map.put(4, asList(11));
  assertThat(map.containsKey(1), is(false));
  assertThat(map.weightedSize(), is(9L));

  // evict (2, 3)
  map.put(5, asList(12, 13, 14, 15, 16, 17, 18, 19, 20));
  assertThat(map.weightedSize(), is(10L));

  assertThat(map, is(valid()));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:24,代码来源:EvictionTest.java


示例5: evict_lru

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder")
public void evict_lru(Builder<Integer, Integer> builder) {
  ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(10)
      .build();
  warmUp(map, 0, 10);
  checkContainsInOrder(map, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);

  // re-order
  checkReorder(map, asList(0, 1, 2), 3, 4, 5, 6, 7, 8, 9, 0, 1, 2);

  // evict 3, 4, 5
  checkEvict(map, asList(10, 11, 12), 6, 7, 8, 9, 0, 1, 2, 10, 11, 12);

  // re-order
  checkReorder(map, asList(6, 7, 8), 9, 0, 1, 2, 10, 11, 12, 6, 7, 8);

  // evict 9, 0, 1
  checkEvict(map, asList(13, 14, 15), 2, 10, 11, 12, 6, 7, 8, 13, 14, 15);

  assertThat(map, is(valid()));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:23,代码来源:EvictionTest.java


示例6: evict_efficiency

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void evict_efficiency() {
  Map<String, String> expected = new CacheFactory()
      .maximumCapacity((int) capacity())
      .makeCache(CacheType.LinkedHashMap_Lru_Sync);
  Map<String, String> actual = new Builder<String, String>()
      .maximumWeightedCapacity(capacity())
      .build();

  Generator generator = new ScrambledZipfianGenerator(10 * capacity());
  List<String> workingSet = createWorkingSet(generator, 10 * (int) capacity());

  EfficiencyRun runExpected = determineEfficiency(expected, workingSet);
  EfficiencyRun runActual = determineEfficiency(actual, workingSet);

  String reason = String.format("Expected [%s] but was [%s]", runExpected, runActual);
  assertThat(reason, runActual.hitCount, is(runExpected.hitCount));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:19,代码来源:EvictionTest.java


示例7: providesBuilder

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
/** Provides a builder with the capacity set. */
@DataProvider(name = "builder")
public Object[][] providesBuilder() {
  return new Object[][] {{
    new Builder<Object, Object>().maximumWeightedCapacity(capacity())
  }};
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:8,代码来源:AbstractTest.java


示例8: newGuarded

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
/** Creates a map that fails if an eviction occurs. */
protected <K, V> ConcurrentLinkedHashMap<K, V> newGuarded() {
  EvictionListener<K, V> guardingListener = guardingListener();
  return new Builder<K, V>()
      .maximumWeightedCapacity(capacity())
      .listener(guardingListener)
      .build();
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:9,代码来源:AbstractTest.java


示例9: newGuardedWeightedMap

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
private <K, V> ConcurrentLinkedHashMap<K, Iterable<V>> newGuardedWeightedMap() {
  EvictionListener<K, Iterable<V>> guardingListener = guardingListener();
  return new Builder<K, Iterable<V>>()
      .maximumWeightedCapacity(capacity())
      .weigher(Weighers.<V>iterable())
      .listener(guardingListener)
      .build();
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:9,代码来源:AbstractTest.java


示例10: serialize_withCustomSettings

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void serialize_withCustomSettings() {
  Map<Integer, Collection<Integer>> map = new Builder<Integer, Collection<Integer>>()
      .listener(new SerializableEvictionListener())
      .weigher(Weighers.<Integer>collection())
      .maximumWeightedCapacity(500)
      .initialCapacity(100)
      .concurrencyLevel(32)
      .build();
  map.put(1, singletonList(2));
  assertThat(map, is(reserializable()));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:13,代码来源:ConcurrentMapTest.java


示例11: checkDecreasedCapacity

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
private void checkDecreasedCapacity(long newMaxCapacity) {
  ConcurrentLinkedHashMap<Integer, Integer> map = new Builder<Integer, Integer>()
      .maximumWeightedCapacity(capacity())
      .listener(listener)
      .build();
  warmUp(map, 0, capacity());
  map.setCapacity(newMaxCapacity);

  assertThat(map, is(valid()));
  assertThat(map.size(), is(equalTo((int) newMaxCapacity)));
  assertThat(map.capacity(), is(equalTo(newMaxCapacity)));
  verify(listener, times((int) (capacity() - newMaxCapacity))).onEviction(anyInt(), anyInt());
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:14,代码来源:EvictionTest.java


示例12: evict_listenerFails

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder", expectedExceptions = IllegalStateException.class)
public void evict_listenerFails(Builder<Integer, Integer> builder) {
  doThrow(new IllegalStateException()).when(listener).onEviction(anyInt(), anyInt());
  ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(0)
      .listener(listener)
      .build();
  try {
    warmUp(map, 0, capacity());
  } finally {
    assertThat(map, is(valid()));
  }
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:14,代码来源:EvictionTest.java


示例13: evict_alwaysDiscard

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void evict_alwaysDiscard() {
  ConcurrentLinkedHashMap<Integer, Integer> map = new Builder<Integer, Integer>()
      .maximumWeightedCapacity(0)
      .listener(listener)
      .build();
  warmUp(map, 0, 100);

  assertThat(map, is(valid()));
  verify(listener, times(100)).onEviction(anyInt(), anyInt());
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:12,代码来源:EvictionTest.java


示例14: evict

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void evict() {
  ConcurrentLinkedHashMap<Integer, Integer> map = new Builder<Integer, Integer>()
      .maximumWeightedCapacity(10)
      .listener(listener)
      .build();
  warmUp(map, 0, 20);

  assertThat(map, is(valid()));
  assertThat(map.size(), is(10));
  assertThat(map.weightedSize(), is(10L));
  verify(listener, times(10)).onEviction(anyInt(), anyInt());
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:14,代码来源:EvictionTest.java


示例15: evict_maximumCapacity

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder")
public void evict_maximumCapacity(Builder<Integer, Integer> builder) {
  ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(MAXIMUM_CAPACITY)
      .build();
  map.put(1, 2);
  map.capacity.set(MAXIMUM_CAPACITY);
  map.weightedSize.set(MAXIMUM_CAPACITY);

  map.put(2, 3);
  assertThat(map.weightedSize(), is(MAXIMUM_CAPACITY));
  assertThat(map, is(equalTo(singletonMap(2, 3))));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:14,代码来源:EvictionTest.java


示例16: evict_alreadyRemoved

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void evict_alreadyRemoved() throws Exception {
  final ConcurrentLinkedHashMap<Integer, Integer> map = new Builder<Integer, Integer>()
      .maximumWeightedCapacity(1)
      .listener(listener)
      .build();
  map.put(0, 0);
  map.evictionLock.lock();
  try {
    Node<Integer, Integer> node = map.data.get(0);
    checkStatus(map, node, ALIVE);
    new Thread() {
      @Override public void run() {
        map.put(1, 1);
        assertThat(map.remove(0), is(0));
      }
    }.start();
    await().untilCall(to((Map<?, ?>) map).containsKey(0), is(false));
    checkStatus(map, node, RETIRED);
    map.drainBuffers();

    checkStatus(map, node, DEAD);
    assertThat(map.containsKey(1), is(true));
    verify(listener, never()).onEviction(anyInt(), anyInt());
  } finally {
    map.evictionLock.unlock();
  }
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:29,代码来源:EvictionTest.java


示例17: beforeMemoryLeakTest

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@BeforeMethod
public void beforeMemoryLeakTest() {
  ThreadFactory threadFactory = new ThreadFactoryBuilder()
      .setPriority(Thread.MAX_PRIORITY)
      .setDaemon(true)
      .build();
  statusExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory);
  statusExecutor.scheduleAtFixedRate(newStatusTask(),
      statusInterval, statusInterval, SECONDS);
  map = new Builder<Long, Long>()
      .maximumWeightedCapacity(threads)
      .build();
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:14,代码来源:MemoryLeakTest.java


示例18: listener_withCustom

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test
public void listener_withCustom() {
  Builder<Integer, Integer> builder = new Builder<Integer, Integer>()
      .maximumWeightedCapacity(capacity())
      .listener(listener);
  assertThat(builder.build().listener, is(sameInstance(listener)));
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:8,代码来源:BuilderTest.java


示例19: put_withNegativeWeight

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder", expectedExceptions = IllegalArgumentException.class)
public void put_withNegativeWeight(Builder<Integer, Integer> builder) {
  ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(capacity())
      .weigher(weigher).build();
  when(weigher.weightOf(anyInt())).thenReturn(-1);
  map.put(1, 2);
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:9,代码来源:WeigherTest.java


示例20: put_withZeroWeight

import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; //导入依赖的package包/类
@Test(dataProvider = "builder", expectedExceptions = IllegalArgumentException.class)
public void put_withZeroWeight(Builder<Integer, Integer> builder) {
  ConcurrentLinkedHashMap<Integer, Integer> map = builder
      .maximumWeightedCapacity(capacity())
      .weigher(weigher).build();
  doReturn(0).when(weigher).weightOf(anyInt());
  map.put(1, 2);
}
 
开发者ID:ben-manes,项目名称:concurrentlinkedhashmap,代码行数:9,代码来源:WeigherTest.java



注:本文中的com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OracleResultSet类代码示例发布时间:2022-05-23
下一篇:
Java BegunBy类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap