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

📄 resource.java

📁 java code for seifer secds
💻 JAVA
字号:
/* * (C) Copyright 2005 Davide Brugali, Marco Torchiano * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307  USA */package scheduler;import java.util.*;public class Resource {  class CompareActivity implements Comparator {    public int compare(Object o1, Object o2) {      Activity t1 = (Activity) o1;      Activity t2 = (Activity) o2;      if(t1.getActivation() > t2.getActivation())    return 1;      if(t1.getActivation() < t2.getActivation())    return -1;      return t1.getName().compareTo(t2.getName());    }  }  private String name;  private ArrayList activities = new ArrayList();  private double gain = 0.0;  public Resource(String name) {    this.name = name;  }  public String getName() { return name; }  public void addActivity(Activity activity) {    activities.add(activity);  }  public void addTask(Task task) {    Iterator iterator = task.getActivities();    Activity activity;    while(iterator.hasNext())      activities.add( (Activity) iterator.next() );  }  public void setGain(double gain) {    this.gain = gain;  }  public void reset() {    Iterator iterator = activities.iterator();    Activity activity;    while(iterator.hasNext()) {      activity = (Activity) iterator.next();      activity.reset();    }  }  public void schedule() {    // updates the activationTime of each activity    for(int i=0; i < activities.size(); i++)      ((Activity) activities.get(i)).update(gain);    // sorts the list of activities for activationTime    Collections.sort(activities, new CompareActivity());    // evaluates the new completionTime of each activity    Activity previous = (Activity) activities.get(0);    for(int i=1; i < activities.size(); i++) {      Activity activity = (Activity) activities.get(i);      activity.serialize(previous);      previous = activity;    }  }  public double getPerformance() {    double performance = 0.0;    for(int i=0; i < activities.size(); i++) {      Activity activity = (Activity) activities.get(i);      performance += activity.getPerformance();    }    return performance;  }  public void store() {    for(int i=0; i < activities.size(); i++) {      Activity activity = (Activity) activities.get(i);      activity.store();    }  }  public void restore() {    for(int i=0; i < activities.size(); i++) {      Activity activity = (Activity) activities.get(i);      activity.restore();    }  }  public String toString() {    String result = "\nResource " + name;    for(int i=0; i < activities.size(); i++)      result = result.concat("\n   "+((Activity) activities.get(i)).toString());    return result;  }// P2 - begin  public Iterator getActivities() {    return activities.iterator();  }// P2 - end}

⌨️ 快捷键说明

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