當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。