File: MediaListImpl.java

package info (click to toggle)
flutejava 1.3-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,316 kB
  • ctags: 1,070
  • sloc: java: 8,251; makefile: 51
file content (78 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * (c) COPYRIGHT 1999 World Wide Web Consortium
 * (Massachusetts Institute of Technology, Institut National de Recherche
 *  en Informatique et en Automatique, Keio University).
 * All Rights Reserved. http://www.w3.org/Consortium/Legal/
 *
 * $Id: MediaListImpl.java,v 1.4 2000/04/26 13:40:19 plehegar Exp $
 */
package org.w3c.flute.parser;

import org.w3c.css.sac.SACMediaList;

/**
 * @version $Revision: 1.4 $
 * @author  Philippe Le Hegaret
 */
public class MediaListImpl implements SACMediaList {

    String[] array = new String[10];
    int current;

    public int getLength() {
	return current;
    }

    public String item(int index) {
	if ((index < 0) || (index >= current)) {
	    return null;
	}
	return array[index];
    }

    void addItem(String medium) {
	if (medium.equals("all")) {
	    array[0] = "all";
	    current = 1;
	    return;
	}
	for (int i = 0; i < current; i++) {
	    if (medium.equals(array[i])) {
		return;
	    }
	}
	if (current == array.length) {
	    String[] old = array;
	    array = new String[current + current];
	    System.arraycopy(old, 0, array, 0, current);
	}
	array[current++] = medium;
    }

    /**
     * Returns a string representation of this object.
     */
    public String toString() {
	int _i;

	switch (current) {
	case 0:
	    return "";
	case 1:
	    return array[0];
	default:
	    boolean not_done = true;
	    int i            = 0;
	    StringBuffer buf = new StringBuffer(50);
	    do {
		buf.append(array[i++]);
		if (i == current) {
		    not_done = false;
		} else {
		    buf.append(", ");
		}
	    } while (not_done);
	    return buf.toString();
	}
    }    
}