Coverage Report - org.apache.maven.wagon.providers.webdav.PathNavigator
 
Classes in this File Line Coverage Branch Coverage Complexity
PathNavigator
100 %
18/18
100 %
6/6
2,25
 
 1  
 package org.apache.maven.wagon.providers.webdav;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.codehaus.plexus.util.StringUtils;
 23  
 
 24  
 import java.util.List;
 25  
 import java.util.Arrays;
 26  
 
 27  
 /**
 28  
  * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
 29  
  */
 30  
 public class PathNavigator
 31  
 {
 32  
     private final List<String> list;
 33  
 
 34  
     private int currentPosition;
 35  
 
 36  
     public PathNavigator( String path )
 37  105
     {
 38  105
         list = Arrays.asList( StringUtils.split( path, "/" ) );
 39  105
         currentPosition = list.size();
 40  105
     }
 41  
 
 42  
     public String getPath()
 43  
     {
 44  277
         List<String> currentPathList = list.subList( 0, currentPosition );
 45  277
         StringBuffer sb = new StringBuffer();
 46  1086
         for ( int i = 0; i < currentPathList.size(); i++ )
 47  
         {
 48  809
             sb.append( currentPathList.get( i ) );
 49  809
             sb.append( '/' );
 50  
         }
 51  277
         return sb.toString();
 52  
     }
 53  
 
 54  
     public boolean backward()
 55  
     {
 56  102
         if ( currentPosition == 0 )
 57  
         {
 58  17
             return false;
 59  
         }
 60  85
         currentPosition--;
 61  85
         return true;
 62  
     }
 63  
 
 64  
     public boolean forward()
 65  
     {
 66  190
         if ( currentPosition + 1 > list.size() )
 67  
         {
 68  105
             return false;
 69  
         }
 70  85
         currentPosition++;
 71  85
         return true;
 72  
     }
 73  
 }