Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: Allocator/WorstFitStrategy.java


1   // WorstFitStrategy.java, created Mon Mar 17  2:03:41 2003 by laudney
2   // Copyright (C) 2001-3 laudney <laudney@acm.org>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package Allocator;
5   
6   import java.util.Collection;
7   import java.util.TreeSet;
8   
9   /**
10   * Worst Fit Strategy
11   *
12   * @author laudney <laudney@acm.org>
13   * @version $Id: WorstFitStrategy.java,v 1.2 2003/05/12 10:04:52 joewhaley Exp $
14   */
15  public class WorstFitStrategy implements FreeMemStrategy {
16      private TreeSet freePool;
17  
18      public WorstFitStrategy() {
19          freePool = new TreeSet(new MemUnitComparator());
20      }
21  
22      public void addFreeMem(MemUnit unit) {
23          freePool.add(unit);
24      }
25  
26      public void addCollection(Collection c) {
27          freePool.addAll(c);
28      }
29  
30      public MemUnit getFreeMem(int size) {
31          return (MemUnit) (freePool.last());
32      }
33  }