当前位置: 首页>>代码示例>>Java>>正文


Java Builder类代码示例

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


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


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