KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > extended > OneOrMore


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.model.extended;
10
11 import net.sourceforge.chaperon.model.Violations;
12
13 /**
14  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
15  * @version CVS $Id: OneOrMore.java,v 1.5 2004/01/07 08:28:49 benedikta Exp $
16  */

17 public class OneOrMore extends PatternList
18 {
19   public OneOrMore() {}
20
21   public void update()
22   {
23     super.update();
24
25     PatternSet firstSet = getFirstSet();
26     for (PatternIterator i = getLastSet().getPattern(); i.hasNext();)
27     {
28       Pattern lastPattern = i.next();
29       for (PatternIterator j = firstSet.getPattern(); j.hasNext();)
30       {
31         Pattern firstPattern = j.next();
32         lastPattern.addSuccessor(firstPattern);
33       }
34     }
35   }
36
37   /**
38    * Return a string representation of this pattern
39    *
40    * @return String representation of the pattern.
41    */

42   public String JavaDoc toString()
43   {
44     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
45
46     if (getPatternCount()>0)
47     {
48       buffer.append(super.toString());
49       buffer.append("+");
50     }
51
52     return buffer.toString();
53   }
54
55   public String JavaDoc toString(PatternSet previous, PatternSet next)
56   {
57     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
58
59     if (getPatternCount()>0)
60     {
61       buffer.append(super.toString(previous, next));
62       buffer.append("+");
63     }
64
65     return buffer.toString();
66   }
67
68   /**
69    * Create a clone this pattern.
70    *
71    * @return Clone of this pattern.
72    *
73    * @throws CloneNotSupportedException If an exception occurs during the cloning.
74    */

75   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc
76   {
77     OneOrMore clone = new OneOrMore();
78
79     for (int i = 0; i<getPatternCount(); i++)
80       clone.addPattern((Pattern)getPattern(i).clone());
81
82     return clone;
83   }
84
85   /**
86    * Validates this pattern.
87    *
88    * @return Return a list of violations, if this pattern isn't valid.
89    */

90   public Violations validate()
91   {
92     Violations violations = new Violations();
93
94     /*if (pattern==null)
95       violations.addViolation("Multiplier contains no pattern",
96                               getLocation());*/

97     for (int i = 0; i<getPatternCount(); i++)
98       violations.addViolations(getPattern(i).validate());
99
100     return violations;
101   }
102 }
103
Popular Tags