Coverage Report - org.apache.onami.configuration.variables.MixinAppender
 
Classes in this File Line Coverage Branch Coverage Complexity
MixinAppender
80%
17/21
91%
11/12
2.5
 
 1  
 package org.apache.onami.configuration.variables;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Arrays;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * Composition appender which delegates the resolving to an inner list of appenders.
 29  
  */
 30  
 final class MixinAppender
 31  
     extends AbstractAppender
 32  
 {
 33  
 
 34  
     /** Inner appenders */
 35  442
     private final List<Appender> appenders = new ArrayList<Appender>();
 36  
 
 37  
     /**
 38  
      * Constructor from array.
 39  
      *
 40  
      * @param chunk
 41  
      * @param appenders
 42  
      */
 43  
     public MixinAppender( String chunk, Appender... appenders )
 44  
     {
 45  0
         this( chunk, Arrays.asList( appenders ) );
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Constructor from list.
 50  
      *
 51  
      * @param chunk
 52  
      * @param appenders
 53  
      */
 54  
     public MixinAppender( String chunk, List<Appender> appenders )
 55  
     {
 56  442
         super( chunk );
 57  442
         this.appenders.addAll( appenders );
 58  442
     }
 59  
 
 60  
     @Override
 61  
     public void doAppend( StringBuilder buffer, Map<String, String> configuration, Tree<Appender> context )
 62  
     {
 63  6910
         for ( Appender appender : appenders )
 64  
         {
 65  23278
             appender.append( buffer, configuration, context );
 66  
         }
 67  6910
     }
 68  
 
 69  
     @Override
 70  
     public boolean equals( Object obj )
 71  
     {
 72  44016
         if ( obj == this )
 73  
         {
 74  0
             return true;
 75  
         }
 76  44016
         if ( obj instanceof MixinAppender )
 77  
         {
 78  690
             MixinAppender other = (MixinAppender) obj;
 79  690
             if ( appenders.size() == other.appenders.size() )
 80  
             {
 81  12
                 return appenders.containsAll( other.appenders );
 82  
             }
 83  
         }
 84  44004
         return false;
 85  
     }
 86  
 
 87  
     @Override
 88  
     public int hashCode()
 89  
     {
 90  0
         return appenders.hashCode();
 91  
     }
 92  
 
 93  
     /**
 94  
      * @return True if at least one of the inner appenders need resolving
 95  
      */
 96  
     public boolean needsResolving()
 97  
     {
 98  192
         for ( Appender appender : appenders )
 99  
         {
 100  312
             if ( appender.needsResolving() )
 101  
             {
 102  188
                 return true;
 103  
             }
 104  
         }
 105  4
         return false;
 106  
     }
 107  
 
 108  
 }