Coverage Report - org.apache.commons.betwixt.expression.CollectionUpdater

Classes in this File Line Coverage Branch Coverage Complexity
CollectionUpdater
100% 
100% 
2.5

 1  
 /*
 2  
  * Copyright 2006 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 package org.apache.commons.betwixt.expression;
 17  
 
 18  
 import java.util.Collection;
 19  
 
 20  
 /**
 21  
  * Updates a Collection by adding the new value to it.
 22  
  */
 23  66
 public class CollectionUpdater implements Updater {
 24  
 
 25  
     private static CollectionUpdater INSTANCE;
 26  
     
 27  
     /**
 28  
      * Gets singleton instance.
 29  
      * @return <code>CollectionUpdater</code>, not null
 30  
      */
 31  
     public static synchronized CollectionUpdater getInstance() {
 32  180
          if (INSTANCE == null) {
 33  66
              INSTANCE = new CollectionUpdater();
 34  
          }
 35  180
          return INSTANCE;
 36  
     }
 37  
     
 38  
     /**
 39  
      * Updates collection contained by the context by adding the new value.
 40  
      * @param context <code>Context</code>, not null
 41  
      * @param newValue value to be added, possibly null 
 42  
      */
 43  
     public void update(Context context, Object newValue) {
 44  54
             if (newValue != null) {
 45  36
                 Object subject = context.getBean();
 46  36
                 if (subject != null && subject instanceof Collection) {
 47  24
                     Collection collection = (Collection) subject;
 48  24
                     collection.add(newValue);
 49  
                 }
 50  
             }
 51  54
     }
 52  
 }