jdk/src/share/classes/sun/security/provider/certpath/AdjacencyList.java
author xuelei
Tue, 18 Aug 2009 20:47:13 -0700
changeset 4190 227655c2ff8c
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6861062: Disable MD2 support Reviewed-by: mullan, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * An AdjacencyList is used to store the history of certification paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * attempted in constructing a path from an initiator to a target. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * AdjacencyList is initialized with a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>List</code>s, where each sub-<code>List</code> contains objects of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * type <code>Vertex</code>. A <code>Vertex</code> describes one possible or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * actual step in the chain building process, and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>Certificate</code>. Specifically, a <code>Vertex</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * contains a <code>Certificate</code> and an index value referencing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * next sub-list in the process. If the index value is -1 then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>Vertex</code> doesn't continue the attempted build path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Attempted Paths:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>C1-&gt;C2-&gt;C3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <li>C1-&gt;C4-&gt;C5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <li>C1-&gt;C4-&gt;C6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>C1-&gt;C4-&gt;C7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li>C1-&gt;C8-&gt;C9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>C1-&gt;C10-&gt;C11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * AdjacencyList structure:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <li>AL[0] = C1,1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <li>AL[1] = C2,2   =&gt;C4,3   =&gt;C8,4     =&gt;C10,5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <li>AL[2] = C3,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>AL[3] = C5,-1  =&gt;C6,-1  =&gt;C7,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <li>AL[4] = C9,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <li>AL[5] = C11,-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The iterator method returns objects of type <code>BuildStep</code>, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * objects of type <code>Vertex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * A <code>BuildStep</code> contains a <code>Vertex</code> and a result code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * accessable via getResult method. There are five result values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <code>POSSIBLE</code> denotes that the current step represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>Certificate</code> that the builder is considering at this point in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the build. <code>FOLLOW</code> denotes a <code>Certificate</code> (one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * those noted as <code>POSSIBLE</code>) that the builder is using to try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * extending the chain. <code>BACK</code> represents that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <code>FOLLOW</code> was incorrect, and is being removed from the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * There is exactly one <code>FOLLOW</code> for each <code>BACK</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * values <code>SUCCEED</code> and <code>FAIL</code> mean that we've come to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * the end of the build process, and there will not be any more entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see sun.security.provider.certpath.BuildStep
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see sun.security.provider.certpath.Vertex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author  seth proctor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class AdjacencyList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // the actual set of steps the AdjacencyList represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private ArrayList<BuildStep> mStepList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // the original list, just for the toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private List<List<Vertex>> mOrigList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Constructs a new <code>AdjacencyList</code> based on the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <code>List</code>. See the example above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param list a <code>List</code> of <code>List</code>s of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *             <code>Vertex</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public AdjacencyList(List<List<Vertex>> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        mStepList = new ArrayList<BuildStep>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        mOrigList = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        buildList(list, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Gets an <code>Iterator</code> to iterate over the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>BuildStep</code>s in build-order. Any attempts to change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * the list through the remove method will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return an <code>Iterator</code> over the <code>BuildStep</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public Iterator<BuildStep> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return Collections.unmodifiableList(mStepList).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Recursive, private method which actually builds the step list from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the given adjacency list. <code>Follow</code> is the parent BuildStep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * that we followed to get here, and if it's null, it means that we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * at the start.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private boolean buildList(List<List<Vertex>> theList, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        BuildStep follow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // Each time this method is called, we're examining a new list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // from the global list. So, we have to start by getting the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // that contains the set of Vertexes we're considering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        List<Vertex> l = theList.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // we're interested in the case where all indexes are -1...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            boolean allNegOne = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // ...and in the case where every entry has a Throwable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            boolean allXcps = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            for (Vertex v : l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (v.getIndex() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    // count an empty list the same as an index of -1...this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    // is to patch a bug somewhere in the builder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    if (theList.get(v.getIndex()).size() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                        allNegOne = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    if (v.getThrowable() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        allXcps = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                // every entry, regardless of the final use for it, is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                // entered as a possible step before we take any actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                mStepList.add(new BuildStep(v, BuildStep.POSSIBLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (allNegOne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // There are two cases that we could be looking at here. We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                // may need to back up, or the build may have succeeded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                // this point. This is based on whether or not any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                // exceptions were found in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (allXcps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    // we need to go back...see if this is the last one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    if (follow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        mStepList.add(new BuildStep(null, BuildStep.FAIL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        mStepList.add(new BuildStep(follow.getVertex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                                    BuildStep.BACK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    // we succeeded...now the only question is which is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    // successful step? If there's only one entry without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    // a throwable, then that's the successful step. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    // we'll have to make some guesses...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    List<Vertex> possibles = new ArrayList<Vertex>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    for (Vertex v : l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        if (v.getThrowable() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            possibles.add(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    if (possibles.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        // real easy...we've found the final Vertex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        mStepList.add(new BuildStep(possibles.get(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                    BuildStep.SUCCEED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        // ok...at this point, there is more than one Cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        // which might be the succeed step...how do we know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        // which it is? I'm going to assume that our builder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        // algorithm is good enough to know which is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        // correct one, and put it first...but a FIXME goes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        // here anyway, and we should be comparing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        // target/initiator Cert...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        mStepList.add(new BuildStep(possibles.get(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                                    BuildStep.SUCCEED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                // There's at least one thing that we can try before we give
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                // up and go back. Run through the list now, and enter a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                // BuildStep for each path that we try to follow. If none of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                // the paths we try produce a successful end, we're going to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                // have to back out ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                boolean success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                for (Vertex v : l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    // Note that we'll only find a SUCCEED case when we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    // looking at the last possible path, so we don't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    // consider success in the while loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    if (v.getIndex() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        if (theList.get(v.getIndex()).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            // If the entry we're looking at doesn't have an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                            // index of -1, and doesn't lead to an empty list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            // then it's something we follow!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                            BuildStep bs = new BuildStep(v, BuildStep.FOLLOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                            mStepList.add(bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                            success = buildList(theList, v.getIndex(), bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    // We're already finished!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    // We failed, and we've exhausted all the paths that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    // could take. The only choice is to back ourselves out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    if (follow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        mStepList.add(new BuildStep(null, BuildStep.FAIL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        mStepList.add(new BuildStep(follow.getVertex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                                    BuildStep.BACK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        catch (Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // we'll never get here, but you know java...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Prints out a string representation of this AdjacencyList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return String representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String out = "[\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        for (List<Vertex> l : mOrigList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            out = out + "LinkedList[" + i++ + "]:\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            for (Vertex step : l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    out = out + step.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    out = out + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                catch (Exception e) { out = out + "No Such Element\n"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        out = out + "]\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}