KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > util > ConditionnalString


1 /*
2  * Copyright (C) 2001 SCALAGENT
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  */

20 package fr.dyade.aaa.util;
21
22 import java.util.*;
23
24 public class ConditionnalString implements java.io.Serializable JavaDoc {
25
26
27   public static ConditionnalString valueOf(String JavaDoc s) throws Exception JavaDoc {
28     StringTokenizer tokenizer = new StringTokenizer(s, "(),");
29     int tokenNb = tokenizer.countTokens();
30     String JavaDoc value = "";
31     if (tokenNb == 2) {
32       value = tokenizer.nextToken();
33     }
34     String JavaDoc c = tokenizer.nextToken();
35     boolean condition = Boolean.valueOf(c).booleanValue();
36     ConditionnalString cs = new ConditionnalString(value, condition);
37     return cs;
38   }
39
40   public String JavaDoc value = null;
41   public boolean condition = false;
42
43   public ConditionnalString(String JavaDoc value, boolean condition) {
44     this.value = value;
45     this.condition = condition;
46   }
47
48   public String JavaDoc toString() {
49     return '(' + value + ',' + condition + ')';
50   }
51 }
52
Popular Tags