From 04683077fbd54d72e5d96658e04a26300323c714 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Tue, 11 Nov 2003 20:16:39 +0000 Subject: Rework PathSpec based on the now specified algorith. Some questions are still open --- src/org/noreply/fancydress/type3/PathSpec.java | 106 +++++++++++-------------- 1 file changed, 47 insertions(+), 59 deletions(-) (limited to 'src/org') diff --git a/src/org/noreply/fancydress/type3/PathSpec.java b/src/org/noreply/fancydress/type3/PathSpec.java index bf5f1b5..a0e5d47 100644 --- a/src/org/noreply/fancydress/type3/PathSpec.java +++ b/src/org/noreply/fancydress/type3/PathSpec.java @@ -97,6 +97,15 @@ public class PathSpec { return (type == TYPE_CROSSOVER); } + /** + * If this path component is a ByNickname component. + * + * @return true if this path component is a ByNickname component. + */ + public boolean isByNickname() { + return (type == TYPE_NICKNAME); + } + /** * Get a number of hops statisfyi8ng this path component. * @@ -202,20 +211,13 @@ public class PathSpec { /** * A class holding a list of Servers and a Crossover point location. */ - private class ServerWithCrossover { + private class ServerlistWithCrossover { public Server[] servers; public int crossoverPoint; - public Server getLastServer() { - return (servers[servers.length - 1]); - } - - public void setLastServer(Server s) { - servers[servers.length - 1] = s; - } - - public Server getSecondToLastServer() { - return (servers[servers.length - 2]); + public ServerlistWithCrossover(Server[] servers, int crossoverPoint) { + this.servers = servers; + this.crossoverPoint = crossoverPoint; } private void fillInRandoms() throws Mix3PathProblemException { @@ -267,9 +269,11 @@ public class PathSpec { /** * Concat path components, getting random amount of hops where requested. * - * @return a list of servers and a crossover point as an ServerWithCrossover object. + * @param chopOffRandomLast remove the last component if it is a RandomHop Component. // FIXME: understand what the spec says + * @param exitHop the exit hop to use. + * @return a list of servers and a crossover point as an ServerlistWithCrossover object. */ - private ServerWithCrossover concatComponents() throws Mix3PathProblemException { + private ServerlistWithCrossover concatComponents(boolean chopOffRandomLast, Server exitHop) throws Mix3PathProblemException { Server[][] components = new Server[pathComponents.length][]; int length = 0; int crossoverBefore = -1; @@ -292,9 +296,13 @@ public class PathSpec { if (c != length) throw new Error ("Did not fill in length hops ("+c+" vs "+length+")"); - ServerWithCrossover result = new ServerWithCrossover(); - result.servers = servers; - result.crossoverPoint = crossoverBefore; + if (chopOffRandomLast && servers[servers.length-1] == null) { + Server[] newServers = new Server[servers.length-1]; + System.arraycopy(servers, 0, newServers, 0, servers.length-1); + servers = newServers; + } + + ServerlistWithCrossover result = new ServerlistWithCrossover(servers, crossoverBefore); return result; } @@ -311,63 +319,43 @@ public class PathSpec { * * @param payload the payload * @return paths constructed from the PathSpec + * @throws IllegalArgumentException if this is a single leg path spec. */ public Path[] getPath(Payload payload) throws Mix3PathProblemException { if (singleLeg) throw new IllegalArgumentException("getPath() may not be called for single leg path specs."); - ServerWithCrossover[] paths = new ServerWithCrossover[payload.numPackets()]; - for (int i=0; i