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


Java CopyOnWriteArrayList类代码示例

本文整理汇总了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()]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ListDefaults.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:EventBus.java

示例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);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:21,代码来源:Emitter.java

示例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;
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:23,代码来源:kafkaProducer.java

示例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;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:25,代码来源:TileLayer.java

示例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) );
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:27,代码来源:TestSelectPerf.java

示例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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:DefaultMultiEventListenerSupport.java

示例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;
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:25,代码来源:Effect.java

示例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();
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:17,代码来源:AndroidJSTPConnection.java

示例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());
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:18,代码来源:TracingObserverTest.java

示例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();
    }
}
 
开发者ID:Wangsu-Cloud-Storage,项目名称:wcs-android-sdk,代码行数:22,代码来源:InternalRequest.java

示例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());
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:RemoteClusterConnectionTests.java

示例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);
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-A,代码行数:11,代码来源:PartitaOfflineConsoleView.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:CopyOnWriteArrayListTest.java

示例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;
}
 
开发者ID:imaTowan,项目名称:Towan,代码行数:17,代码来源:Tower.java


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