Coverage details for umich.cac.data.MemField

LineHitsSource
1 package umich.cac.data;
2  
3 import java.util.logging.Level;
4 import java.util.logging.Logger;
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7  
8 import umich.cac.pbs.FieldFactory;
9  
10 /**
11  * This class encapsulates memory field data. Memory in PBS is encoded as
12  * "1234kb" where the data AND the unites are in the same field. It is nice to
13  * have the units seperate from the data. Thus two children are created MEMORY
14  * and UNITS, so the results XML looks like
15  *
16  * <pre>
17  * &ltmem&gt &ltmemory>15848&lt/memory&gt &ltunits>kb&lt/units&gt &lt/mem&gt
18  * </pre>
19  *
20  * @author rmach@umich.edu
21  * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/data/MemField.java,v 1.3 2003/10/21 19:08:00 rodmach Exp $
22  */
23 public class MemField extends Field {
24  
25     
2618    private Logger logger = Logger.getLogger(MemField.class.getName());
27  
28     /**
29      * Constructor for MemField field
30      *
31      * @param fieldName
32      * FieldName describing this field, like MEM or VMEM
33      * @param rawValue
34      * The raw value of this field from accounting data
35      */
36     public MemField(FieldName fieldName, String rawValue) {
3715        super(fieldName, rawValue, fieldName.getFieldType());
3815        setupChildren(rawValue);
3915    }
40  
41     /**
42      * Contains children of type node.
43      *
44      * @param rawValue
45      * The raw value of this field from accounting data
46      */
47     private void setupChildren(String rawValue) {
48  
49         //The pattern matchines 1234kb for example
5015        String patternStr = "(\\d+)(\\S+)";
5115        Pattern pattern = Pattern.compile(patternStr);
5215        Matcher matcher = pattern.matcher(rawValue);
5315        boolean matchFound = matcher.find();
54  
55         //Look for a match, we should always find one if data is in correct
56         // format
5715        if (matchFound) {
5815            if (matcher.groupCount() == 2) {
59  
60                 //The memory is the match from group 1, the (\\d+)
6115                String memory = matcher.group(1);
62                 //The units is the match from group 2, the (\\S+)
6315                String units = matcher.group(2);
64  
65                 //Add the child nodes
6615                Field memoryNode =
67                     FieldFactory.getInstance().getField(
68                         FieldName.MEMORY,
69                         memory);
7015                addChild(memoryNode);
71  
7215                Field unitsNode =
73                     FieldFactory.getInstance().getField(FieldName.UNITS, units);
7415                addChild(unitsNode);
75  
76             } else {
770                if (logger.isLoggable(Level.WARNING)) {
780                    logger.warning(
79                         "The group count for "
80                             + rawValue
81                             + " is not correct, it should be 2");
82                 }
83             }
84         } else {
850            if (logger.isLoggable(Level.WARNING)) {
860                logger.warning(
87                     "The regex of "
88                         + patternStr
89                         + " did not match "
90                         + rawValue
91                         + " so discarding");
92             }
93         }
94  
9515    }
96  
97 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.