package cn.edu.bjut.chapter6; import java.util.ArrayList; import java.util.List; public class CorpusList { private List data; public CorpusList() { this.data = new ArrayList(); } public CorpusList(List data) { this.data = data; } public CorpusList(Patent[] patents) { this(); for (Patent patent: patents) { data.add(patent); } } public void add(Patent patent) { data.add(patent); } public int size() { return data.size(); } public boolean contains(String applicationNo) { if (applicationNo == null || applicationNo.trim().equals("")) { return false; } for (Patent patent: data) { if (patent.getApplicationNo().equalsIgnoreCase(applicationNo)) { return true; } } return false; } public boolean contains(Ipc ipc) { if (ipc == null) { return false; } for (Patent patent: data) { Ipc[] ipcs = patent.getIpcs(); for (Ipc e: ipcs) { if (e.equals(ipc)) { return true; } } } return false; } public boolean contains(Cpc cpc) { if (cpc == null) { return false; } for (Patent patent: data) { Cpc[] cpcs = patent.getCpcs(); for (Cpc e: cpcs) { if (e.equals(cpc)) { return true; } } } return false; } public boolean contains(Date applicationDate) { if (applicationDate == null) { return false; } for (Patent patent: data) { if (patent.getApplicationDate().equals(applicationDate)) { return true; } } return false; } public CorpusList find(String applicationNo) { if (applicationNo == null || applicationNo.trim().equals("")) { return null; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { if (patent.getApplicationNo().equalsIgnoreCase(applicationNo)) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } public CorpusList find(Ipc ipc) { if (ipc == null) { return null; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { Ipc[] ipcs = patent.getIpcs(); for (Ipc e: ipcs) { if (e.equals(ipc)) { corpus.add(patent); break; } } } return corpus.size() == 0? null: corpus; } public CorpusList find(Cpc cpc) { if (cpc == null) { return null; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { Cpc[] cpcs = patent.getCpcs(); for (Cpc e: cpcs) { if (e.equals(cpc)) { corpus.add(patent); break; } } } return corpus.size() == 0? null: corpus; } public CorpusList find(Date applicationDate) { if (applicationDate == null) { return null; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { if (patent.getApplicationDate().equals(applicationDate)) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } public CorpusList remove(String applicationNo) { if (applicationNo == null || applicationNo.trim().equals("")) { return this; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { if (!patent.getApplicationNo().equalsIgnoreCase(applicationNo)) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } public CorpusList remove(Ipc ipc) { if (ipc == null) { return this; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { boolean flag = false; Ipc[] ipcs = patent.getIpcs(); for (Ipc e: ipcs) { if (e.equals(ipc)) { flag = true; break; } } if (!flag) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } public CorpusList remove(Cpc cpc) { if (cpc == null) { return null; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { boolean flag = false; Cpc[] cpcs = patent.getCpcs(); for (Cpc e: cpcs) { if (e.equals(cpc)) { flag = true; break; } } if (!flag) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } public CorpusList remove(Date applicationDate) { if (applicationDate == null) { return this; } CorpusList corpus = new CorpusList(); for (Patent patent: data) { if (!patent.getApplicationDate().equals(applicationDate)) { corpus.add(patent); } } return corpus.size() == 0? null: corpus; } @Override public String toString() { StringBuilder sb = new StringBuilder(); for (Patent patent: data) { sb.append(patent + "\n"); } return sb.toString(); } public static void main(String[] args) { Patent[] patents = new Patent[5]; patents[0] = new Patent("14725838", "2015-05-29", "A23B 5/04, A23B 5/045", "A23B 5/04, A23B 5/45, A23L 15/20", 'F', 'I'); patents[1] = new Patent("14814205", "2015-07-30", "A61H 33/00, C01B 33/107, E04B 1/84", "A61H 33/6063, A61H 33/6042", 'F', 'I'); patents[2] = new Patent("15189723", "2016-06-22", "D04B 1/00", "B65H2301/44514, C01B 33/1071, F16F 15/2, H01L 27/14641", 'L', 'A'); patents[3] = new Patent("14711011", "2015-05-13", "B32B 17/10, B32B 27/32", "G06F 3/485", 'L', 'A'); patents[4] = new Patent("14515267", "2014-10-15", "F16F 15/02, G09G 5/34, G06F 3/0485", "A01B 15/06, A01B 15/06", 'L', 'I'); CorpusList corpus = new CorpusList(patents); System.out.println(corpus); CorpusList corpusFound = corpus.find(new Date("2016-06-22")); System.out.println(corpusFound); CorpusList corpusAfterRemovingIpc = corpus.remove(new Ipc("F16F 15/02")); System.out.println(corpusAfterRemovingIpc); CorpusList corpusAfterRemovingCpc =corpus.remove(new Cpc("A23B 5/04", 'F', 'I')); System.out.println(corpusAfterRemovingCpc); } }