|
Last change
on this file was
6,
checked in by dsowen, 21 years ago
|
|
Split out the access stuff into accesslib.
New Creator interface off-loads object creation to user.
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * Created on Apr 24, 2005 |
|---|
| 3 | * |
|---|
| 4 | * $Log$ |
|---|
| 5 | * Revision 1.3 2005/09/21 22:00:45 dsowen |
|---|
| 6 | * Split out the access stuff into accesslib. |
|---|
| 7 | * New Creator interface off-loads object creation to user. |
|---|
| 8 | * |
|---|
| 9 | * Revision 1.2 2005/08/19 17:51:17 dsowen |
|---|
| 10 | * Fixed: NPEs when using accessors from paths, &c. Included tests. |
|---|
| 11 | * Fixed: parsing exception wasn't very enlightening. |
|---|
| 12 | * |
|---|
| 13 | * Revision 1.1 2005/08/03 00:35:29 dsowen |
|---|
| 14 | * Initial commit. |
|---|
| 15 | * |
|---|
| 16 | * Revision 1.1 2005/04/25 01:39:53 dowen |
|---|
| 17 | * Preliminary path support. |
|---|
| 18 | * |
|---|
| 19 | */ |
|---|
| 20 | package ws.fugue88.jpath; |
|---|
| 21 | |
|---|
| 22 | import java.util.Collections; |
|---|
| 23 | import java.util.Iterator; |
|---|
| 24 | import java.util.List; |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * @author dsowen |
|---|
| 28 | */ |
|---|
| 29 | public class Path { |
|---|
| 30 | |
|---|
| 31 | Path(final List parts) |
|---|
| 32 | { |
|---|
| 33 | _parts = parts; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public Path parents() |
|---|
| 37 | { |
|---|
| 38 | return new Path(_parts.subList(0, _parts.size() - 1)); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public Path children() |
|---|
| 42 | { |
|---|
| 43 | return new Path(_parts.subList(1, _parts.size())); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public PathPart head() |
|---|
| 47 | { |
|---|
| 48 | return (PathPart)_parts.get(0); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | public PathPart terminal() |
|---|
| 52 | { |
|---|
| 53 | return (PathPart)_parts.get(_parts.size() - 1); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public Iterator iterator() |
|---|
| 57 | { |
|---|
| 58 | return Collections.unmodifiableList(_parts).iterator(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public boolean isEmpty() |
|---|
| 62 | { |
|---|
| 63 | return _parts.isEmpty(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | public String toString() |
|---|
| 67 | { |
|---|
| 68 | final StringBuffer buff = new StringBuffer(); |
|---|
| 69 | for(final Iterator i = _parts.iterator(); i.hasNext();) { |
|---|
| 70 | buff.append(i.next()); |
|---|
| 71 | } |
|---|
| 72 | return buff.toString(); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | private final List _parts; |
|---|
| 76 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.