Tools: context=


Download 1.5 Mb.
bet2/5
Sana27.03.2023
Hajmi1.5 Mb.
#1300986
1   2   3   4   5
Bog'liq
apk

/**
* Created by Tortuvshin Byambaa on 2/15/2017.
*/

public class ToDay implements Parcelable {

private String name;

private int completionTokens;

private LinkedList childToDayElements;


// Keeps track of the current ToDayElements which belong to this ToDay

private int totalTime=0;


// Time is stored in Millis

private int lifeTimeInToDay=0;

private String uuid;

/** Overloaded ToDay Object constructor.
* @param name name of the ToDay object being instantiated
* @param time total time estimate of the ToDay object
*/
public ToDay(String name, double time) {
this.name = name;
this.totalTime = (int) time;
this.completionTokens=0;
this.childToDayElements = new LinkedList<>();
this.uuid = UUID.randomUUID().toString();
} // End of overload constructor

/*~~~~~~~~~ Getters & Setters ~~~~~~~~~*/

public int getLifeTimeInToDay() {
return lifeTimeInToDay;
}

public void setLifeTimeInToDay(int lifeTimeInToDay) {


this.lifeTimeInToDay = lifeTimeInToDay;
}

public String getUuid() {


return uuid;
}

public LinkedList getChildElements() {


return childToDayElements;
}
public void setChildElements(LinkedList newDataSet) {
this.childToDayElements = newDataSet;
}

/** Sets the name for the ToDay
* @param name desired name of the ToDay object
*/
public void setName(String name) {
this.name = name;
}

/** Gets the name of the ToDay
* @return name
*/
public String getName() {
return this.name;
}

/** Gets the current Element count for the ToDay
* @return childToDayElements.size()
*/
public Integer getChildCount() {
return childToDayElements.size();
}

/** Gets the total estimated time for the ToDay
* @return totalTime
*/
public double getTime() {
return totalTime;
}

public int getHours() {


return AppUtils.calcHours(totalTime);
}

public int getMinutes() {


return AppUtils.calcRemainderMins(totalTime);
}
/**
* Returns H and M formatted time for the total ToDay Time
* @return String, time
*/
public String getFormattedTime() {
// Total time includes hrs and minutes, int truncates the double
return AppUtils.buildCardViewStyleTime(this.totalTime);
}


/**
* Returns number of completion tokens in this ToDay
* @return completionTokens, int
*/
public int getCompletionTokens() {
return completionTokens;
}

/*~~~~~~~~ Action Methods ~~~~~~~~~~*/

@Override
public boolean equals(Object o) {
ToDay other = (ToDay) o;
String otherUniqueId = other.getUuid();
return this.uuid.equals(otherUniqueId);
}

/**
* Reassigns Child Element Location Parameters to match their current location in the LinkedList.
*/
public void reassignChildLocations() {
for (int i=0; ichildToDayElements.get(i).setLocation(i);
}
}

/**
* Adds a completion token to the current ToDay
*/
public void addCompletionToken(){
completionTokens++;
}


/** Retrieves the ToDayElement at the specified index position within
* the ToDay's children ArrayList
*
* @param childLocation the index position which the ToDayElement is at
* @return ToDayElement the element which has been found
*/
public ToDayElement getChildAt(int childLocation) {
return childToDayElements.get(childLocation);
}

/** Adds the ToDayElement received via Parameters to the ToDay's
* children ArrayList
*
* @param newElement the Element being added to the ToDay's ArrayList
*/
public void add(ToDayElement newElement) {

childToDayElements.add(newElement);

totalTime = totalTime + newElement.getTimeEstimate();
}

public void reorderChildAt(int originalLocation, int newLocation) {


ToDayElement target = this.childToDayElements.remove(originalLocation);

this.childToDayElements.add(newLocation, target);

this.reassignChildLocations();
}


/**
* Removes the supplied collection of child elements to remove from this ToDay.
*
* * On avg case:
* O(n) of calculating totalTime of deletedChildElement
* <
* O(n) recalculating totalTime from remaining elements
*
*
* @param deletedChildElements
*/
public void removeSelectedCollection(LinkedList deletedChildElements) {
childToDayElements.removeAll(deletedChildElements);

for (ToDayElement removed: deletedChildElements) {


totalTime = totalTime - removed.getTimeEstimate();
}

}


Download 1.5 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling