01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: 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: public OneOrMore() {
19: }
20:
21: public void update() {
22: super .update();
23:
24: PatternSet firstSet = getFirstSet();
25: for (PatternIterator i = getLastSet().getPattern(); i.hasNext();) {
26: Pattern lastPattern = i.next();
27: for (PatternIterator j = firstSet.getPattern(); j.hasNext();) {
28: Pattern firstPattern = j.next();
29: lastPattern.addSuccessor(firstPattern);
30: }
31: }
32: }
33:
34: /**
35: * Return a string representation of this pattern
36: *
37: * @return String representation of the pattern.
38: */
39: public String toString() {
40: StringBuffer buffer = new StringBuffer();
41:
42: if (getPatternCount() > 0) {
43: buffer.append(super .toString());
44: buffer.append("+");
45: }
46:
47: return buffer.toString();
48: }
49:
50: public String toString(PatternSet previous, PatternSet next) {
51: StringBuffer buffer = new StringBuffer();
52:
53: if (getPatternCount() > 0) {
54: buffer.append(super .toString(previous, next));
55: buffer.append("+");
56: }
57:
58: return buffer.toString();
59: }
60:
61: /**
62: * Create a clone this pattern.
63: *
64: * @return Clone of this pattern.
65: *
66: * @throws CloneNotSupportedException If an exception occurs during the cloning.
67: */
68: public Object clone() throws CloneNotSupportedException {
69: OneOrMore clone = new OneOrMore();
70:
71: for (int i = 0; i < getPatternCount(); i++)
72: clone.addPattern((Pattern) getPattern(i).clone());
73:
74: return clone;
75: }
76:
77: /**
78: * Validates this pattern.
79: *
80: * @return Return a list of violations, if this pattern isn't valid.
81: */
82: public Violations validate() {
83: Violations violations = new Violations();
84:
85: /*if (pattern==null)
86: violations.addViolation("Multiplier contains no pattern",
87: getLocation());*/
88: for (int i = 0; i < getPatternCount(); i++)
89: violations.addViolations(getPattern(i).validate());
90:
91: return violations;
92: }
93: }
|