Coverage Report - org.kuali.student.common.assembly.data.QueryPath
 
Classes in this File Line Coverage Branch Coverage Complexity
QueryPath
16%
7/43
0%
0/8
1.235
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 /**
 17  
  * 
 18  
  */
 19  
 package org.kuali.student.common.assembly.data;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 
 24  
 import org.kuali.student.common.assembly.data.Data.Key;
 25  
 /**
 26  
  * QueryPath is used for retrieving and storing data in the DataModel.  A path is can be represented with
 27  
  * a "/" separated string.
 28  
  * 
 29  
  * @author Kuali Student Team
 30  
  *
 31  
  */
 32  28
 public class QueryPath extends ArrayList<Key> {
 33  
         //private static final PathParser parser = GWT.create(PathParser.class);
 34  1
         private static final PathParser parser = new DefaultPathParser();
 35  
         
 36  
         private static final long serialVersionUID = 1L;
 37  
 
 38  
         public static String getWildCard() {
 39  1
                 return parser.getWildCard();
 40  
         }
 41  
         
 42  
         public static String getPathSeparator(){
 43  0
             return parser.getPathSeparator();
 44  
         }
 45  
 
 46  
         public static QueryPath parse(final String path) {
 47  1
                 return parser.parse(path);
 48  
         }
 49  
 
 50  28
         private String stringPath = null;
 51  
 
 52  
         /* (non-Javadoc)
 53  
          * @see java.util.ArrayList#add(int, java.lang.Object)
 54  
          */
 55  
         @Override
 56  
         public void add(final int index, final Key element) {
 57  0
                 stringPath = null;
 58  0
                 super.add(index, element);
 59  0
         }
 60  
 
 61  
         /* (non-Javadoc)
 62  
          * @see java.util.ArrayList#add(java.lang.Object)
 63  
          */
 64  
         @Override
 65  
         public boolean add(final Key e) {
 66  29
                 stringPath = null;
 67  29
                 return super.add(e);
 68  
         }
 69  
 
 70  
         /* (non-Javadoc)
 71  
          * @see java.util.ArrayList#addAll(java.util.Collection)
 72  
          */
 73  
         @Override
 74  
         public boolean addAll(final Collection<? extends Key> c) {
 75  0
                 stringPath = null;
 76  0
                 return super.addAll(c);
 77  
         }
 78  
 
 79  
         /* (non-Javadoc)
 80  
          * @see java.util.ArrayList#addAll(int, java.util.Collection)
 81  
          */
 82  
         @Override
 83  
         public boolean addAll(final int index, final Collection<? extends Key> c) {
 84  0
                 stringPath = null;
 85  0
                 return super.addAll(index, c);
 86  
         }
 87  
 
 88  
         /* (non-Javadoc)
 89  
          * @see java.util.ArrayList#clear()
 90  
          */
 91  
         @Override
 92  
         public void clear() {
 93  0
                 stringPath = null;
 94  0
                 super.clear();
 95  0
         }
 96  
 
 97  
         /* (non-Javadoc)
 98  
          * @see java.util.ArrayList#remove(int)
 99  
          */
 100  
         @Override
 101  
         public Key remove(final int index) {
 102  0
                 stringPath = null;
 103  0
                 return super.remove(index);
 104  
         }
 105  
 
 106  
         /* (non-Javadoc)
 107  
          * @see java.util.ArrayList#remove(java.lang.Object)
 108  
          */
 109  
         @Override
 110  
         public boolean remove(final Object o) {
 111  0
                 stringPath = null;
 112  0
                 return super.remove(o);
 113  
         }
 114  
 
 115  
         /* (non-Javadoc)
 116  
          * @see java.util.AbstractCollection#removeAll(java.util.Collection)
 117  
          */
 118  
         @Override
 119  
         public boolean removeAll(final Collection<?> c) {
 120  0
                 stringPath = null;
 121  0
                 return super.removeAll(c);
 122  
         }
 123  
 
 124  
         /* (non-Javadoc)
 125  
          * @see java.util.ArrayList#removeRange(int, int)
 126  
          */
 127  
         @Override
 128  
         protected void removeRange(final int fromIndex, final int toIndex) {
 129  0
                 stringPath = null;
 130  0
                 super.removeRange(fromIndex, toIndex);
 131  0
         }
 132  
 
 133  
         /* (non-Javadoc)
 134  
          * @see java.util.AbstractCollection#retainAll(java.util.Collection)
 135  
          */
 136  
         @Override
 137  
         public boolean retainAll(final Collection<?> c) {
 138  0
                 stringPath = null;
 139  0
                 return super.retainAll(c);
 140  
         }
 141  
 
 142  
         /* (non-Javadoc)
 143  
          * @see java.util.ArrayList#set(int, java.lang.Object)
 144  
          */
 145  
         @Override
 146  
         public Key set(final int index, final Key element) {
 147  0
                 stringPath = null;
 148  0
                 return super.set(index, element);
 149  
         }
 150  
 
 151  
         public QueryPath subPath(final int fromIndex, final int toIndex) {
 152  
                 // TODO revamp this method to use subList once GWT issue 1791 is fixed
 153  0
                 final QueryPath result = new QueryPath();
 154  0
                 for (int i = fromIndex; i < toIndex; i++) {
 155  0
                         result.add(this.get(i));
 156  
                 }
 157  0
                 return result;
 158  
         }
 159  
 
 160  
         @Override
 161  
         public String toString() {
 162  0
                 if (stringPath == null) {
 163  0
                         stringPath = parser.format(this);
 164  
                 }
 165  0
                 return stringPath;
 166  
         }
 167  
         
 168  
         public static QueryPath concat(String... paths) {
 169  0
                 QueryPath result = new QueryPath();
 170  0
                 for (String path : paths) {
 171  0
                         if (path != null) {
 172  0
                                 result.addAll(QueryPath.parse(path));
 173  
                         }
 174  
                 }
 175  0
                 return result;
 176  
         }
 177  
 }