KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > pattern > CharacterSet


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.pattern;
10
11 import net.sourceforge.chaperon.common.Decoder;
12 import net.sourceforge.chaperon.model.Violations;
13
14 /**
15  * This represents a set of characters within a character class.
16  *
17  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
18  * @version CVS $Id: CharacterSet.java,v 1.6 2003/12/09 19:55:52 benedikta Exp $
19  */

20 public class CharacterSet implements CharacterClassElement
21 {
22   private String JavaDoc set = "";
23   private String JavaDoc location = null;
24
25   /**
26    * Creates set of characters.
27    */

28   public CharacterSet() {}
29
30   /**
31    * Set the set of characters.
32    *
33    * @param set Set of characters.
34    */

35   public void setCharacters(String JavaDoc set)
36   {
37     this.set = set;
38   }
39
40   /**
41    * Returns the to comparing characters
42    *
43    * @return To comparing characters
44    */

45   public String JavaDoc getCharacters()
46   {
47     return set;
48   }
49
50   /**
51    * Set the location from the input source.
52    *
53    * @param location Location in the input source.
54    */

55   public void setLocation(String JavaDoc location)
56   {
57     this.location = location;
58   }
59
60   /**
61    * Returns the location from the input source.
62    *
63    * @return Location in the input source.
64    */

65   public String JavaDoc getLocation()
66   {
67     return location;
68   }
69
70   /**
71    * Return a string representation of this pattern
72    *
73    * @return String representation of the pattern.
74    */

75   public String JavaDoc toString()
76   {
77     return Decoder.decode(set, Decoder.CLASS);
78   }
79
80   /**
81    * Create a clone of this pattern.
82    *
83    * @return Clone of this pattern.
84    *
85    * @throws CloneNotSupportedException If an exception occurs during the cloning.
86    */

87   public Object JavaDoc clone()
88   {
89     CharacterSet clone = new CharacterSet();
90
91     clone.setCharacters(getCharacters());
92
93     return clone;
94   }
95
96   /**
97    * Validates this pattern.
98    *
99    * @return Return a list of violations, if this pattern isn't valid.
100    */

101   public Violations validate()
102   {
103     Violations violations = new Violations();
104
105     if ((set==null) || (set.length()==0))
106       violations.addViolation("Character set contains no characters", getLocation());
107
108     return violations;
109   }
110 }
111
Popular Tags