📄 adindex.java
字号:
package jp.co.sjts.gsession.card;
import java.io.File;
import java.util.Collections;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import jp.co.sjts.gsession.card.CDCardFile;
import jp.co.sjts.gsession.tools.*;
import jp.co.sjts.gsession.tools.mail.*;
/**
* <p>傾僪儗僗挔僀儞僨僢僋僗庢摼
*
* @author Junichi KANEUCHI <kaneuchi@sjts.co.jp>
*/
public class ADIndex {
private int max = 0;
private String cardDir = null;
private String dataDir = null;
private Set toSet = null;
private Set ccSet = null;
private Set bccSet = null;
/** */
private static final String[] indexs = {"偁","偄","偆","偊","偍","偐","偒","偔","偗","偙","偝","偟","偡","偣","偦","偨","偪","偮","偰","偲","側","偵","偸","偹","偺","偼","傂","傆","傊","傎","傑","傒","傓","傔","傕","傗","備","傛","傜","傝","傞","傟","傠","傢","傪","傫","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","etc"};
/**
* <p> 僷儔儊乕僞僙僢僩
*
* @param cardDir
* @param dataDir
* @param max
*/
public ADIndex(String cardDir, String dataDir, int max) {
this.max = max;
this.cardDir = cardDir;
this.dataDir = dataDir;
toSet = Collections.synchronizedSet(new HashSet());
ccSet = Collections.synchronizedSet(new HashSet());
bccSet = Collections.synchronizedSet(new HashSet());
}
/**
* <p>
*
* @param item
* @return HashSet
*/
public synchronized HashSet getItemIndexs(int item) {
HashSet itemSet = new HashSet();
CDCardFile cdfile = null;
String param = null;
try {
String indexDir = cardDir+CDCmd.CD_IX+File.separator;
switch(item) {
case CDCmd.CD_CARD1:
indexDir += CDCmd.CD_IX_CO;
break;
case CDCmd.CD_CARD2:
indexDir += CDCmd.CD_IX_KN;
break;
case CDCmd.CD_CARD4:
indexDir += CDCmd.CD_IX_ML;
}
CDKanaIndexSearch idxSearch = new CDKanaIndexSearch(indexDir);
List CIDList = null;
Iterator it_index = null;
for(int i=0; i < indexs.length; i++) {
CIDList = idxSearch.getIDs(indexs[i].hashCode());
if(CIDList != null) {
it_index = CIDList.iterator();
while(it_index.hasNext()) {
String id = ((Integer)it_index.next()).toString();
if((new File(dataDir + id)).exists()) {
cdfile = new CDCardFile(dataDir, id , 0);
cdfile.Load();
if(cdfile.getMail().length() > 0) {
itemSet.add(indexs[i]);
break;
}
}
}
}
}
} catch(GSException ge) {}
return itemSet;
}
/**
* <p>
*
* @param address
*/
public synchronized void getIndexs(MailAddress address) {
CDCardFile cdfile = null;
try {
for(int i=0; i <= max; i++) {
if((new File(dataDir + i)).exists()) {
cdfile = new CDCardFile(dataDir, Integer.toString(i), 0);
cdfile.Load();
if(cdfile.getMail().length() > 0) {
// ID庢摼
if(address.containsTO(cdfile.getMail()))
toSet.add(Integer.toString(i));
if(address.containsCC(cdfile.getMail()))
ccSet.add(Integer.toString(i));
if(address.containsBCC(cdfile.getMail()))
bccSet.add(Integer.toString(i));
}
}
}
} catch(GSException ge) {}
}
/**
* <p>
*
* @return String[]
*/
public synchronized String[] gettoID() {
Object[] ids = toSet.toArray();
String[] ids_str = new String[ids.length];
for(int i=0; i < ids.length; i++) {
ids_str[i] = (String)ids[i];
}
return ids_str;
}
/**
* <p>
*
* @return String[]
*/
public synchronized String[] getccID() {
Object[] ids = ccSet.toArray();
String[] ids_str = new String[ids.length];
for(int i=0; i < ids.length; i++) {
ids_str[i] = (String)ids[i];
}
return ids_str;
}
/**
* <p>
*
* @return String[]
*/
public synchronized String[] getbccID() {
Object[] ids = bccSet.toArray();
String[] ids_str = new String[ids.length];
for(int i=0; i < ids.length; i++) {
ids_str[i] = (String)ids[i];
}
return ids_str;
}
/**
* <p>
*
* @param address
* @param toIDs
* @param ccIDs
* @param bccIDs
* @return MailAddress
*/
public synchronized MailAddress setAddress(MailAddress address, HashSet toIDs, HashSet ccIDs, HashSet bccIDs) {
CDCardFile cdfile = null;
String param = null;
Hashtable indexs = new Hashtable();
try {
for(int i=0; i <= max; i++) {
if((new File(dataDir + i)).exists()) {
cdfile = new CDCardFile(dataDir, Integer.toString(i), 0);
cdfile.Load();
if(cdfile.getMail().length() > 0) {
address.removeTO(cdfile.getMail());
address.removeCC(cdfile.getMail());
address.removeBCC(cdfile.getMail());
if(toIDs.contains(Integer.toString(i)))
address.addTO(cdfile.getName(), cdfile.getMail());
if(ccIDs.contains(Integer.toString(i)))
address.addCC(cdfile.getName(), cdfile.getMail());
if(bccIDs.contains(Integer.toString(i)))
address.addBCC(cdfile.getName(), cdfile.getMail());
}
}
}
} catch(GSException ge) {}
return address;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -