public class StorageResource
extends java.lang.Object
StorageResource
class stores any number of String
objects and
allows access to these stored values one at a time, using the method data
. These
strings can then be iterated over in the order they were added using a for
loop.
This class mirrors an ArrayList<String>
in some functionality, but is simpler
to use and fits the Duke/Coursersa model of creating and using iterables.
Example usage:
FileResource fr = new FileResource(); StorageResource store = new StorageResource(); for (String s : fr.words()) { store.add(s); } // can process store here, e.g., // get number of strings stored int x = store.size(); for (String s : store.data()) { // print or process s }
This software is licensed with an Apache 2 license, see http://www.apache.org/licenses/LICENSE-2.0 for details.
Constructor and Description |
---|
StorageResource()
Create an empty
StorageResource object |
StorageResource(StorageResource other)
Create an
StorageResource object that is a copy of another list. |
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String s)
Adds a string to this storage object.
|
void |
clear()
Remove all strings from this object so that
.size() == 0 . |
boolean |
contains(java.lang.String s)
Determines if a string is stored in this object.
|
java.lang.Iterable<java.lang.String> |
data()
Create and return an iterable for all strings in this object.
|
int |
size()
Returns the number of strings added/stored in this object.
|
public StorageResource()
StorageResource
objectpublic StorageResource(StorageResource other)
StorageResource
object that is a copy of another list.other
- the original list being copiedpublic void clear()
.size() == 0
.public void add(java.lang.String s)
s
- the value addedpublic int size()
public boolean contains(java.lang.String s)
s
- string searched forpublic java.lang.Iterable<java.lang.String> data()
Iterable
that allows access to each string in the order stored