本文整理汇总了Java中java.util.AbstractCollection.add方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractCollection.add方法的具体用法?Java AbstractCollection.add怎么用?Java AbstractCollection.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.AbstractCollection
的用法示例。
在下文中一共展示了AbstractCollection.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_addLjava_lang_Object
import java.util.AbstractCollection; //导入方法依赖的package包/类
/**
* @tests java.util.AbstractCollection#add(java.lang.Object)
*/
public void test_addLjava_lang_Object() {
AbstractCollection<Object> ac = new AbstractCollection<Object>() {
@Override
public Iterator<Object> iterator() {
fail("iterator should not get called");
return null;
}
@Override
public int size() {
fail("size should not get called");
return 0;
}
};
try {
ac.add(null);
} catch (UnsupportedOperationException e) {
}
}
示例2: test_addLjava_lang_Object
import java.util.AbstractCollection; //导入方法依赖的package包/类
/**
* @tests java.util.AbstractCollection#add(java.lang.Object)
*/
public void test_addLjava_lang_Object() {
AbstractCollection<Object> ac = new AbstractCollection<Object>() {
@Override
public Iterator<Object> iterator() {
fail("iterator should not get called");
return null;
}
@Override
public int size() {
fail("size should not get called");
return 0;
}
};
try {
ac.add(null);
} catch (UnsupportedOperationException e) {
}
}
示例3: read
import java.util.AbstractCollection; //导入方法依赖的package包/类
public static AbstractCollection<String> read(String filepath, AbstractCollection<String> collection, Callable<String> function)
{
File file = new File(filepath);
// if file does not exist, output error and return null
if (!file.exists())
{
logger.error("file at " + filepath + " does not exist");
return null;
}
// if file cannot be read, output error and return null
if (!file.canRead())
{
logger.error("cannot read file at " + filepath);
return null;
}
// create buffered reader
try (BufferedReader br = new BufferedReader(new FileReader(file)))
{
// read through the file, line by line
String line;
while ((line = br.readLine()) != null)
{
String item = function.call(line);
if (item != null)
{
collection.add(item);
}
}
} catch (Exception e)
{
logger.error("unable to read file");
}
return collection;
}
示例4: makeCollection
import java.util.AbstractCollection; //导入方法依赖的package包/类
/**
* Creates a mutable {@link ArrayList} instance containing the given elements.
*
* @param source Iterable
* @return Collection
*/
protected AbstractCollection<S> makeCollection(Iterable<S> source) {
AbstractCollection<S> result = new ArrayList<S>();
for (S element : source) {
try {
result.add(element);
}
catch (Exception o_O) {
throw new RuntimeException(o_O);
}
}
return result;
}