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

📄 hitcomputing.java

📁 队列调度算法的一种
💻 JAVA
字号:
//Source file: E:/工作和学习/工作/硕士论文工作/程序/数据库缓存管理/20040304/src/DBCachePak/HitComputing.java

/* tangtang */

package DBCachePak;


/**
 * @author
 * @version
 */
public class HitComputing
{
   private final int negative = 45;
   private final int zero = 48;
   private final int nine = 58;
   private final int error = 123456789;
   private final int star = 42;

   /**
    * @param InputReffers
    * @param CacheReffers
    * @return int
    * @exception
    * @author
    * @version
    * @roseuid 4075573E0128
    */
   public int Compute(String[] InputReffers, String[] CacheReffers)
   {
     String X;
     String Y;
     int hit;
     int[]  HitResultsArray=new int[31];
     for(int i=0;i<31;i++)
     HitResultsArray[i]=1;

     //  InputReffers[3] "BrowserName"
     //参数 BrowserName
     X=InputReffers[3];
     Y=CacheReffers[3];

     if(X.equals("Unknown"))
     {
       if(Y.equals("MSIE"))
         hit=1;
       else  hit=0;
     }
     else
     {
      if( X.equals(Y))
      {
        hit=1;
      }
      else
      {
        hit=0;
      }
     }
   HitResultsArray[3]=hit;

    //InputReffers[5] "CcppAccept";
    //参数 CcppAccept;
     X=InputReffers[5];
     Y=CacheReffers[5];
     String Xsub=null;
     String Ysub=null;
     int va;
     int vb;

    if(X.equals("Unknown")||X.equals("*/*"))
    {
      if(Y.equals("*/*"))
      {
        hit=1;
      }
      else
        hit=2;
    }
    else
    {
      //计算text子标签
      if(X.indexOf("text")!=-1)
      {
        int a=X.indexOf("text");
        int b=X.indexOf("/",a);
        int c=X.indexOf(",",a);
        if(c!=-1)
        {
           Xsub=X.substring(b+1,c);
        }
         else
           Xsub=X.substring(b+1);
      }
      else
        Xsub="Unknown";

      if(Y.indexOf("text")!=-1)
      {
        int a=Y.indexOf("text");
        int b=Y.indexOf("/",a);
        int c=Y.indexOf(",",a);
        if(c!=-1)
        {
           Ysub=Y.substring(b+1,c);
        }
        else
           Ysub=Y.substring(b+1);
      }
      else
        Ysub="Unknown";

      if(Xsub.equals(Ysub))
      {
         va=1;
      }
      else
       {
        if(Xsub.equals("*")||Xsub.equals("Unknown"))
        {
          if((Ysub.equals("html"))||Ysub.equals("plain"))
          {
            va=2;
          }
          else
            va=1;
        }
        else
        {
          if(Ysub.equals("Unknown"))
          {
            va=2;
          }
          else
            va=0;
        }
       }
//System.out.println(Xsub);
//System.out.println(Ysub);

     //计算image子标签
        if(X.indexOf("image")!=-1)
         {
           int a=X.indexOf("image");
           int b=X.indexOf("/",a);
           int c=X.indexOf(",",a);
           if(c!=-1)
            {
              Xsub=X.substring(b+1,c);
            }
           else
              Xsub=X.substring(b+1);
         }
         else
           Xsub="Unknown";

         if(Y.indexOf("image")!=-1)
         {
           int a=Y.indexOf("image");
           int b=Y.indexOf("/",a);
           int c=Y.indexOf(",",a);
           if(c!=-1)
            {
              Ysub=Y.substring(b+1,c);
            }
            else
               Ysub=Y.substring(b+1);
         }
         else
           Ysub="Unknown";

         if(Xsub.equals(Ysub))
         {
           vb=1;
         }
         else
           if(Xsub.equals("*")||Xsub.equals("Unknown"))
           {
             if((Ysub.equals("jpeg"))||(Ysub.equals("gif")))
             {
               vb=2;
             }
             else
               vb=1;
           }
           else
            {
            if(Ysub.equals("Unknown"))
             {
               vb=2;
             }
             else
               vb=0;
            }

      //子计算的结果相乘
      hit=va*vb;

    }

     HitResultsArray[5]=hit;

    //InputReffers[9] = "ColorCapable";
     //参数 ColorCapable
     X=InputReffers[9];
     Y=CacheReffers[9];
     if(X.equals("Unknown"))
     {
       if(Y.equals("yes"))
        hit=1;
       else  hit=0;
     }
     else
     {
      if( X.equals(Y))
      {
        hit=1;
      }
      else
      {
        hit=0;
      }
     }
    HitResultsArray[9]=hit;

    //InputReffers[13] "ImageCapable;
    //参数 ImageCapable
     X=InputReffers[13];
     Y=CacheReffers[13];
     if(X.equals("Unknown"))
    {
      if(Y.equals("yes"))
        hit=1;
      else  hit=0;
    }
    else
    {
     if( X.equals(Y))
     {
       hit=1;
     }
     else
     {
       hit=0;
     }
     }
     HitResultsArray[13]=hit;

     //InputReffers[23] "ScreenSize";
     //参数 ScreenSize
     X=InputReffers[23];
     Y=CacheReffers[23];
     int X1,X2,Y1,Y2;
     int Xstar,Ystar;
     Xstar=GetStarLocation(X);
     Ystar=GetStarLocation(Y);
     X1=StrToInt(X,0);
     X2=StrToInt(X,Xstar+1);
     Y1=StrToInt(Y,0);
     Y2=StrToInt(Y,Ystar+1);

     if(!X.equals("Unknown"))
     {
       if(X1==Y1)
       {
         if(X2==Y2)
          {
            hit=1;
          }
          if(X2<Y2)
          {
           hit=0;
          }
          if(X2>Y2)
          {
            hit=2;
          }
       }
        if(X1<Y1)
         {
           hit=4;
         }
         if(X1>Y1)
         {
           if(X2<Y2)
           {
             hit=4;
           }
           if(X2>Y2)
           {
             hit=2;
           }
         }
     }
    if(X.equals("Unknown"))
    {
      if((Y1==1024 )&&(Y2==768))
      {
         hit=1;
      }
      else
      {

        if((Y1<1024)&&(Y2<768))
        {
           hit=2;
        }
      else
         hit=0;
      }
    }

     HitResultsArray[23]=hit;

/////最后的计算工作
     int HitResult=1;
     for(int i=0;i<31;i++)
      HitResult=HitResult*HitResultsArray[i];

//打印结果
     //for(int i=0;i<31;i++)
      // System.out.print(HitResultsArray[i]);
     //System.out.println();
     return HitResult;
   }

   /**
    * @param inStr
    * @return int
    * @exception
    * @author
    * @version
    *?
    * author:wangli
    * @roseuid 4075573E0271
    */
   public int StrToInt(String inStr, int begingLocation)
   {
      Math nm=null;
     double val=1;
     int len=inStr.length();
     char c;
     int outInt=0;
     int tag;
     boolean error=false;

     if(inStr.charAt(0)==negative)
       {
         tag=1;
       }
       else
       {
         tag=0;
       }
    // len=inStr.length();
     for(int i=0+tag+begingLocation;i<len;i++)
      {
        c=inStr.charAt(i) ;
       if(c>=zero&&c<=nine)
        {
          val=nm.pow(10,(len-i-1));
          outInt=outInt+(c-zero)*(int)val;
        }
        else
          if(c==star)
          {
            return outInt/(int)val;
          }
          else
          {
            error=true;
           break;
          }
      }
      if(error==false)
      {
        if(tag==1)
        {
          return 0-outInt;
        }
        else
        {
          return outInt;
        }
      }
      else
      {
        System.out.println("Not a Integer String Error");
        return this.error;
      }
   }

   /**
    * @return
    * @exception
    * @author
    * @version
    * @roseuid 4075573E02B0
    */
   public HitComputing()
   {
   }

   /**
    * @param paraValue
    * @return int
    * @exception
    * @author
    * @version
    * @roseuid 40761008013E
    */
   public int GetStarLocation(String paraValue)
   {
     /*int Loaction=0;
     for(int i=0;i<paraValue.length();i++)
     {
       int temp=paraValue.charAt(i);
       if(temp==star)
       {
       return i;
       }
     }
     return error;*/
     int Location=0;
     Location=paraValue.indexOf("*");
     if(Location!=-1)
     {
       return Location;
     }
     else
       return error;
   }

   /**
    * @param paraValue
    * @return int
    * @exception
    * @author
    * @version
    * @roseuid 407A49CD0080
    */
   public int GetXiegangLocation(String paraValue)
   {
     int Location=0;
     Location=paraValue.indexOf("/");
     if(Location!=-1)
     {
       return Location;
     }
     else
       return error;
   }
}

⌨️ 快捷键说明

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