File: ToDoRecord.java

package info (click to toggle)
pilot-link 0.12.5-dfsg-2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 6,868 kB
  • ctags: 5,811
  • sloc: ansic: 53,153; sh: 10,459; java: 2,584; perl: 2,247; python: 1,044; makefile: 991; yacc: 662; cpp: 551; xml: 39
file content (144 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Created on 15.10.2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.gnu.pilotlink;

import java.util.Date;

/**
 * @author stephan
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ToDoRecord extends Record {
	private Date dueDate;
	private byte priority;
	private String description;
	private boolean done;
	private String note;

	public String getDescription() {
		return description;
	}
	public void setDescription(String d) {
		description=d;
		setSize(getBuffer().length);
	}
	public boolean getDone() {
		return done;
	}
	public void setDone(boolean d) {
		done=d;
	}
	public int getPriority() {
		return priority;
	}
	public void setPriority(int i) {
		if (i>255) 
			throw new IllegalArgumentException("Invalid priority");
		priority=(byte)i;
	}
	
	public void setNote(String n) {
		note=n;
		setSize(getBuffer().length);
	}
	public String getNote() {
		return note;
	}
	
	public void setDueDate(Date dd) {
		dueDate=dd;
		setSize(getBuffer().length);
	}
	public Date getDueDate() {
		return dueDate;
	}
	
	public ToDoRecord(Record r) {
		super(r);
	}

	public ToDoRecord() {
	}
	/* (non-Javadoc)
	 * @see org.gnu.pilotlink.Record#getBuffer()
	 */
	public byte[] getBuffer() {
		int size=3;
		if (note!=null) {
			size+=note.length()+1;
		} else {
			size++;
		}
		if (description!=null)  {
			size+=description.length()+1;
		} else {
			size++;
		}
		byte buf[]=new byte[size];
		System.out.println("Size: "+size); 
		if (dueDate!=null) {
			Record.setDateAt(buf,dueDate,0);
		} else {
			buf[0]=(byte)0xff; buf[1]=(byte)0xff;
		}
		buf[2]=priority;
		if(done) {
			buf[2]|=0x80;
		}
		int offset=3;
		if (description!=null) {
			offset=Record.setStringAt(buf,description,offset);			
		} else {
			buf[offset++]=0;
		}
		if (note!=null) {
			Record.setStringAt(buf,note,offset);
		} else {
			buf[offset++]=0;
		}
		return buf;
 	}

	/* (non-Javadoc)
	 * @see org.gnu.pilotlink.Record#setBuffer(byte[])
	 */
	public void setBuffer(byte[] buf) {
		
		if (Record.getIntAt(buf,0) != 0xffff) {
			//due-date set
			System.out.println("\n\nReading in due-date..."+(buf[0]&0xff)+"  "+(buf[1]&0xff)+" getInt "+Record.getIntAt(buf,0)+" "+Record.getDateAt(buf,0));
		
			dueDate=Record.getDateAt(buf,0);
		}
		priority=buf[2];
		if ((priority & 0x80) > 0) {
			//Completed
			priority&=0x7f;
			done=true;
		} else {
			done=false;
		}
		if (buf.length <= 3) {
			return;
		}
		int pos=3;
		description=Record.getStringAt(buf,3);
		if (buf.length<=3+description.length()) {
			return;
		}
		note=Record.getStringAt(buf,3+description.length());
		
		setSize(buf.length);
	}
	
	public String toString() {
		return "P"+priority+": "+description+" Done: "+done+" due to: "+dueDate+" note: "+note; 
	}

}