📄 csupercache.java
字号:
//Source file: E:/工作和学习/工作/硕士论文工作/程序/数据库缓存管理/20040304/src/DBCachePak/CSuperCache.java
/* tangtang */
package DBCachePak;
/**
* @author
* @version
*/
public class CSuperCache
{
private boolean CachLock = false;
private int tepcn = 0;
public SuperCacheNode head;
public SuperCacheNode tail;
public SuperCacheNode curr;
/**
* @param sz
* @return void
* @exception
* @author
* @version
* @roseuid 40693E630020
*/
public CSuperCache(int sz)
{
setup();
if(SuperCacheNode.freelist==null)
{
SuperCacheNode temp=new SuperCacheNode(null);
SuperCacheNode.freelist=temp;
}
for(int i=0;i<sz-1;i++)
{
SuperCacheNode temp= SuperCacheNode.freelist;
SuperCacheNode.freelist= new SuperCacheNode(null);
SuperCacheNode.freelist.next=temp;
}
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 406B7A6F00E9
*/
private void setup()
{
tail=head=curr=new SuperCacheNode(null);
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 406B7AF70157
*/
public void clear()
{
if(CachLock==true)
{
head.setNext(null);
curr=tail=head;
}
}
/**
* @param Aelement
* @return void
* @exception
* @author
* @version
* @roseuid 406B7B2A035A
*/
public void insert(CacheReferences Aelement)
{
Assertion.check(curr==null,"No current element");
if(CachLock==true)
{
try
{
SuperCacheNode temp=SuperCacheNode.get(Aelement,curr.next());
if(temp==null)
{
System.out.println("高速缓存满,插入失败!");
return;
}
curr.setNext(temp); //Get a free node
}
catch(Exception e)
{
System.out.println("异常,插入失败!");
}
if (tail==curr)
tail=curr.next();
}
}
/**
* @param Aelement
* @return void
* @exception
* @author
* @version
* @roseuid 406B7BA00222
*/
public void append(CacheReferences Aelement)
{
if(CachLock==true)
{
try
{
SuperCacheNode temp=SuperCacheNode.get(Aelement,null);
if(temp==null)
{
System.out.println("高速缓存满,插入失败!");
return;
}
tail.setNext(temp);
tail=tail.next();
}
catch(Exception e)
{
System.out.println("异常,插入失败!");
}
}
}
/**
* @return CacheReferences
* @exception
* @author
* @version
* @roseuid 406B7BF201A5
*/
public CacheReferences remove()
{
Assertion.check(isInList(),"No current element");
if(CachLock==true)
{
if(!isInList()) return null;
CacheReferences it =curr.next().GetElement();
if(tail==curr.next()) tail=curr;
SuperCacheNode tempptr=curr.next();
curr.setNext(curr.next().next());
tempptr.release();
return it;
}
else return null;
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 406B7C1702CE
*/
public void setFirst()
{
if(CachLock==true)
curr=head;
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 406B7C2F03A9
*/
public void next()
{
if(CachLock==true)
{
if (curr!=null) curr=curr.next();
}
}
/**
* @return int
* @exception
* @author
* @version
* @roseuid 406B7C7502CE
*/
public int length()
{
if(CachLock==true)
{
int cnt=0;
for(SuperCacheNode temp=head.next();temp!=null;temp=temp.next())
cnt++;
return cnt;
}
return 0;
}
/**
* @param Aelement
* @return void
* @exception
* @author
* @version
* @roseuid 406B7CBF0109
*/
public void setValue(CacheReferences Aelement)
{
Assertion.check(isInList(),"No current element");
if(CachLock==true)
{
curr.next().SetElement(Aelement);
}
}
/**
* @return CacheReferences
* @exception
* @author
* @version
* @roseuid 406B7D0903B8
*/
public CacheReferences currValue()
{
if(CachLock==true)
{
if(!isInList()) return null;
return curr.next().GetElement();
}
return null;
}
/**
* @return boolean
* @exception
* @author
* @version
* @roseuid 406B7D330128
*/
public boolean isEmpty()
{
return head.next()==null;
}
/**
* @return boolean
* @exception
* @author
* @version
* @roseuid 406B7D5E01E3
*/
public boolean isInList()
{
return(curr!=null)&&(curr.next()!=null);
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 406B7D8E01F3
*/
public void print()
{
if(isEmpty()) System.out.println("()");
else
{
System.out.println("(");
for(setFirst();isInList();next())
{ for(int i=0;i<=30;i++)
System.out.print(currValue().GetValues()[i]+" ");
System.out.println();
}
System.out.println(")");
}
}
/**
* @return void
* @exception
* @author
* @version
* @roseuid 40700CC00170
*/
public void prev()
{
if(CachLock==true)
{
if((curr==null)||(curr==head))
{curr=null;
return;
}
SuperCacheNode temp=head;
while ((temp!=null)&&(temp.next()!=curr))
temp=temp.next();
curr=temp;
}
}
/**
* @param pos
* @return void
* @exception
* @author
* @version
* @roseuid 4070153201BF
*/
public void setPos(int pos)
{
if(CachLock==true)
{
curr=head;
for(int i=0;(curr!=null)&&(i<pos);i++)
curr=curr.next();
}
}
/**
* @return boolean
* @exception
* @author
* @version
* @roseuid 40715C320145
*/
public boolean open()
{
CachLock=true;
return CachLock;
}
/**
* @return boolean
* @exception
* @author
* @version
* @roseuid 40715CCE030B
*/
public boolean close()
{
CachLock=false;
return CachLock;
}
/**
* @param paraName
* @param paraValue
* @return int
* @exception
* @author
* @version
* @roseuid 4072135F0211
*/
public int GetQueryCount(String paraName, String paraValue)
{
int location=ParseName(paraName);
String str;
setFirst();
tepcn=0;
while(isInList())
{
CacheReferences aRef=currValue();
str=aRef.GetValues()[location];
if(str==paraValue)
{
tepcn++;
// aRef.GetValues();
}
next();
}
return tepcn;
}
/**
* @param paraName
* @param paraValue
* @return String[][]
* @exception
* @author
* @version
* @roseuid 4072138E031A
*/
public String[][] GetQueryResult(String paraName, String paraValue)
{
int location=ParseName(paraName);
int cn=0;
String str;
String [][] relt=new String[tepcn][31];
setFirst();
while(isInList())
{
CacheReferences aRef=currValue();
str=aRef.GetValues()[location];
if(str==paraValue)
{
relt[cn]=aRef.GetValues();
cn++;
}
next();
}
return relt;
}
/**
* @param columnName
* @return int
* @exception
* @author
* @version
* @roseuid 407219960220
*/
public int ParseName(String columnName)
{
if(columnName.equals("SourceFileName"))
return 0;
else if(columnName.equals("CacheFileName"))
return 1;
else if(columnName.equals("ScreenSize"))
return 23;
else return 9999;
}
/**
* @param paraName
* @param paraValue
* @return boolean
* @exception
* @author
* @version
* @roseuid 407CDA300148
*/
public boolean delete(String paraName, String paraValue)
{
try
{
int location=ParseName(paraName);
String str;
setFirst();
tepcn=0;
while(isInList())
{
CacheReferences aRef=currValue();
str=aRef.GetValues()[location];
if(str.equals(paraValue))
{
remove();
}
else next();
}
return true;
}
catch(Exception e)
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -