Coverage Report - nextgrid.api.pom.QueryProfile
 
Classes in this File Line Coverage Branch Coverage Complexity
QueryProfile
0%
0/26
0%
0/14
0
 
 1  
 /*
 2  
  Copyright (C) 2006 Grid Systems, S.A.
 3  
 
 4  
  This library is free software; you can redistribute it and/or
 5  
  modify it under the terms of the GNU Lesser General Public
 6  
  License as published by the Free Software Foundation; either
 7  
  version 2.1 of the License, or (at your option) any later version.
 8  
 
 9  
  This library is distributed in the hope that it will be useful,
 10  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  
  Lesser General Public License for more details.
 13  
 
 14  
  You should have received a copy of the GNU Lesser General Public
 15  
  License along with this library; if not, write to the Free Software
 16  
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 17  
 */
 18  
 package nextgrid.api.pom;
 19  
 
 20  
 import java.io.Serializable;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collections;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 
 26  
 /**
 27  
  * Collection of queries for a single process.
 28  
  *
 29  
  * @author Rodrigo Ruiz
 30  
  */
 31  
 public class QueryProfile implements Serializable {
 32  
 
 33  
   /**
 34  
    * <code>serialVersionUID</code> attribute.
 35  
    */
 36  
   private static final long serialVersionUID = 4230594414399444504L;
 37  
 
 38  
   /**
 39  
    * The list of constraints in this profile.
 40  
    */
 41  
   private final List<Query> constraints;
 42  
 
 43  
   /**
 44  
    * Creates a new instance.
 45  
    */
 46  0
   public QueryProfile() {
 47  0
     this.constraints = new ArrayList<Query>();
 48  0
   }
 49  
 
 50  
   /**
 51  
    * Creates a new instance.
 52  
    *
 53  
    * @param constraints A list of queries defining the constraints
 54  
    */
 55  0
   public QueryProfile(List<Query> constraints) {
 56  0
     this.constraints = constraints;
 57  0
   }
 58  
 
 59  
   /**
 60  
    * Gets the constraints defined in this profile as a list of queries.
 61  
    *
 62  
    * @return A list of queries
 63  
    */
 64  
   public final List<Query> getConstraints() {
 65  0
     return Collections.unmodifiableList(this.constraints);
 66  
   }
 67  
 
 68  
   /**
 69  
    * Adds a query to the list.
 70  
    *
 71  
    * @param query The query instance to add
 72  
    */
 73  
   public final void addConstraint(Query query) {
 74  0
     if (query != null) {
 75  0
       constraints.add(query);
 76  
     }
 77  0
   }
 78  
 
 79  
   /**
 80  
    * Adds a query to the list.
 81  
    *
 82  
    * @param lang The query language
 83  
    * @param text The query text
 84  
    */
 85  
   public final void addConstraint(String lang, String text) {
 86  0
     if (lang != null && text != null) {
 87  0
       constraints.add(new Query(lang, text));
 88  
     }
 89  0
   }
 90  
 
 91  
   /**
 92  
    * Removes a query from the list.
 93  
    *
 94  
    * @param lang The query language to remove
 95  
    */
 96  
   public final void removeConstraint(String lang) {
 97  0
     if (lang != null) {
 98  0
       for (Iterator<Query> it = constraints.iterator(); it.hasNext();) {
 99  0
         Query q = it.next();
 100  0
         if (q.getLang().equals(lang)) {
 101  0
           it.remove();
 102  0
           return;
 103  
         }
 104  0
       }
 105  
     }
 106  0
   }
 107  
 
 108  
   /**
 109  
    * Removes a query from the list.
 110  
    *
 111  
    * @param index Position of the query to remove
 112  
    */
 113  
   public final void removeConstraint(int index) {
 114  0
     constraints.remove(index);
 115  0
   }
 116  
 
 117  
   /**
 118  
    * Removes a query from the list.
 119  
    *
 120  
    * @param q The query to remove
 121  
    */
 122  
   public final void removeConstraint(Query q) {
 123  0
     if (q != null) {
 124  0
       constraints.remove(q);
 125  
     }
 126  0
   }
 127  
 }