Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PathNavigator |
|
| 2.25;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 | final private List list; | |
33 | ||
34 | private int currentPosition; | |
35 | ||
36 | public PathNavigator( String path ) | |
37 | 97 | { |
38 | 97 | list = Arrays.asList( StringUtils.split( path, "/" ) ); |
39 | 97 | currentPosition = list.size(); |
40 | 97 | } |
41 | ||
42 | public String getPath() | |
43 | { | |
44 | 261 | List currentPathList = list.subList( 0, currentPosition ); |
45 | 261 | StringBuffer sb = new StringBuffer(); |
46 | 1050 | for ( int i = 0; i < currentPathList.size(); i++ ) |
47 | { | |
48 | 789 | sb.append( currentPathList.get( i ) ); |
49 | 789 | sb.append( '/' ); |
50 | } | |
51 | 261 | return sb.toString(); |
52 | } | |
53 | ||
54 | public boolean backward() | |
55 | { | |
56 | 94 | if ( currentPosition == 0 ) |
57 | { | |
58 | 13 | return false; |
59 | } | |
60 | 81 | currentPosition--; |
61 | 81 | return true; |
62 | } | |
63 | ||
64 | public boolean forward() | |
65 | { | |
66 | 178 | if ( currentPosition + 1 > list.size() ) |
67 | { | |
68 | 97 | return false; |
69 | } | |
70 | 81 | currentPosition++; |
71 | 81 | return true; |
72 | } | |
73 | } |