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


Java CopyOnWriteArrayList.add方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:OkBus.java

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

示例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;
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:23,代码来源:kafkaProducer.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()+ "|" + md5crypt(f.toString()));
                } else {
                    recursion(f.toString(), fileList);
                }
            }
        }
    }
    return fileList;
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:23,代码来源:UploadData.java

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

示例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);
    }
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:15,代码来源:Solution.java

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

示例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;
}
 
开发者ID:magnusmickelsson,项目名称:pokeraidbot,代码行数:8,代码来源:GymHuntrRaidEventListenerTest.java

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

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

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

示例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);
        }
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:14,代码来源:Device.java

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

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

示例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;
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:10,代码来源:CircuitState.java


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