本文整理汇总了Java中java.util.concurrent.CopyOnWriteArrayList类的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArrayList类的具体用法?Java CopyOnWriteArrayList怎么用?Java CopyOnWriteArrayList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CopyOnWriteArrayList类属于java.util.concurrent包,在下文中一共展示了CopyOnWriteArrayList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listCases
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
@DataProvider(name="listProvider", parallel=true)
public static Object[][] listCases() {
final List<Object[]> cases = new LinkedList<>();
cases.add(new Object[] { Collections.emptyList() });
cases.add(new Object[] { new ArrayList<>() });
cases.add(new Object[] { new LinkedList<>() });
cases.add(new Object[] { new Vector<>() });
cases.add(new Object[] { new Stack<>() });
cases.add(new Object[] { new CopyOnWriteArrayList<>() });
cases.add(new Object[] { Arrays.asList() });
List<Integer> l = Arrays.asList(42);
cases.add(new Object[] { new ArrayList<>(l) });
cases.add(new Object[] { new LinkedList<>(l) });
cases.add(new Object[] { new Vector<>(l) });
Stack<Integer> s = new Stack<>(); s.addAll(l);
cases.add(new Object[]{s});
cases.add(new Object[] { new CopyOnWriteArrayList<>(l) });
cases.add(new Object[] { l });
return cases.toArray(new Object[0][cases.size()]);
}
示例2: hasSubscriberForEvent
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public boolean hasSubscriberForEvent(Class<?> eventClass) {
List<Class<?>> eventTypes = lookupAllEventTypes(eventClass);
if (eventTypes != null) {
int countTypes = eventTypes.size();
for (int h = 0; h < countTypes; h++) {
Class<?> clazz = eventTypes.get(h);
CopyOnWriteArrayList<Subscription> subscriptions;
synchronized (this) {
subscriptions = subscriptionsByEventType.get(clazz);
}
if (subscriptions != null && !subscriptions.isEmpty()) {
return true;
}
}
}
return false;
}
示例3: Emitter
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public Emitter(final Point2D origin) {
super();
this.colors = new ArrayList<>();
this.finishedConsumer = new CopyOnWriteArrayList<>();
final EmitterInfo info = this.getClass().getAnnotation(EmitterInfo.class);
this.maxParticles = info.maxParticles();
this.spawnAmount = info.spawnAmount();
this.spawnRate = info.spawnRate();
this.timeToLive = info.emitterTTL();
this.particleMinTTL = info.particleMinTTL();
this.particleMaxTTL = info.particleMaxTTL();
this.particleUpdateDelay = info.particleUpdateRate();
this.particles = new CopyOnWriteArrayList<>();
this.setLocation(origin);
this.activateOnInit = info.activateOnInit();
this.groundRenderable = g -> renderParticles(g, ParticleRenderType.GROUND);
this.overlayRenderable = g -> renderParticles(g, ParticleRenderType.OVERLAY);
}
示例4: addFiles
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
/**
* 创建列表,将多个文件夹下文件以及子文件夹文件加入列表中
* @param folders 文件夹集合
* @return 文件列表
*/
private static CopyOnWriteArrayList<String> addFiles(String[] folders) {
CopyOnWriteArrayList<String> fileList = new CopyOnWriteArrayList<>();
for (String folder : folders) {
File file = new File(folder);
File[] files = file.listFiles();
if (files != null) {
for (File f : files) {
if (!f.isDirectory()) {
fileList.add(f.toString());
} else {
recursion(f.toString(), fileList);
}
}
}
}
return fileList;
}
示例5: getTiles
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
@Override
public List<ITile> getTiles() {
if (this.tileList != null) {
return this.tileList;
}
this.tileList = new CopyOnWriteArrayList<>();
if (this.data == null) {
return this.tileList;
}
this.tiles = new Tile[this.getWidth()][this.getHeight()];
for (int i = 0; i < this.getData().size(); i++) {
final int x = i % this.getWidth();
final int y = i / this.getWidth();
final Tile tile = this.getData().get(i);
tile.setTileCoordinate(new Point(x, y));
this.tileList.add(tile);
this.tiles[x][y] = tile;
}
return this.tileList;
}
示例6: report
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public static void report(CopyOnWriteArrayList<SelectJob> jobs) {
double tps = 0;
long maxTTL = 0;
long minTTL = Integer.MAX_VALUE;
long ttlCount = 0;
long ttlSum = 0;
DecimalFormat df = new DecimalFormat("0.00");
for (SelectJob job : jobs) {
double jobTps = job.getTPS();
if (jobTps > 0) {
tps += job.getTPS();
if (job.getMaxTTL() > maxTTL) {
maxTTL = job.getMaxTTL();
}
if (job.getMinTTL() < minTTL) {
minTTL = job.getMinTTL();
}
ttlCount += job.getValidTTLCount();
ttlSum += job.getValidTTLSum();
}
}
double avgSum =(ttlCount > 0) ? (ttlSum+0.0) / ttlCount : 0;
System.out.println("finishend:" + finshiedCount.get() + " failed:"
+ failedCount.get() + " qps:" + df.format(tps) + ",query time min:"
+ minTTL + "ms,max:" + maxTTL + "ms,avg:" + df.format(avgSum) );
}
示例7: registerType
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
protected List<EventListener<?>> registerType(Class<?> c) {
// ensure that a listener list exists for class c
listeners.putIfAbsent(c, new CopyOnWriteArrayList<EventListener<?>>());
final Set<EventListener<?>> lset = new HashSet<EventListener<?>>();
// make a set of all listeners for every supertype of c
for (Map.Entry<Class<?>,List<EventListener<?>>> e : listeners.entrySet()) {
final Class<?> other = e.getKey();
if (other.isAssignableFrom(c)) {
lset.addAll(e.getValue());
}
}
final List<EventListener<?>> list = listeners.get(c);
list.addAll(lset);
return list;
}
示例8: Effect
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
/**
* Instantiates a new effect.
*
* @param ability
* the ability
* @param targets
* the targets
*/
protected Effect(final Ability ability, final EffectTarget... targets) {
this.appliedConsumer = new CopyOnWriteArrayList<>();
this.ceasedConsumer = new CopyOnWriteArrayList<>();
this.appliances = new ArrayList<>();
this.followUpEffects = new CopyOnWriteArrayList<>();
this.ability = ability;
this.targetPriorityComparator = new EntityDistanceComparator(this.getAbility().getExecutor());
this.duration = ability.getAttributes().getDuration().getCurrentValue();
if (targets == null || targets.length == 0) {
this.effectTargets = new EffectTarget[] { EffectTarget.NONE };
} else {
this.effectTargets = targets;
}
}
示例9: AndroidJSTPConnection
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public AndroidJSTPConnection(String host, int port, boolean usesSSL, Context context) {
mListeners = new CopyOnWriteArrayList<>();
mTaggedCacheCalls = new ConcurrentHashMap<>();
mConnectionState = STATE_NOT_CONNECTED;
mNeedsRestoration = true;
mContext = context;
TCPTransport transport = new TCPTransport(host, port, usesSSL);
mConnection = new Connection(transport, this);
mConnection.addSocketListener(this);
mBroadcastManager = LocalBroadcastManager.getInstance(mContext);
initNetworkReceiver();
}
示例10: two_parallel
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
@Test
public void two_parallel() throws Exception {
List<Integer> result = new CopyOnWriteArrayList<>();
executeParallelObservable("first_parallel", result);
executeParallelObservable("second_parallel", result);
await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(mockTracer), equalTo(2));
assertEquals(10, result.size());
List<MockSpan> spans = mockTracer.finishedSpans();
assertEquals(2, spans.size());
assertNotEquals(spans.get(0).context().traceId(), spans.get(1).context().traceId());
assertNull(mockTracer.scopeManager().active());
}
示例11: cancelRequests
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public void cancelRequests(Context context, Object tag) {
List<CancellationHandler> requestList = requestMap.get(context);
if (requestList != null) {
List<CancellationHandler> cancelledHandler = new CopyOnWriteArrayList<CancellationHandler>();
for (CancellationHandler cancellationHandler : requestList) {
boolean shouldCancel = tag == null;
if (!shouldCancel) {
shouldCancel = tag.equals(cancellationHandler.getTag());
}
if (shouldCancel) {
cancellationHandler.cancel();
cancelledHandler.add(cancellationHandler);
}
}
requestList.removeAll(cancelledHandler);
if (requestList.size() == 0) {
requestMap.remove(context);
}
System.gc();
}
}
示例12: testDiscoverSingleNode
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public void testDiscoverSingleNode() throws Exception {
List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
try (MockTransportService seedTransport = startTransport("seed_node", knownNodes, Version.CURRENT);
MockTransportService discoverableTransport = startTransport("discoverable_node", knownNodes, Version.CURRENT)) {
DiscoveryNode seedNode = seedTransport.getLocalDiscoNode();
DiscoveryNode discoverableNode = discoverableTransport.getLocalDiscoNode();
knownNodes.add(seedTransport.getLocalDiscoNode());
knownNodes.add(discoverableTransport.getLocalDiscoNode());
Collections.shuffle(knownNodes, random());
try (MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
service.start();
service.acceptIncomingRequests();
try (RemoteClusterConnection connection = new RemoteClusterConnection(Settings.EMPTY, "test-cluster",
Arrays.asList(seedNode), service, Integer.MAX_VALUE, n -> true)) {
updateSeedNodes(connection, Arrays.asList(seedNode));
assertTrue(service.nodeConnected(seedNode));
assertTrue(service.nodeConnected(discoverableNode));
assertTrue(connection.assertNoRunningConnections());
}
}
}
}
示例13: PartitaOfflineConsoleView
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
/**
*
* @param model modello partita offline
*/
public PartitaOfflineConsoleView(PartitaOfflineModel model) {
this.listeners = new CopyOnWriteArrayList<>();
this.model = model;
this.model.addObserver(this);
scanner = new Scanner(System.in);
}
示例14: testSubList
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
/**
* sublists contains elements at indexes offset from their base
*/
public void testSubList() {
CopyOnWriteArrayList a = populatedArray(10);
assertTrue(a.subList(1,1).isEmpty());
for (int j = 0; j < 9; ++j) {
for (int i = j ; i < 10; ++i) {
List b = a.subList(j,i);
for (int k = j; k < i; ++k) {
assertEquals(new Integer(k), b.get(k-j));
}
}
}
List s = a.subList(2, 5);
assertEquals(3, s.size());
s.set(2, m1);
assertEquals(a.get(4), m1);
s.clear();
assertEquals(7, a.size());
}
示例15: Tower
import java.util.concurrent.CopyOnWriteArrayList; //导入依赖的package包/类
public Tower(TowerType type, Tile startTile, CopyOnWriteArrayList<Enemy> enemies){
this.type = type;
this.textures = type.textures;
this.range = type.range;
this.cost = type.cost;
this.x = startTile.getX();
this.y = startTile.getY();
this.width = startTile.getWidth();
this.height = startTile.getHeight();
this.enemies = enemies;
this.targeted = false;
this.timeSinceLastShot = 0f;
this.projectiles = new ArrayList<Projectile>();
this.firingSpeed = type.firingSpeed;
this.angle = 0f;
}