KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > w3c > flute > parser > MediaListImpl


1 /*
2  * (c) COPYRIGHT 1999 World Wide Web Consortium
3  * (Massachusetts Institute of Technology, Institut National de Recherche
4  * en Informatique et en Automatique, Keio University).
5  * All Rights Reserved. http://www.w3.org/Consortium/Legal/
6  *
7  * $Id: MediaListImpl.java,v 1.1.1.1 2006/04/23 14:51:51 taqua Exp $
8  */

9 package org.w3c.flute.parser;
10
11 import org.w3c.css.sac.SACMediaList;
12
13 /**
14  * @version $Revision: 1.1.1.1 $
15  * @author Philippe Le Hegaret
16  */

17 public class MediaListImpl implements SACMediaList {
18
19     String JavaDoc[] array = new String JavaDoc[10];
20     int current;
21
22     public int getLength() {
23     return current;
24     }
25
26     public String JavaDoc item(int index) {
27     if ((index < 0) || (index >= current)) {
28         return null;
29     }
30     return array[index];
31     }
32
33     void addItem(String JavaDoc medium) {
34     if (medium.equals("all")) {
35         array[0] = "all";
36         current = 1;
37         return;
38     }
39     for (int i = 0; i < current; i++) {
40         if (medium.equals(array[i])) {
41         return;
42         }
43     }
44     if (current == array.length) {
45         String JavaDoc[] old = array;
46         array = new String JavaDoc[current + current];
47         System.arraycopy(old, 0, array, 0, current);
48     }
49     array[current++] = medium;
50     }
51
52     /**
53      * Returns a string representation of this object.
54      */

55     public String JavaDoc toString() {
56     int _i;
57
58     switch (current) {
59     case 0:
60         return "";
61     case 1:
62         return array[0];
63     default:
64         boolean not_done = true;
65         int i = 0;
66         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(50);
67         do {
68         buf.append(array[i++]);
69         if (i == current) {
70             not_done = false;
71         } else {
72             buf.append(", ");
73         }
74         } while (not_done);
75         return buf.toString();
76     }
77     }
78 }
79
Popular Tags