From 46a03a3ea3c26a65e4428bc9de036a01487aeda3 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 17 Oct 2003 17:34:54 +0000 Subject: First go at refactoring for PathSpecs --- src/org/noreply/fancydress/type3/PathSpec.java | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/org/noreply/fancydress/type3/PathSpec.java (limited to 'src/org/noreply/fancydress/type3/PathSpec.java') diff --git a/src/org/noreply/fancydress/type3/PathSpec.java b/src/org/noreply/fancydress/type3/PathSpec.java new file mode 100644 index 0000000..cbc608f --- /dev/null +++ b/src/org/noreply/fancydress/type3/PathSpec.java @@ -0,0 +1,95 @@ +/* $Id$ */ +package org.noreply.fancydress.type3; + +import org.noreply.fancydress.crypto.*; +import org.noreply.fancydress.status.*; +import org.noreply.fancydress.directory.*; +import org.noreply.fancydress.misc.Util; +import org.noreply.fancydress.type3.routing.*; +import java.net.InetAddress; +import java.util.*; + + +public class PathSpec { + String pathSpec; + Path singlePath; + + private String[] tokenize(String path) throws Mix3Exception { + ArrayList nicks = new ArrayList(); + int indexFrom = 0; + int indexOf; + + while ((indexOf = path.indexOf(',', indexFrom)) != -1) { + String v = path.substring(indexFrom, indexOf).trim(); + if (v.equals("")) + throw new Mix3Exception("Invalid path."); + nicks.add( v ); + indexFrom = indexOf + 1; + } + String v = path.substring(indexFrom).trim(); + if (v.equals("")) + throw new Mix3Exception("Invalid path."); + nicks.add( v ); + + String[] result = new String[nicks.size()]; + for (int i=0; iFoo,Bar,?:Baz,*2,~1". + * + * FIXME: right now we don't do any random foo. + * + * @param path given path + */ + public PathSpec(Directory dir, String pathSpec, boolean singleLeg) throws Mix3Exception { + this.pathSpec = pathSpec; + + int crossover = pathSpec.indexOf(':'); + if (crossover < 0) + throw new Mix3Exception("Path is not a valid path: no crossover point specified."); + + Hop[] leg1 = parseHalfPath(dir, pathSpec.substring(0, crossover)); + Hop[] leg2 = parseHalfPath(dir, pathSpec.substring(crossover+1)); + singlePath = new Path(leg1, leg2); + } + + /** + * Return a path constructed from this PathSpec + * + * @param dir a directory + * @return path + */ + public Path getPath() throws Mix3Exception { + return singlePath; + } +} + -- cgit v1.2.3