~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/cullconv/src/com/sun/grid/cull/CullDefinitionFilter.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.cull;
 
33
 
 
34
import java.util.HashSet;
 
35
import java.util.List;
 
36
import java.util.Set;
 
37
import java.util.logging.Level;
 
38
import java.util.logging.Logger;
 
39
 
 
40
/**
 
41
 *
 
42
 */
 
43
public class CullDefinitionFilter {
 
44
    
 
45
   private static Logger logger = Logger.getLogger("cullconv");
 
46
    
 
47
   private String [] includes;
 
48
   private String [] excludes;
 
49
   private String objectFilter;
 
50
   private boolean printDependencies;
 
51
    
 
52
 
 
53
    /** Creates a new instance of CullDefinitionFilter */
 
54
    public CullDefinitionFilter(String [] includes, String [] excludes) {
 
55
        this.includes = includes;
 
56
        this.excludes = excludes;
 
57
    }
 
58
    
 
59
    public java.util.Set getObjectNames(CullDefinition cullDef) {
 
60
        
 
61
         Set orgSet = cullDef.getObjectNames();
 
62
         HashSet filteredCullObjectNameSet = new HashSet();
 
63
         
 
64
         if( this.includes == null || this.includes.length == 0 ) {
 
65
            filteredCullObjectNameSet.addAll(orgSet);
 
66
         } else {
 
67
 
 
68
            for(int i = 0; i < includes.length; i++) {
 
69
               if( orgSet.contains(includes[i]) ) {
 
70
                  filteredCullObjectNameSet.add(includes[i]);
 
71
               }
 
72
            }
 
73
 
 
74
         }
 
75
         if( this.excludes != null && this.excludes.length > 0 ) {
 
76
            for(int i = 0; i < excludes.length; i++ ) {
 
77
               filteredCullObjectNameSet.remove(excludes[i]);
 
78
            }
 
79
         }
 
80
 
 
81
         if(isPrintDependencies()) {
 
82
            logger.info("dependencies --------------------------------------");
 
83
            logger.info("object filter = '" + getObjectFilter() + "'" );
 
84
         }
 
85
         CullDependencies depend = new CullDependencies(cullDef, filteredCullObjectNameSet, getObjectFilter());
 
86
         
 
87
         String [] names = new String[filteredCullObjectNameSet.size()];
 
88
         filteredCullObjectNameSet.toArray(names);
 
89
         for(int i = 0; i < names.length; i++ ) {
 
90
 
 
91
            CullDependencies.Node node = depend.getNode(names[i]);
 
92
            if( node == null ) {
 
93
               logger.warning("node for obj " + names[i] + " not found");
 
94
            } else {
 
95
 
 
96
               boolean isNeeded = node.isNeeded();
 
97
               
 
98
               if(isPrintDependencies()) {
 
99
                  logger.info(node.toString());
 
100
               } else if( logger.isLoggable(Level.FINE ) ) {
 
101
                 logger.fine(node.toString());
 
102
               }
 
103
 
 
104
               if( !isNeeded ) {
 
105
                  filteredCullObjectNameSet.remove(names[i]);
 
106
               }
 
107
            }
 
108
         }
 
109
         if(filteredCullObjectNameSet.isEmpty()) {
 
110
            logger.warning("No cull object matches the objectFilter '" + getObjectFilter() + "'");
 
111
         }
 
112
         return filteredCullObjectNameSet;
 
113
    }
 
114
 
 
115
    public String getObjectFilter() {
 
116
        return objectFilter;
 
117
    }
 
118
 
 
119
    public void setObjectFilter(String objectFilter) {
 
120
        this.objectFilter = objectFilter;
 
121
    }
 
122
 
 
123
    public boolean isPrintDependencies() {
 
124
        return printDependencies;
 
125
    }
 
126
 
 
127
    public void setPrintDependencies(boolean printDependencies) {
 
128
        this.printDependencies = printDependencies;
 
129
    }
 
130
    
 
131
}