⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rereservefile.java

📁 一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。
💻 JAVA
字号:
/*-
 * reserve 偺XXXX  REReserveFile.java
 */
package jp.co.sjts.gsession.reserve;


import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import jp.co.sjts.gsession.tools.*;

/**
 * <p>梊栺僨乕僞娗棟梡
 * <p>Copyright (C) 1999-2000 Japan Total System Co,LTD
 *
 * @author   Masakatu O   &lt;ookubo@sjts.co.jp&gt;
 * @author   Satoru K   &lt;koni@sjts.co.jp&gt;
 */
public class REReserveFile extends GSTextFile
{
	private List IdxList = null;		// 棙梡儌僕儏乕儖
	private REReserveData data=null;
	private int hitcnt;


	public static String FILENAME = "reserve";
	public final static String DIR0 = "data" + File.separator ;
	public final static String SPATH = File.separator ;

	private File file;
	private String filePath;

	public REReserveFile(String HomeDir,String GId,String Id) throws GSException
	{
		init();
		filePath = HomeDir + DIR0 + GId + SPATH + Id ; //GID偼巤愝僌儖乕僾ID ID偼巤愝ID

		File file1 = new File(filePath);

		if(!file1.exists())		// 僼傽僀儖偑懚嵼偡傞偐
			file1.mkdirs();		// 僼傽僀儖偑懚嵼偟側偄応崌偼丄嶌惉傪帋傒傞

		filePath = filePath + SPATH + FILENAME;
		this.file = new File(filePath);

		if(file.exists()) {
			Load();
		}
	}



//愨懳偄傞
	protected File GetFile()
	{
		return file;
	}


//愨懳偄傞
	synchronized protected void Write(PrintWriter pw) throws GSException
	{
		String[] buf = toModsString();
		for(int i=0;i<buf.length;i++) {
			pw.println(buf[i]);
		}
	}


//愨懳偄傞
	synchronized protected void Read(BufferedReader bf) throws GSException
	{
		init();

		try{
			String buf;

			for(buf=bf.readLine();buf!=null;buf=bf.readLine()) {
				StringTokenizer st = new StringTokenizer(buf,",");
				String id = st.nextToken();
				String name = GSTool.delimitDecorde(",",st.nextToken());
				String start = st.nextToken();
				String end = st.nextToken();
				String object = GSTool.delimitDecorde(",",st.nextToken());
				String note = GSTool.delimitDecorde(",",st.nextToken());
				String uid = st.nextToken();

				Addmod(new REReserveData(id,name,start,end,object,note,uid));
			}
		}catch(IOException e){
			throw new GSException("僼傽僀儖偺撉崬傒偵幐攕");
		}
	}


//婡擻

	//弶婜壔
	public synchronized void init()
	{
		IdxList = Collections.synchronizedList(new ArrayList());
	}


	//僒僀僘庢摼
	public synchronized int size()
	{
		return IdxList.size();
	}

	//嶍彍
	public synchronized void Delall(String date)
	{
		synchronized(IdxList){
			long st = Long.parseLong( date + "0000" );
			int[]   cnt = new int[IdxList.size()] ;
			int ii = 0 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (REReserveData)it.next();
				if( Long.parseLong( data.GetEnd()) < st ) {
					cnt[ii++] = i ;
				}
			}
			if(ii != 0) {
				for(int i=ii;i>0;i--) {
					IdxList.remove(cnt[i-1]);
				}
			}
		}
	}

	//嶍彍
	public synchronized void Del(String bid)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (REReserveData)it.next();
				if( bid.equals( data.GetId()) ) {
					cnt = i ;
					break;
				}
			}
			if(cnt != -1) {
				IdxList.remove(cnt);
			}
		}
	}

	//庢摼
	public synchronized REReserveData DataChk(String id)
	{
		hitcnt = -1;
		synchronized(IdxList){
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (REReserveData)it.next();
				if( Integer.parseInt(data.GetId()) == Integer.parseInt(id) ) {
					hitcnt = i;
					return data ;
				}
			}
			return data ;
		}
	}

	//捛壛
	public synchronized void Addmod(REReserveData mod)
	{
		synchronized(IdxList){
			IdxList.add(mod);
		}
	}

	//捛壛
	public synchronized void Addmod(int id,REReserveData mod)
	{
		synchronized(IdxList){
			IdxList.add(id,mod);
		}
	}

	//捛壛
	public synchronized void Addmod(String bid,REReserveData mod)
	{
		int hit = -1;
		synchronized(IdxList){
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				REReserveData mod1 = (REReserveData)it.next();
				if( bid.equals( mod1.GetId()) ) {
					hit = i;
					break;
				}
			}
			if(hit == -1)
				IdxList.add(mod);
			else
				IdxList.set(hit,mod);
		}
	}

	//峏怴
	public synchronized REReserveData Getmod(int index)
	{
		REReserveData mod = null;
		synchronized(IdxList){
			if( (index>=0)&&(index<IdxList.size()))
				mod = (REReserveData)IdxList.get(index);
			return mod ;
		}
	}

	//峏怴
	public synchronized void update(REReserveData mod)
	{
		synchronized(IdxList){
			IdxList.set(hitcnt,mod);
		}
	}

	public synchronized String[] toModsString()
	{
		synchronized(IdxList){
			Iterator it=IdxList.iterator();
			String[] mods=new String[IdxList.size()];
			for(int i=0;i<IdxList.size();i++) {
				REReserveData mod = (REReserveData)it.next();
				mods[i] = mod.GetId() + ","  + GSTool.delimitEncorde(",",mod.GetName()) + ","  + mod.GetStart()
					+ ","  + mod.GetEnd() + ","  + GSTool.delimitEncorde(",",mod.GetObject())
					+ ","  + GSTool.delimitEncorde(",",mod.GetNote()) + ","  + mod.GetUid();
			}
			return mods;
		}
	}

	//倀俹
	public synchronized void Upuid(String bid)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (REReserveData)it.next();
				if( bid.equals( data.GetId()) ) {
					cnt = i ;
					break;
				}
			}
			if(cnt == 0)//愭摢
				return;
			if(cnt != -1) {
				data = (REReserveData)IdxList.get(cnt-1);
				IdxList.set(cnt-1,IdxList.get(cnt));
				IdxList.set(cnt,data);
			}
		}
	}

	//俢俷倂俶
	public synchronized void Downuid(String bid)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (REReserveData)it.next();
				if( bid.equals( data.GetId()) ) {
					cnt = i ;
					break;
				}
			}
			if(cnt == IdxList.size())//嵟屻
				return;
			if(cnt != IdxList.size()) {
				data = (REReserveData)IdxList.get(cnt+1);
				IdxList.set(cnt+1,IdxList.get(cnt));
				IdxList.set(cnt,data);
			}
		}
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -