📄 note_diary.java
字号:
for(int k=0;k<index;k++){
dates[k]=(date)s.pop();
}
}
return dates;
}
static date[] getdate(int which) throws Exception{
date[] adate;
awhich=which;
int num;
RecordEnumeration enum=null;
Compare1 comp=one.new Compare1();
Filter1 f=one.new Filter1();
try {
enum = note_diary.enumerateRecords(f,comp,true);
} catch (RecordStoreNotOpenException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
return null;
}
num=enum.numRecords();
if(num>=1){
adate=new date[num];
int i=0;
while (enum.hasNextElement())
{
byte[] record;
try {
record = enum.nextRecord();
adate[i]=decode(record);
i++;
} catch (InvalidRecordIDException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (RecordStoreNotOpenException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
enum.destroy();
return adate;
}
return null;
}
static int get_num(int year,int month ,int day){
amonth=month;
aday=day;
date[] adate;
Filter f=one.new Filter();
RecordEnumeration enum;
try {
enum = note_diary.enumerateRecords(f,null,true);
} catch (RecordStoreNotOpenException e1) {
e1.printStackTrace();
return 0;
}
return enum.numRecords();
}
static date[] get(int year,int month ,int day){
amonth=month;
aday=day;
date[] adate;
Filter f=one.new Filter();
RecordEnumeration enum;
try {
enum = note_diary.enumerateRecords(f,null,true);
} catch (RecordStoreNotOpenException e1) {
e1.printStackTrace();
return null;
}
int num=enum.numRecords();
if(num>=1){
adate=new date[num];
int i=0;
while (enum.hasNextElement())
{
byte[] record;
try {
record = enum.nextRecord();
try {
adate[i]=decode(record);
} catch (Exception e2) {
e2.printStackTrace();
}
i++;
} catch (InvalidRecordIDException e) {
e.printStackTrace();
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
enum.destroy();
return adate;
}
return null;
}
static boolean delete(date adate) throws RecordStoreException{
date a=new date();
for(int i=1;i<note_diary.getNextRecordID();i++){
try{
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(note_diary.getRecord(i));
DataInputStream dataInputStream = new DataInputStream(byteInputStream);
a.setYear(dataInputStream.readInt());
a.setMonth(dataInputStream.readInt());
a.setDay(dataInputStream.readInt());
a.setName(dataInputStream.readUTF());
a.setContent(dataInputStream.readUTF());
a.setWhich(dataInputStream.readInt());
if(adate.year ==a.year && adate.month ==a.month && adate.day ==a.day &&adate.name.equals(a.name ) &&adate.content.equals(a.content ) &&adate.which ==a.which ){
note_diary.deleteRecord(i);
dataInputStream.close();
byteInputStream.close();
return true;
}
}catch (Exception e){
e.printStackTrace();
}
}
return false;
}
static int find(date adate){
date a=new date();
int index=0;
try {
for(int i=1;i<note_diary.getNextRecordID();i++){
try{
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(note_diary.getRecord(i));
DataInputStream dataInputStream = new DataInputStream(byteInputStream);
a.setYear(dataInputStream.readInt());
a.setMonth(dataInputStream.readInt());
a.setDay(dataInputStream.readInt());
a.setName(dataInputStream.readUTF());
a.setContent(dataInputStream.readUTF());
a.setWhich(dataInputStream.readInt());
if(adate.year ==a.year && adate.month ==a.month && adate.day ==a.day &&adate.name.equals(a.name ) &&adate.content.equals(a.content ) &&adate.which ==a.which ){
index=i;
dataInputStream.close();
byteInputStream.close();
return index;
}
}catch (Exception e){
e.printStackTrace();
}
}
} catch (RecordStoreNotOpenException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return index;
}
static boolean update(date adate,int which) throws RecordStoreException, IOException{
int index=find(adate);
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);
dataOutputStream.writeInt(adate.year);
dataOutputStream.writeInt(adate.month);
dataOutputStream.writeInt(adate.day);
dataOutputStream.writeUTF(adate.name);
dataOutputStream.writeUTF(adate.content);
dataOutputStream.writeInt(which);
dataOutputStream.flush();
byte[] recordOut = byteOutputStream.toByteArray();
try {
note_diary.setRecord(index,recordOut, 0, recordOut.length);
dataOutputStream.close();
byteOutputStream.close();
return true;
} catch (RecordStoreException e) {
e.printStackTrace();
}
dataOutputStream.close();
byteOutputStream.close();
return false;
}
static boolean update(date adate,String add) throws RecordStoreException, IOException{
int index=find(adate);
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);
dataOutputStream.writeInt(adate.year);
dataOutputStream.writeInt(adate.month);
dataOutputStream.writeInt(adate.day);
dataOutputStream.writeUTF(adate.name);
dataOutputStream.writeUTF(adate.content+add);
dataOutputStream.writeInt(adate.which);
dataOutputStream.flush();
byte[] recordOut = byteOutputStream.toByteArray();
try {
note_diary.setRecord(index,recordOut, 0, recordOut.length);
dataOutputStream.close();
byteOutputStream.close();
return true;
} catch (RecordStoreException e) {
e.printStackTrace();
}
dataOutputStream.close();
byteOutputStream.close();
return false;
}
static void delete(int year,int month,int day) throws RecordStoreException {
date a = new date();
try {
for(int i=1;i<note_diary.getNextRecordID();i++){
try{
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(note_diary.getRecord(i));
DataInputStream dataInputStream = new DataInputStream(byteInputStream);
a.setYear(dataInputStream.readInt());
a.setMonth(dataInputStream.readInt());
a.setDay(dataInputStream.readInt());
a.setName(dataInputStream.readUTF());
a.setContent(dataInputStream.readUTF());
a.setWhich(dataInputStream.readInt());
if(a.getWhich()!=2)
{
dataInputStream.close();
byteInputStream.close();
continue;
}
if(a.getYear()>year)
{
dataInputStream.close();
byteInputStream.close();
continue;
}
if(a.getMonth()>month){
dataInputStream.close();
byteInputStream.close();
continue;
}
if(a.getDay()>day){
dataInputStream.close();
byteInputStream.close();
continue;
}
note_diary.deleteRecord(i);
dataInputStream.close();
byteInputStream.close();
}catch (Exception e){
}
}
} catch (RecordStoreNotOpenException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -