01: /*
02: * <copyright>
03: *
04: * Copyright 2001-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.glm.plugin.completion;
28:
29: import java.util.HashSet;
30: import java.util.Set;
31:
32: import org.cougaar.glm.ldm.Constants;
33: import org.cougaar.planning.ldm.plan.Task;
34: import org.cougaar.planning.ldm.plan.Verb;
35: import org.cougaar.planning.plugin.completion.CompletionCalculator;
36: import org.cougaar.planning.plugin.util.PluginHelper;
37: import org.cougaar.util.UnaryPredicate;
38:
39: /**
40: */
41: public class GLMCompletionCalculator extends CompletionCalculator {
42:
43: private static final Set ignoredVerbs = new HashSet();
44: private static final Set specialVerbs = new HashSet();
45:
46: static {
47: ignoredVerbs.add(Constants.Verb.DetermineRequirements);
48: ignoredVerbs.add(Constants.Verb.GetLogSupport);
49: ignoredVerbs.add(Constants.Verb.MaintainInventory);
50:
51: specialVerbs.add(Constants.Verb.ProjectSupply);
52: specialVerbs.add(Constants.Verb.ProjectWithdraw);
53: specialVerbs.add(Constants.Verb.Supply);
54: specialVerbs.add(Constants.Verb.Transport);
55: }
56:
57: private final long maxTime;
58:
59: public GLMCompletionCalculator(long maxTime) {
60: this .maxTime = maxTime;
61: }
62:
63: protected UnaryPredicate createPredicate() {
64: return new UnaryPredicate() {
65: public boolean execute(Object o) {
66: if (o instanceof Task) {
67: Task task = (Task) o;
68: Verb verb = task.getVerb();
69: if (!ignoredVerbs.contains(verb)) {
70: if (maxTime < Long.MAX_VALUE
71: && specialVerbs.contains(verb)) {
72: long endTime;
73: try {
74: endTime = PluginHelper.getEndTime(task);
75: } catch (IllegalArgumentException iae) {
76: // never?
77: endTime = Long.MIN_VALUE;
78: }
79: if (endTime > maxTime) {
80: return false;
81: }
82: }
83: return true;
84: }
85: }
86: return false;
87: }
88: };
89: }
90: }
|