add new features to TodoItem and TodoItemFactory

This commit is contained in:
hlq07 2018-05-26 17:38:42 +08:00
parent f364d264a2
commit 1ac3c637b0
2 changed files with 136 additions and 27 deletions

View File

@ -11,19 +11,54 @@ import java.util.*;
public class TodoItem {
/**
* Value of a type of TodoItem indicating the "conference" type.
* Value of a type of TodoItem indicating the "others" type.
* <p>
* required string properties: "description"
*/
public static final int CONFERENCE = 1;
public static final int OTHERS = 1;
/**
* Value of a type of TodoItem indicating the "conference" type.
*
* required string properties: "location", "title", "description"
*/
public static final int CONFERENCE = 2;
/**
* Value of a type of TodoItem indicating the "date" type.
*
* required string properties: "location", "title"
*
* personnel should have at least one element
*/
public static final int DATE = 2;
public static final int DATE = 3;
/**
* Value of a type of TodoItem indicating the "others" type.
*
* required string properties: "transportation", "number", "location", "title"
*/
public static final int OTHERS = 3;
public static final int TRIP = 4;
/**
* Value of a type of TodoItem indicating the "others" type.
* <p>
* required string properties: "type"(birth day, marriage day), "title", "description"
* <p>
* note: repeat every year
*/
public static final int ANNIVERSARY = 5;
/**
* Value of a type of TodoItem indicating the "others" type.
*
* required string properties: "title", "time of day", "weekday", "repeatWeeks", "content", "location",
* "teacher", "description"
*
* note: the bgn and end should consist with the the first course time
*/
public static final int COURSE = 6;
/**
@ -41,6 +76,73 @@ public class TodoItem {
*/
public static final String DESCRIPTION = "description";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "urgent" or "" (an empty string);
*/
public static final String PRIORITY = "priority";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "important" or "" (an empty string);
*/
public static final String IMPORTANCE = "importance";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "parent", "children";
* <p>
* If the instance have no {@code COMPOSITE}, then the corresponding value should be assumed as "parent".
*/
public static final String COMPOSITE = "composite";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "id1;id2;id3;...";
*/
public static final String CHILDREN_IDS = "children_ids";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "id";
*/
public static final String PARENT_ID = "parent_id";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "finish" or ""(an empty string);
*/
public static final String FINISH = "finish";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "area", "dialog" or "none".
*/
public static final String ALARM_METHOD = "alarm_method";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "yyyy-mm-dd/hh:mm";
*/
public static final String ALARM_START = "alarm_start";
/**
* Value of a name of possible string-type property index.
* <p>
* The corresponding value of stringProperties is formatted: "yyyy-mm-dd/hh:mm";
*/
public static final String ALARM_INTERVAL = "alarm_interval";
private long mId;
@ -50,7 +152,9 @@ public class TodoItem {
private int mType;
private HashMap<String, String> stringProperties = new HashMap<>();
private HashMap<String, String> mStringProperties = new HashMap<>();
private Map<String, String> mUnmodifiableStringProperties = Collections.unmodifiableMap(mStringProperties);
private String[] mPersonnel;
@ -93,13 +197,13 @@ public class TodoItem {
}
mId = id;
mBgn = begin;
mEnd = end;
mBgn = (Calendar) begin.clone();
mEnd = (Calendar) end.clone();
mType = type;
mPersonnel = personnel == null ? new String[0] : personnel.clone();
if (properties != null) {
stringProperties.putAll(properties);
mStringProperties.putAll(properties);
}
}
@ -119,7 +223,7 @@ public class TodoItem {
* @return the begin time
*/
public Calendar getBgn() {
return mBgn;
return (Calendar) mBgn.clone();
}
/**
@ -128,7 +232,7 @@ public class TodoItem {
* @return the end time
*/
public Calendar getEnd() {
return mEnd;
return (Calendar) mEnd.clone();
}
/**
@ -168,7 +272,7 @@ public class TodoItem {
* @return the title property value if any; {@code null} otherwise
*/
public String getTitle() {
return stringProperties.getOrDefault(TITLE, null);
return mStringProperties.getOrDefault(TITLE, null);
}
/**
@ -177,7 +281,7 @@ public class TodoItem {
* @return the location property value if any; {@code null} otherwise
*/
public String getLocation() {
return stringProperties.getOrDefault(LOCATION, null);
return mStringProperties.getOrDefault(LOCATION, null);
}
/**
@ -186,7 +290,7 @@ public class TodoItem {
* @return the description property value if any; {@code null} otherwise
*/
public String getDescription() {
return stringProperties.getOrDefault(DESCRIPTION, null);
return mStringProperties.getOrDefault(DESCRIPTION, null);
}
/**
@ -196,7 +300,7 @@ public class TodoItem {
* @return the property value if there exists the property; {@code null} otherwise
*/
public String getStringProperty(String index) {
return stringProperties.getOrDefault(index, null);
return mStringProperties.getOrDefault(index, null);
}
/**
@ -206,10 +310,18 @@ public class TodoItem {
*/
public List<GenericPair<String, String>> getStringProperties() {
ArrayList<GenericPair<String, String>> result = new ArrayList<>();
stringProperties.forEach((k, v) -> result.add(GenericPair.makePair(k, v)));
mStringProperties.forEach((k, v) -> result.add(GenericPair.makePair(k, v)));
return result;
}
/**
* Returns a map of all string-type properties.
*
* @return the map of all string-type properties
*/
public Map<String, String> getStringPropertiesMap() {
return mUnmodifiableStringProperties;
}
/**
* Compares this {@code TodoItem} to the specified {@code obj}.

View File

@ -3,10 +3,7 @@ package org.cutem.cutecalendar.model;
import org.cutem.cutecalendar.util.CalendarUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import static org.cutem.cutecalendar.model.TodoItem.*;
@ -24,12 +21,12 @@ public class TodoItemFactory {
public TodoItemFactory beginTime(@NotNull Calendar begin) {
mBgn = begin;
mBgn = CalendarUtil.roundToMinute(begin);
return this;
}
public TodoItemFactory endTime(@NotNull Calendar end) {
mEnd = end;
mEnd = CalendarUtil.roundToMinute(end);
return this;
}
@ -58,17 +55,17 @@ public class TodoItemFactory {
return this;
}
public TodoItemFactory type(int type) {
// Note: keep consist with the type value range in TodoItem
if (type < 1 || type > 3) {
throw new IllegalArgumentException("the argument is an unknown type");
}
public TodoItemFactory stringProperties(@NotNull Map<String, String> props) {
mStringProperties.putAll(props);
return this;
}
public TodoItemFactory type(int type) {
mType = type;
return this;
}
public TodoItemFactory personnel(List<String> personnel) {
public TodoItemFactory personnel(Collection<String> personnel) {
if (personnel != null) {
mPersonnel.addAll(personnel);
}