本文整理匯總了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;
}