本文整理汇总了Java中java.util.concurrent.CopyOnWriteArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArrayList.add方法的具体用法?Java CopyOnWriteArrayList.add怎么用?Java CopyOnWriteArrayList.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CopyOnWriteArrayList
的用法示例。
在下文中一共展示了CopyOnWriteArrayList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
public OkBus register(int tag, final Event ev, int thread) {
SparseArray<Event> mEvent = new SparseArray<>();
mEvent.put(thread, ev);
if (mEventList.get(tag) != null) {
mEventList.get(tag).add(mEvent);
} else {
CopyOnWriteArrayList<SparseArray<Event>> mList = new CopyOnWriteArrayList<>();
mList.add(mEvent);
mEventList.put(tag, mList);
}
LogUtils.e("Bus register", tag + " :" + mEventList.get(tag).size());
if (mStickyEventList.get(tag) != null) {//注册时分发粘连事件
final Message msg = new Message();
msg.obj = mStickyEventList.get(tag);
msg.what = tag;
callEvent(msg, ev, thread);
LogUtils.e("mStickyEvent register and onEvent", tag + " :" + mEventList.get(tag).size());
}
return this;
}
示例2: register
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
public <T> void register(@NonNull Class<? extends T> clazz, @NonNull MultiItemView<T> multiItemView) {
CopyOnWriteArrayList<MultiItemView> list = calss2ItemViewMap.get(clazz);
if (list == null) {
list = new CopyOnWriteArrayList<>();
}
int size = itemViewType2itemViewMap.size();
if (multiItemView.haveChild()) {
list.addAll(multiItemView.getChildList());
for (MultiItemView<T> tMultiItemView : multiItemView.getChildList()) {
itemViewType2itemViewMap.put(size, tMultiItemView);
itemViewMap2itemViewType.put(tMultiItemView, size);
size++;
}
} else {
list.add(multiItemView);
itemViewType2itemViewMap.put(size, multiItemView);
itemViewMap2itemViewType.put(multiItemView, size);
}
calss2ItemViewMap.put(clazz, list);
}
示例3: 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;
}
示例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()+ "|" + md5crypt(f.toString()));
} else {
recursion(f.toString(), fileList);
}
}
}
}
return fileList;
}
示例5: testTwoLegendariesInParallel
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
@Test
public void testTwoLegendariesInParallel() throws Exception {
final CopyOnWriteArrayList<String> currentTier5Bosses = new CopyOnWriteArrayList<>();
currentTier5Bosses.add(expectedTier5Boss);
currentTier5Bosses.add("Kyogre");
BotService.currentTier5Bosses = currentTier5Bosses;
clockService.setMockTime(LocalTime.of(18, 0, 0));
final List<String> arguments = GymHuntrRaidEventListener.pokeAlarmArgumentsToCreateRaid(
"T3 Center has a level 5", "Raid will hatch 18:31:10 (54m 32s).", clockService);
assertThat(arguments.size(), is(3));
final Iterator<String> iterator = arguments.iterator();
assertThat(iterator.next(), is("T3 Center"));
assertThat(iterator.next(), is("Egg5"));
assertThat(iterator.next(), is(Utils.printTime(clockService.getCurrentTime()
.plusMinutes(31).plusSeconds(10).plusMinutes(Utils.RAID_DURATION_IN_MINUTES))));
}
示例6: main
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
public static void main(String... args) { //it's correct line
CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList();
list.add("A");
list.add("B");
list.add("C");
list.remove("B");
List<String> collection = Arrays.asList(new String[]{"B", "C", "D", "B"});
list.addAllAbsent(collection);
for (String string : list) {
System.out.println(string);
}
}
示例7: testToArray_ArrayStoreException
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* toArray throws an ArrayStoreException when the given array
* can not store the objects inside the list
*/
public void testToArray_ArrayStoreException() {
CopyOnWriteArrayList c = new CopyOnWriteArrayList();
c.add("zfasdfsdf");
c.add("asdadasd");
try {
c.toArray(new Long[5]);
shouldThrow();
} catch (ArrayStoreException success) {}
}
示例8: setUp
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
clockService = new ClockService();
final CopyOnWriteArrayList<String> currentTier5Bosses = new CopyOnWriteArrayList<>();
currentTier5Bosses.add(expectedTier5Boss);
BotService.currentTier5Bosses = currentTier5Bosses;
}
示例9: recursion
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* 辅助函数,读取子文件夹中文件
* @param root 文件夹名
* @param fileList 文件列表
*/
private static void recursion(String root, CopyOnWriteArrayList<String> fileList) {
File file = new File(root);
File[] subFile = file.listFiles();
if (subFile != null) {
for (int i = 0; i < subFile.length; i++) {
if (subFile[i].isDirectory()) {
recursion(subFile[i].getAbsolutePath(), fileList);
} else {
fileList.add(subFile[i].getAbsolutePath());
}
}
}
}
示例10: recursion
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* 辅助函数,读取子文件夹中文件
* @param root 文件夹名
* @param fileList 文件列表
*/
private static void recursion(String root, CopyOnWriteArrayList<String> fileList) {
File file = new File(root);
File[] subFile = file.listFiles();
if (subFile != null) {
for (int i = 0; i < subFile.length; i++) {
if (subFile[i].isDirectory()) {
recursion(subFile[i].getAbsolutePath(), fileList);
} else {
fileList.add(subFile[i].getAbsolutePath()+ "|" + md5crypt(subFile[i].getAbsolutePath()));
}
}
}
}
示例11: testLastIndexOf2
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* lastIndexOf returns the index from the given starting point
*/
public void testLastIndexOf2() {
CopyOnWriteArrayList full = populatedArray(3);
full.add(one);
full.add(three);
assertEquals(3, full.lastIndexOf(one, 4));
assertEquals(-1, full.lastIndexOf(three, 3));
}
示例12: addCharacteristicsChangedListener
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
@Override
public void addCharacteristicsChangedListener(UUID characteristicsUUID, CharacteristicsChangedListener listener) {
synchronized (lock) {
CopyOnWriteArrayList<CharacteristicsChangedListener> list = changeListeners.get(characteristicsUUID);
if (list == null) {
list = new CopyOnWriteArrayList<>();
list.add(listener);
changeListeners.put(characteristicsUUID, list);
} else if (!list.contains(listener)) {
list.add(listener);
}
}
}
示例13: populatedArray
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
static CopyOnWriteArrayList<Integer> populatedArray(Integer[] elements) {
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<>();
assertTrue(a.isEmpty());
for (int i = 0; i < elements.length; i++)
a.add(elements[i]);
assertFalse(a.isEmpty());
assertEquals(elements.length, a.size());
return a;
}
示例14: testAddIndex
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* adding at an index places it in the indicated index
*/
public void testAddIndex() {
CopyOnWriteArrayList full = populatedArray(3);
full.add(0, m1);
assertEquals(4, full.size());
assertEquals(m1, full.get(0));
assertEquals(zero, full.get(1));
full.add(2, m2);
assertEquals(5, full.size());
assertEquals(m2, full.get(2));
assertEquals(two, full.get(4));
}
示例15: markComponentAsDirty
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
public void markComponentAsDirty(Component comp) {
try {
dirtyComponents.add(comp);
} catch (RuntimeException e) {
CopyOnWriteArrayList<Component> set = new CopyOnWriteArrayList<Component>();
set.add(comp);
dirtyComponents = set;
}
}