Commit 2170b4bc authored by Oliver Adams's avatar Oliver Adams

Javadoc'd the model package

parent 554cefc4
......@@ -44,16 +44,10 @@ public class Language implements Parcelable {
this.code = code;
}
/**
* Name accessor
*/
public String getName() {
return this.name;
}
/**
* Code accessor
*/
public String getCode() {
return this.code;
}
......@@ -176,6 +170,7 @@ public class Language implements Parcelable {
* Compares the given object with the Language, and returns true if the
* Language name and code are equal.
*
* @param obj The object to be compared.
* @return true if the name and codes of the languages are equal; false
* otherwise.
*/
......
......@@ -66,6 +66,12 @@ public class Recording {
* @param uuid the recording's UUID.
* @param name The recording's name.
* @param date The date of creation.
* @param languages The languages associated with the recording
* @param speakersUUIDs The UUIDs of the speakers associated with the
* recording
* @param androidID The android ID of the device that created the
* recording
* @param sampleRate The sample rate of the recording.
*/
public Recording(UUID uuid, String name, Date date,
List<Language> languages, List<UUID> speakersUUIDs,
......@@ -86,6 +92,15 @@ public class Recording {
* @param uuid the recording's UUID.
* @param name The recording's name.
* @param date The date of creation.
* @param languages The languages associated with the recording
* @param speakersUUIDs The UUIDs of the speakers associated with the
* recording
* @param androidID The android ID of the device that created the
* recording
* @param originalUUID The UUID of the recording that this recording
* is a respeaking of
* @param sampleRate The sample rate of the recording.
* @param durationMsec The duration of the recording in milliseconds.
*/
public Recording(UUID uuid, String name, Date date,
List<Language> languages, List<UUID> speakersUUIDs,
......@@ -102,20 +117,23 @@ public class Recording {
setDurationMsec(durationMsec);
}
/**
* UUID accessor.
*/
public UUID getUUID() {
return uuid;
}
/** Returns a File that refers to the actual recording file. */
/**
* Returns a File that refers to the actual recording file.
*
* @return The file the recording is stored in.
*/
public File getFile() {
return new File(getRecordingsPath(), getUUID() + ".wav");
}
/**
* Name accessor.
* Name accessor; returns an empty string if the name is null
*
* @return The name of the recording.
*/
public String getName() {
if (name != null) {
......@@ -125,16 +143,10 @@ public class Recording {
}
}
/**
* Date accessor.
*/
public Date getDate() {
return date;
}
/**
* languages accessor.
*/
public List<Language> getLanguages() {
return languages;
}
......@@ -142,6 +154,9 @@ public class Recording {
/**
* Returns the first language code as a string, or an empty string if there
* is none.
*
* @return The language code of the first language associated with the
* recording.
*/
public String getFirstLangCode() {
if (getLanguages().size() > 0) {
......@@ -151,6 +166,11 @@ public class Recording {
}
}
/**
* Returns the name and language of the recording in a single string.
*
* @return The name and langugage of the recording in a string.
*/
public String getNameAndLang() {
if (getFirstLangCode().equals("")) {
return getName();
......@@ -161,6 +181,8 @@ public class Recording {
/**
* speakersUUIDs accessor.
*
* @return A list of UUIDs representing the speakers of the recording.
*/
public List<UUID> getSpeakersUUIDs() {
return speakersUUIDs;
......@@ -180,6 +202,8 @@ public class Recording {
/**
* androidID accessor
*
* @return The Andorid of the device that made the recording.
*/
public String getAndroidID() {
return androidID;
......@@ -187,6 +211,9 @@ public class Recording {
/**
* originalUUID accessor.
*
* @return The UUID of the original recording that this is a respeaking
* of.
*/
public UUID getOriginalUUID() {
if (originalUUID == null) {
......@@ -199,6 +226,8 @@ public class Recording {
/**
* sampleRate accessor
*
* @return The sample rate of the recording as a long.
*/
public long getSampleRate() {
return sampleRate;
......@@ -206,6 +235,8 @@ public class Recording {
/**
* durationMsec accessor
*
* @return The duration of the recording in milliseconds as an int.
*/
public int getDurationMsec() {
return durationMsec;
......@@ -254,6 +285,8 @@ public class Recording {
/**
* Write the Recording to file in a subdirectory of the recordings
* directory named as <uuid>.json
*
* @throws IOException If the recording metadata could not be written.
*/
public void write() throws IOException {
JSONObject encodedRecording = this.encode();
......@@ -265,6 +298,8 @@ public class Recording {
/**
* Deletes the JSON File associated with the recording.
*
* @return true if successful; false otherwise.
*/
public boolean delete() {
File file = new File(getRecordingsPath(), this.getUUID().toString() +
......@@ -285,6 +320,8 @@ public class Recording {
* Read a recording from the file containing JSON describing the Recording
*
* @param uuid The uuid of the recording to be read.
* @return A Recording object corresponding to the uuid.
* @throws IOException If the recording metadata cannot be read.
*/
public static Recording read(UUID uuid) throws IOException {
JSONObject jsonObj = FileIO.readJSONObject(
......@@ -354,6 +391,8 @@ public class Recording {
/**
* Returns a list of all the respeakings of this Recording.
*
* @return A list of all the respeakings of the recording.
*/
public List<Recording> getRespeakings() {
List<Recording> allRecordings = readAll();
......@@ -415,6 +454,7 @@ public class Recording {
* Recordings uuid, name, date, languages, androidID and originalUUID are
* equal
*
* @param obj The object to be compared.
* @return true if the uuid, name, date, languages, androidID and
* originalUUID are equal; false otherwise.
*/
......@@ -572,6 +612,13 @@ public class Recording {
return path;
}
/**
* Indicates that this recording is allowed to be synced by moving it to a
* directory that the SyncUtil synchronizes.
*
* @param uuid The UUID of the recording to sync.
* @throws IOException If it cannot be moved to the synced directory.
*/
public static void enableSync(UUID uuid) throws IOException {
File wavFile = new File(getNoSyncRecordingsPath(), uuid + ".wav");
FileUtils.moveFileToDirectory(wavFile, getRecordingsPath(), false);
......
......@@ -39,6 +39,9 @@ public class Segments {
}
}
/**
* Constructor to create an empty Segments object.
*/
public Segments() {
segmentMap = new LinkedHashMap<Segment, Segment>();
}
......@@ -46,13 +49,21 @@ public class Segments {
/**
* Gets the respeaking segment associated with the supplied original
* segment.
*
* @param originalSegment A Segment object representing a segment of the original audio.
* @return A respeaking Segment object corresponding to the
* originalSegment
*/
public Segment getRespeakingSegment(Segment originalSegment) {
return segmentMap.get(originalSegment);
}
/**
* Adds a pair of segments.
* Adds a pair of segments to the Segments; analogous to Map.add().
*
* @param originalSegment A segment of an original recording.
* @param respeakingSegment A respeaking segment corresponding to
* originalSegment.
*/
public void put(Segment originalSegment,
Segment respeakingSegment) {
......@@ -61,6 +72,8 @@ public class Segments {
/**
* Returns an iterator over the segments of the original recording.
*
* @return An iterator over the segments of the original recording.
*/
public Iterator<Segment> getOriginalSegmentIterator() {
return segmentMap.keySet().iterator();
......@@ -68,6 +81,9 @@ public class Segments {
/**
* Reads the segments from a file.
*
* @param path The path to the file.
* @throws Exception If the segments cannot be read.
*/
private void readSegments(File path) throws Exception {
String mapString = FileIO.read(path);
......@@ -91,6 +107,9 @@ public class Segments {
/**
* Writes the segment mapping to file.
*
* @param path The path to the file.
* @throws IOException If the segments cannot be written to file.
*/
public void write(File path) throws IOException {
FileIO.write(path, toString());
......@@ -105,6 +124,9 @@ public class Segments {
/**
* Creates a segment given the sample at which the segment starts, and
* the sample at which it ends.
*
* @param startSample The sample at which the segment starts.
* @param endSample The sample at which the segment ends.
*/
public Segment(Long startSample, Long endSample) {
if (startSample == null) {
......@@ -124,14 +146,21 @@ public class Segments {
return this.pair.second;
}
/**
* Returns the duration of the segment in samples
*
* @return The duration of the segment in samples.
*/
public Long getDuration() {
return this.pair.second - this.pair.first;
}
@Override
public String toString() {
return getStartSample() + "," + getEndSample();
}
@Override
public boolean equals(Object obj) {
if (obj == null) { return false; }
if (obj == this) { return true; }
......@@ -145,11 +174,13 @@ public class Segments {
.isEquals();
}
@Override
public int hashCode() {
return pair.hashCode();
}
}
@Override
public String toString() {
String mapString = new String();
Segment respeakingSegment;
......
......@@ -20,6 +20,16 @@ import org.lp20.aikuma.util.FileIO;
*/
public class ServerCredentials {
/**
* Constructor
*
* @param ipAddress The IP address of the server.
* @param username The username of a user on the server who will be
* logged in as.
* @param password The password corresponding to the user.
* @param syncActivated A flag indicating whether automatic sync is
* activated or not
*/
public ServerCredentials(String ipAddress, String username,
String password, boolean syncActivated) {
setIPAddress(ipAddress);
......@@ -28,6 +38,11 @@ public class ServerCredentials {
setSyncActivated(syncActivated);
}
/**
* Write the server credentials to file.
*
* @throws IOException If the credentials cannot be written.
*/
public void write() throws IOException {
JSONObject encodedServerCredentials = this.encode();
FileIO.writeJSONObject(
......@@ -35,6 +50,13 @@ public class ServerCredentials {
encodedServerCredentials);
}
/**
* Reads server credentials from file.
*
* @return A ServerCredentials object representing the stored server
* credentials
* @throws IOException If the credentials cannot be read.
*/
public static ServerCredentials read() throws IOException {
JSONObject encodedServerCredentials = FileIO.readJSONObject(
new File(FileIO.getAppRootPath(), "server_credentials.json"));
......
......@@ -98,6 +98,7 @@ public class Speaker implements Parcelable{
* Gets the Speaker's image.
*
* @return A Bitmap object.
* @throws IOException If the image cannot be retrieved.
*/
public Bitmap getImage() throws IOException {
return ImageUtils.getImage(getUUID());
......@@ -107,6 +108,7 @@ public class Speaker implements Parcelable{
* Gets the small version of the Speaker's image.
*
* @return A Bitmap object.
* @throws IOException If the image cannot be retrieved.
*/
public Bitmap getSmallImage() throws IOException {
return ImageUtils.getSmallImage(getUUID());
......@@ -160,6 +162,8 @@ public class Speaker implements Parcelable{
/**
* Write the Speaker to file iin a subdirectory of the Speakers directory
* named as <uuid>.json
*
* @throws IOException If the speaker metadata cannot be written to file.
*/
public void write() throws IOException {
JSONObject encodedSpeaker = this.encode();
......@@ -172,6 +176,8 @@ public class Speaker implements Parcelable{
* read a Speaker from the file containing the JSON describing the speaker
*
* @param uuid A UUID object representing the UUID of the Speaker.
* @return A Speaker object corresponding to the given speaker UUID.
* @throws IOException If the speaker metadata cannot be read from file.
*/
public static Speaker read(UUID uuid) throws IOException {
JSONObject jsonObj = FileIO.readJSONObject(
......@@ -220,6 +226,7 @@ public class Speaker implements Parcelable{
* Compares the given object with the Speaker, and returns true if the
* Speaker uuid, name and languages are equal.
*
* @param obj The object to compare to.
* @return true if the uuid, name and languages of the Speaker are equal;
* false otherwise.
*/
......@@ -235,6 +242,11 @@ public class Speaker implements Parcelable{
.append(languages, rhs.languages).isEquals();
}
/**
* Provides a string representation of the speaker.
*
* @return A string representation of the Speaker
*/
public String toString() {
String s = getUUID().toString() + ", " + getName() + ", " +
getLanguages().toString();
......@@ -287,17 +299,27 @@ public class Speaker implements Parcelable{
this.languages = languages;
}
/* To make it Parcelable */
@Override
public int describeContents() {
return 0;
}
/**
* Creates a Parcel object representing the Speaker.
*
* @param out The parcel to be written to
* @param _flags Unused additional flags about how the object should be
* written.
*/
public void writeToParcel(Parcel out, int _flags) {
out.writeString(uuid.toString());
out.writeString(name);
out.writeTypedList(languages);
}
/**
* Generates instances of a Speaker from a parcel.
*/
public static final Parcelable.Creator<Speaker> CREATOR =
new Parcelable.Creator<Speaker>() {
public Speaker createFromParcel(Parcel in) {
......@@ -308,6 +330,11 @@ public class Speaker implements Parcelable{
}
};
/**
* Constructor that takes a parcel representing the speaker.
*
* @param in The parcel representing the Speaker to be constructed.
*/
public Speaker(Parcel in) {
setUUID(UUID.fromString(in.readString()));
setName(in.readString());
......
......@@ -27,6 +27,8 @@ public class WaveFile {
* Constructor.
*
* @param file The file to read from.
* @throws IOException In the event that there is an issue reading the
* file.
*/
public WaveFile(File file) throws IOException {
setFile(file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment