| 1 | package de.uka.ipd.sdq.scheduler.priority.impl; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | |
| 5 | import de.uka.ipd.sdq.scheduler.priority.IPriority; |
| 6 | import de.uka.ipd.sdq.scheduler.priority.IPriorityManager; |
| 7 | |
| 8 | |
| 9 | public class PriorityManagerImpl implements IPriorityManager { |
| 10 | |
| 11 | protected IPriority highestPriority; |
| 12 | protected IPriority highPriority; |
| 13 | protected IPriority averagePriority; |
| 14 | protected IPriority lowPriority; |
| 15 | protected IPriority lowestPriority; |
| 16 | protected IPriority defaultPriority; |
| 17 | protected int direction; |
| 18 | protected int highest_value; |
| 19 | protected int lowest_value; |
| 20 | |
| 21 | public PriorityManagerImpl(int highest_value, int high_value, int average_value, int low_value, int lowest_value, int default_value){ |
| 22 | assert (highest_value >= high_value && |
| 23 | high_value >= average_value && |
| 24 | average_value >= low_value && |
| 25 | low_value >= lowest_value) || |
| 26 | (highest_value <= high_value && |
| 27 | high_value <= average_value && |
| 28 | average_value <= low_value && |
| 29 | low_value <= lowest_value) : "Priorities must be ordered!"; |
| 30 | |
| 31 | direction = highest_value > lowest_value ? 1 : -1; |
| 32 | this.highest_value = highest_value; |
| 33 | this.lowest_value = lowest_value; |
| 34 | |
| 35 | this.highestPriority = new PriorityImpl(highest_value, this); |
| 36 | this.highPriority = new PriorityImpl(high_value, this); |
| 37 | this.averagePriority = new PriorityImpl(average_value, this); |
| 38 | this.lowPriority = new PriorityImpl(low_value, this); |
| 39 | this.lowestPriority = new PriorityImpl(lowest_value, this); |
| 40 | this.defaultPriority = new PriorityImpl(default_value, this); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | public Iterable<IPriority> decreasing() { |
| 45 | return new Iterable<IPriority>(){ |
| 46 | public Iterator<IPriority> iterator() { |
| 47 | return new Iterator<IPriority>(){ |
| 48 | IPriority current = highestPriority.clone(); |
| 49 | public boolean hasNext() { |
| 50 | return lowestPriority.lessOrEqual(current); |
| 51 | } |
| 52 | public IPriority next() { |
| 53 | IPriority result = current; |
| 54 | current = current.decrease(); |
| 55 | return result; |
| 56 | } |
| 57 | public void remove() { |
| 58 | } |
| 59 | }; |
| 60 | } |
| 61 | }; |
| 62 | } |
| 63 | |
| 64 | public Iterable<IPriority> increasing() { |
| 65 | return new Iterable<IPriority>(){ |
| 66 | public Iterator<IPriority> iterator() { |
| 67 | return new Iterator<IPriority>(){ |
| 68 | IPriority current = lowestPriority.clone(); |
| 69 | public boolean hasNext() { |
| 70 | return current.lessOrEqual(highestPriority); |
| 71 | } |
| 72 | public IPriority next() { |
| 73 | IPriority result = current; |
| 74 | current = current.increase(); |
| 75 | return result; |
| 76 | } |
| 77 | public void remove() { |
| 78 | } |
| 79 | }; |
| 80 | } |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | public IPriority getDefaultPriority() { |
| 85 | return defaultPriority.clone(); |
| 86 | } |
| 87 | |
| 88 | public IPriority getHighestPriority() { |
| 89 | return highestPriority.clone(); |
| 90 | } |
| 91 | |
| 92 | public IPriority getLowestPriority() { |
| 93 | return lowestPriority.clone(); |
| 94 | } |
| 95 | |
| 96 | public IPriority getAveragePriority() { |
| 97 | return averagePriority.clone(); |
| 98 | } |
| 99 | |
| 100 | public IPriority getHighPriority() { |
| 101 | return highPriority.clone(); |
| 102 | } |
| 103 | |
| 104 | public IPriority getLowPriority() { |
| 105 | return lowPriority.clone(); |
| 106 | } |
| 107 | } |