Coverage Report - org.simpleframework.xml.core.LabelGroup
 
Classes in this File Line Coverage Branch Coverage Complexity
LabelGroup
90%
9/10
50%
1/2
1.5
 
 1  
 /*
 2  
  * LabelGroup.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.core;
 20  
 
 21  
 import java.util.Arrays;
 22  
 import java.util.List;
 23  
 
 24  
 /**
 25  
  * The <code>LabelList</code> contains a group of labels associated
 26  
  * with a specific contact. Here any number of annotations can be
 27  
  * associated with a single contact. This allows for element unions
 28  
  * that may contain more than one label to be represented.
 29  
  * 
 30  
  * @author Niall Gallagher
 31  
  */
 32  
 class LabelGroup {
 33  
    
 34  
    /**
 35  
     * This contains the list of labels associated with a contact.
 36  
     */
 37  
    private final List<Label> list;
 38  
    
 39  
    /**
 40  
     * This contains the number of labels this list contains.
 41  
     */
 42  
    private final int size;
 43  
    
 44  
    /**
 45  
     * Constructor for the <code>LabelList</code> object. This is 
 46  
     * used to create a group of labels that contains a single 
 47  
     * label. Typically this is used for non-union annotations.
 48  
     * 
 49  
     * @param label this is the label that this group represents
 50  
     */
 51  
    public LabelGroup(Label label) {
 52  3325
       this(Arrays.asList(label));
 53  3325
    }
 54  
    
 55  
    /**
 56  
     * Constructor for the <code>LabelList</code> object. This is 
 57  
     * used to create a group of labels that contains a multiple 
 58  
     * labels. Typically this is used for union annotations.
 59  
     * 
 60  
     * @param list this is the labels that this group contains
 61  
     */
 62  3489
    public LabelGroup(List<Label> list) {
 63  3489
       this.size = list.size();
 64  3489
       this.list = list;
 65  3489
    }
 66  
    
 67  
    /**
 68  
     * This is used to acquire all of the labels associated with
 69  
     * this group. For a non-union annotation this will contain 
 70  
     * a list containing a single label object.
 71  
     * 
 72  
     * @return this returns a list containing a single label
 73  
     */
 74  
    public List<Label> getList() {
 75  165
       return list;
 76  
    }
 77  
    
 78  
    /**
 79  
     * This is used to acquire the primary label associated with
 80  
     * this group. If this group represents a non-union then this
 81  
     * will return the only label associated with the contact.
 82  
     * 
 83  
     * @return this returns the primary annotation for the group
 84  
     */
 85  
    public Label getPrimary(){
 86  3472
       if(size > 0) {
 87  3472
          return list.get(0);
 88  
       }
 89  0
       return null;
 90  
    }
 91  
 }