View Javadoc
1   package org.codehaus.plexus.util.dag;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  public class CycleDetectedException extends Exception {
23      private List<String> cycle;
24  
25      public CycleDetectedException(final String message, final List<String> cycle) {
26          super(message);
27  
28          this.cycle = cycle;
29      }
30  
31      public List<String> getCycle() {
32          return cycle;
33      }
34  
35      public String cycleToString() {
36          final StringBuilder buffer = new StringBuilder();
37  
38          for (Iterator<String> iterator = cycle.iterator(); iterator.hasNext(); ) {
39              buffer.append(iterator.next());
40  
41              if (iterator.hasNext()) {
42                  buffer.append(" --> ");
43              }
44          }
45          return buffer.toString();
46      }
47  
48      @Override
49      public String getMessage() {
50          return super.getMessage() + " " + cycleToString();
51      }
52  }