001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import java.util.*;
036:
037: import org.apache.oro.text.perl.*;
038:
039: import com.jeantessier.text.*;
040:
041: public class MetricsConfiguration {
042: private static final Perl5Util perl = new Perl5Util(
043: new MaximumCapacityPatternCache());
044:
045: private List<MeasurementDescriptor> projectMeasurements = new LinkedList<MeasurementDescriptor>();
046: private List<MeasurementDescriptor> groupMeasurements = new LinkedList<MeasurementDescriptor>();
047: private List<MeasurementDescriptor> classMeasurements = new LinkedList<MeasurementDescriptor>();
048: private List<MeasurementDescriptor> methodMeasurements = new LinkedList<MeasurementDescriptor>();
049: private Map<String, Collection<String>> groupDefinitions = new HashMap<String, Collection<String>>();
050:
051: public List<MeasurementDescriptor> getProjectMeasurements() {
052: return Collections.unmodifiableList(projectMeasurements);
053: }
054:
055: public void addProjectMeasurement(MeasurementDescriptor descriptor) {
056: projectMeasurements.add(descriptor);
057: }
058:
059: public List<MeasurementDescriptor> getGroupMeasurements() {
060: return Collections.unmodifiableList(groupMeasurements);
061: }
062:
063: public void addGroupMeasurement(MeasurementDescriptor descriptor) {
064: groupMeasurements.add(descriptor);
065: }
066:
067: public List<MeasurementDescriptor> getClassMeasurements() {
068: return Collections.unmodifiableList(classMeasurements);
069: }
070:
071: public void addClassMeasurement(MeasurementDescriptor descriptor) {
072: classMeasurements.add(descriptor);
073: }
074:
075: public List<MeasurementDescriptor> getMethodMeasurements() {
076: return Collections.unmodifiableList(methodMeasurements);
077: }
078:
079: public void addMethodMeasurement(MeasurementDescriptor descriptor) {
080: methodMeasurements.add(descriptor);
081: }
082:
083: public void addGroupDefinition(String name, String pattern) {
084: Collection<String> bucket = groupDefinitions.get(name);
085:
086: if (bucket == null) {
087: bucket = new LinkedList<String>();
088: groupDefinitions.put(name, bucket);
089: }
090:
091: bucket.add(pattern);
092: }
093:
094: public Collection<String> getGroups(String name) {
095: Collection<String> result = new HashSet<String>();
096:
097: for (String key : groupDefinitions.keySet()) {
098: if (groupDefinitions.get(key) != null) {
099: for (String pattern : groupDefinitions.get(key)) {
100: if (perl.match(pattern, name)) {
101: result.add(key);
102: }
103: }
104: }
105: }
106:
107: return result;
108: }
109: }
|