Coverage Report - org.kuali.student.common.assembly.data.DefaultPathParser
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultPathParser
50%
13/26
33%
4/12
2.75
 
 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.Iterator;
 22  
 
 23  
 import org.kuali.student.common.assembly.data.Data.Key;
 24  
 /**
 25  
  * @author wilj
 26  
  *
 27  
  */
 28  1
 public class DefaultPathParser implements PathParser {
 29  
 
 30  
     private static final String PATH_SEPARATOR = "/";
 31  
     
 32  
         @Override
 33  
         public String format(final QueryPath path) {
 34  0
                 final StringBuilder sb = new StringBuilder();
 35  0
                 for (final Iterator<Key> itr = path.iterator(); itr.hasNext();) {
 36  0
                         final Key key = itr.next();
 37  0
                         if (key == null) {
 38  
                                 // note, this branch should ideally never be hit
 39  
                                 // but if we throw an exception here, it breaks the eclipse debugger when trying to introspect
 40  0
                                 sb.append("null");
 41  
                         } else {
 42  0
                                 sb.append(key.toString());
 43  
                         }
 44  0
                         if (itr.hasNext()) {
 45  0
                                 sb.append(PATH_SEPARATOR);
 46  
                         }
 47  0
                 }
 48  0
                 return sb.toString();
 49  
         }
 50  
 
 51  
         @Override
 52  
         public String getWildCard() {
 53  1
                 return "*";
 54  
         }
 55  
         
 56  
         @Override
 57  
         public QueryPath parse(final String path) {
 58  1
                 final QueryPath result = new QueryPath();
 59  1
                 final String[] elements = path.split(PATH_SEPARATOR);
 60  3
                 for (String element : elements) {
 61  2
                         element = element.trim();
 62  2
                         if (!element.isEmpty()) {
 63  2
                                 Integer index = null;
 64  
                                 try {
 65  2
                                         index = Integer.valueOf(element);
 66  2
                                 } catch (final Exception e) {
 67  
                                         // do nothing
 68  0
                                 }
 69  2
                                 if (index == null) {
 70  2
                                         result.add(new Data.StringKey(element));
 71  
                                 } else {
 72  0
                                         result.add(new Data.IntegerKey(index));
 73  
                                 }
 74  
                         }
 75  
                 }
 76  1
                 return result;
 77  
         }
 78  
 
 79  
     @Override
 80  
     public String getPathSeparator() {
 81  0
         return PATH_SEPARATOR;
 82  
     }
 83  
 }