// Path: src/main/java/com/zavakid/mushroom/MetricsBuilder.java
// public interface MetricsBuilder {
// 
//     /**
//      * Add a metrics record
//      * 
//      * @param name of the record
//      * @return a metrics record builder for the record
//      */
//     public MetricsRecordBuilder addRecord(String name);
// }
// 
// Path: src/main/java/com/zavakid/mushroom/MetricsFilter.java
// public abstract class MetricsFilter implements MetricsPlugin {
// 
//     public abstract void init(SubsetConfiguration conf);
// 
//     /**
//      * Whether to accept the name
//      * 
//      * @param name to filter on
//      * @return true to accept; false otherwise.
//      */
//     public abstract boolean accepts(String name);
// 
//     /**
//      * Whether to accept the tag
//      * 
//      * @param tag to filter on
//      * @return true to accept; false otherwise
//      */
//     public abstract boolean accepts(MetricsTag tag);
// 
//     /**
//      * Whether to accept the tags
//      * 
//      * @param tags to filter on
//      * @return true to accept; false otherwise
//      */
//     public abstract boolean accepts(Iterable<MetricsTag> tags);
// 
//     /**
//      * Whether to accept the record
//      * 
//      * @param record to filter on
//      * @return true to accept; false otherwise.
//      */
//     public boolean accepts(MetricsRecord record) {
//         return accepts(record.tags());
//     }
// 
// }


import com.zavakid.mushroom.MetricsBuilder;
import com.zavakid.mushroom.MetricsFilter;
import java.util.ArrayList;
import java.util.List;
/**
   Copyright [2013] [Mushroom]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
/**
 Notice : this source is extracted from Hadoop metric2 package
 and some source code may changed by zavakid
 */
package com.zavakid.mushroom.impl;



/**
 * @author Hadoop metric2 package's authors
 * @since 0.1
 */
public class MetricsBuilderImpl extends ArrayList<MetricsRecordBuilderImpl> implements MetricsBuilder {

    private static final long serialVersionUID = 1L;
    private MetricsFilter     recordFilter, metricFilter;

    @Override
    public MetricsRecordBuilderImpl addRecord(String name) {
        boolean acceptable = recordFilter == null || recordFilter.accepts(name);
        MetricsRecordBuilderImpl rb = new MetricsRecordBuilderImpl(name, recordFilter, metricFilter, acceptable);
        if (acceptable) {
            add(rb);
        }
        return rb;
    }

    public List<MetricsRecordImpl> getRecords() {
        List<MetricsRecordImpl> records = new ArrayList<MetricsRecordImpl>(size());
        for (MetricsRecordBuilderImpl rb : this) {
            MetricsRecordImpl mr = rb.getRecord();
            if (mr != null) {
// Path: src/main/java/com/zavakid/mushroom/MetricsBuilder.java
// public interface MetricsBuilder {
// 
//     /**
//      * Add a metrics record
//      * 
//      * @param name of the record
//      * @return a metrics record builder for the record
//      */
//     public MetricsRecordBuilder addRecord(String name);
// }
// 
// Path: src/main/java/com/zavakid/mushroom/MetricsFilter.java
// public abstract class MetricsFilter implements MetricsPlugin {
// 
//     public abstract void init(SubsetConfiguration conf);
// 
//     /**
//      * Whether to accept the name
//      * 
//      * @param name to filter on
//      * @return true to accept; false otherwise.
//      */
//     public abstract boolean accepts(String name);
// 
//     /**
//      * Whether to accept the tag
//      * 
//      * @param tag to filter on
//      * @return true to accept; false otherwise
//      */
//     public abstract boolean accepts(MetricsTag tag);
// 
//     /**
//      * Whether to accept the tags
//      * 
//      * @param tags to filter on
//      * @return true to accept; false otherwise
//      */
//     public abstract boolean accepts(Iterable<MetricsTag> tags);
// 
//     /**
//      * Whether to accept the record
//      * 
//      * @param record to filter on
//      * @return true to accept; false otherwise.
//      */
//     public boolean accepts(MetricsRecord record) {
//         return accepts(record.tags());
//     }
// 
// }


// Path: src/main/java/com/zavakid/mushroom/impl/MetricsBuilderImpl.java
import com.zavakid.mushroom.MetricsBuilder;
import com.zavakid.mushroom.MetricsFilter;
import java.util.ArrayList;
import java.util.List;

/**
   Copyright [2013] [Mushroom]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
/**
 Notice : this source is extracted from Hadoop metric2 package
 and some source code may changed by zavakid
 */
package com.zavakid.mushroom.impl;



/**
 * @author Hadoop metric2 package's authors
 * @since 0.1
 */
public class MetricsBuilderImpl extends ArrayList<MetricsRecordBuilderImpl> implements MetricsBuilder {

    private static final long serialVersionUID = 1L;
    private MetricsFilter     recordFilter, metricFilter;

    @Override
    public MetricsRecordBuilderImpl addRecord(String name) {
        boolean acceptable = recordFilter == null || recordFilter.accepts(name);
        MetricsRecordBuilderImpl rb = new MetricsRecordBuilderImpl(name, recordFilter, metricFilter, acceptable);
        if (acceptable) {
            add(rb);
        }
        return rb;
    }

    public List<MetricsRecordImpl> getRecords() {
        List<MetricsRecordImpl> records = new ArrayList<MetricsRecordImpl>(size());
        for (MetricsRecordBuilderImpl rb : this) {
            MetricsRecordImpl mr = rb.getRecord();
            if (mr != null) {
                records.add(mr);