01: /*
02: * <copyright>
03: *
04: * Copyright 2003-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: package org.cougaar.logistics.plugin.packer;
27:
28: import org.cougaar.glm.ldm.asset.Ammunition;
29: import org.cougaar.logistics.ldm.Constants;
30: import org.cougaar.planning.ldm.plan.PlanElement;
31: import org.cougaar.planning.ldm.plan.Task;
32: import org.cougaar.util.UnaryPredicate;
33:
34: /**
35: * This UnaryPredicate is used to test whether Tasks should be
36: * packed together, in the Packer's packing rule. It picks out
37: * all supply tasks that request Ammunition.
38: */
39:
40: public class ALAmmoPackerPredicate {
41:
42: public static UnaryPredicate getInputTaskPredicate() {
43: return new UnaryPredicate() {
44:
45: public boolean execute(Object o) {
46: if ((o instanceof Task)
47: && (((Task) o).getVerb()
48: .equals(Constants.Verb.SUPPLY))
49: && (((Task) o)
50: .getPrepositionalPhrase(GenericPlugin.INTERNAL) == null)
51: && (((Task) o).getDirectObject() instanceof Ammunition)
52: && (((Task) o)
53: .getPrepositionalPhrase("LOW_FIDELITY") == null)) {// BOZO - change this to a const reference later...
54: return true;
55: } else {
56: /*if ((o instanceof Task) &&
57: (((Task)o).getVerb().equals(Constants.Verb.SUPPLY))) {
58: if (((Task)o).getPrepositionalPhrase(GenericPlugin.INTERNAL) != null)
59: System.out.println ("AmmoPackerPredicate - Ignoring supply task " + ((Task)o).getUID() +
60: " b/c has internal prep.");
61: else if (!(((Task)o).getDirectObject() instanceof Ammunition))
62: System.out.println ("AmmoPackerPredicate - Ignoring supply task " + ((Task)o).getUID() +
63: " b/c d.o. not Ammunition.");
64: else if (!(((Task)o).getPrepositionalPhrase("LOW_FIDELITY") != null))
65: System.out.println ("AmmoPackerPredicate - Ignoring supply task " + ((Task)o).getUID() +
66: " b/c has LOW_FIDELITY prep.");
67: else
68: System.out.println ("AmmoPackerPredicate - Ignoring supply task " + ((Task)o).getUID() +
69: " b/c - ?");
70:
71: } */
72: return false;
73: }
74: }
75: };
76: }
77:
78: public static UnaryPredicate getPlanElementPredicate() {
79: return new UnaryPredicate() {
80: private UnaryPredicate myInputTaskPredicate = getInputTaskPredicate();
81:
82: public boolean execute(Object o) {
83: if (o instanceof PlanElement) {
84: Task task = ((PlanElement) o).getTask();
85: if (myInputTaskPredicate.execute(task)
86: || ((task
87: .getPrepositionalPhrase(GenericPlugin.INTERNAL) != null) && (task
88: .getDirectObject() instanceof Ammunition))) {
89: return true;
90: } else {
91: return false;
92: }
93: } else {
94: return false;
95: }
96: }
97: };
98: }
99: }
|