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

📄 resourcefile.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
字号:
/*****************************************************************************
* Author: Nithiapidary Muthuvelu, Junyang Liu and Nay Lin Soe
* Date: 30 June 2004
*
* This class reads the resource file imported and store the resource list
* in an Array list. Each resource is implemented as an object which are created
* out of the inner class, "Resource"
******************************************************************************/

   import java.io.*;
   import java.util.*;

   public class ResourceFile
   {	
      private ArrayList list;
   
		//***************************************************************
		// Constructor
		//***************************************************************
      public ResourceFile(String file) throws 	FileNotFoundException, IOException, 
       														NoSuchElementException, NumberFormatException
      {
         list = new ArrayList();		
         readFile(file);
      }
   
		//***************************************************************
		// Read the file and create ArrayList
		//***************************************************************
      public void readFile(String file) throws FileNotFoundException, IOException, 
       														NoSuchElementException, NumberFormatException
      {
         StringTokenizer token;
      
         FileReader aFile = new FileReader(file);
         BufferedReader read = new BufferedReader(aFile);
         String line;
         line = read.readLine();						//read the first line
      
         list.clear();
      
         while (line != null)							//keep reading till the line is empty
         {
            token = new StringTokenizer(line, ":");	
         
            String 	name 				= token.nextToken();
            String 	architecture	= token.nextToken();
            String 	OS					= token.nextToken();
            int 		machines			= Integer.parseInt(token.nextToken());
            int 		PE					= Integer.parseInt(token.nextToken());
            int 		MIPSofPE			= Integer.parseInt(token.nextToken());				
            long		seed				= Long.parseLong(token.nextToken());
            double	timezone			= Double.parseDouble(token.nextToken());
            double 	cost				= Double.parseDouble(token.nextToken());	
            double	baudRate			= Double.parseDouble(token.nextToken());
            double 	peakLoad			= Double.parseDouble(token.nextToken());
            double 	offPeakLoad		= Double.parseDouble(token.nextToken());
            double	holidayLoad		= Double.parseDouble(token.nextToken());
         
            Resource resource = new Resource(	name,
               											architecture,
               											OS,
               											machines,
               											PE,
               											MIPSofPE,
               											seed,
               											timezone,
               											cost,
               											baudRate,
               											peakLoad,
               											offPeakLoad,
               											holidayLoad  );
            list.add(resource);
         
            line = read.readLine();					//read next line
         
         }
      
      }
   
		//***************************************************************
 	  	// Following are the accessors and mutators.
   	//***************************************************************
      public int numberOfResources()
      {
         return list.size();
      }
   
      public String getNameOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.name;
      }
   
      public String getArchitectureOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.architecture;
      }
   
      public String getOSOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.OS;
      }
   
      public int getMachinesOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.machines;
      }
   
      public int getPEOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.PE;
      }
   
      public int getMIPSofPEOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.MIPSofPE;
      }
   
      public long getSeedOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.seed;
      }
   
      public double getTimezoneOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.timezone;
      }
   
      public double getCostOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.cost;
      }
   
      public double getBaudRateOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.baudRate;
      }
   
      public double getPeakLoadOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.peakLoad;
      }
   
      public double getOffPeakLoadOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.offPeakLoad;
      }
   
      public double getHolidayLoadOfResource(int index)
      {
         Resource r = (Resource)list.get(index);
         return r.holidayLoad;
      }
   
   
   	/********************************************************************
   	* Inner class for implementing each of the resources
   	********************************************************************/	
      private class Resource
      {
         public String 	name;
         public String 	architecture;
         public String 	OS;
         public int 		machines;
         public int 		PE;
         public int	 	MIPSofPE;
         public long		seed;
         public double	timezone;
         public double 	cost;
         public double	baudRate;
         public double 	peakLoad;
         public double 	offPeakLoad;
         public double	holidayLoad;
      
         public Resource(	String 	name,
          						String 	architecture,
          						String 	OS,
	          					int 		machines,
 	         					int 		PE,
  	  	      					int 		MIPSofPE,
   	       					long		seed,
    	      					double	timezone,
      	    					double 	cost,
       	   					double	baudRate,
        	 	 					double 	peakLoad,
         	 					double 	offPeakLoad,
          						double	holidayLoad )
         {
            this.name 			= name;
            this.MIPSofPE		= MIPSofPE;
            this.machines		= machines;
            this.PE				= PE;
            this.architecture = architecture;
            this.OS				= OS;
            this.timezone		= timezone;
            this.cost			= cost;
            this.baudRate	   = baudRate;
            this.seed			= seed;
            this.peakLoad		= peakLoad;
            this.offPeakLoad	= offPeakLoad;
            this.holidayLoad	= holidayLoad;
         }
      }
   }

⌨️ 快捷键说明

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