001 /* 002 * (c) COPYRIGHT 1999 World Wide Web Consortium 003 * (Massachusetts Institute of Technology, Institut National de Recherche 004 * en Informatique et en Automatique, Keio University). 005 * All Rights Reserved. http://www.w3.org/Consortium/Legal/ 006 * 007 * $Id: MediaListImpl.java,v 1.1.1.1 2006/04/23 14:51:51 taqua Exp $ 008 */ 009 package org.w3c.flute.parser; 010 011 import org.w3c.css.sac.SACMediaList; 012 013 /** 014 * @version $Revision: 1.1.1.1 $ 015 * @author Philippe Le Hegaret 016 */ 017 public class MediaListImpl implements SACMediaList { 018 019 String[] array = new String[10]; 020 int current; 021 022 public int getLength() { 023 return current; 024 } 025 026 public String item(int index) { 027 if ((index < 0) || (index >= current)) { 028 return null; 029 } 030 return array[index]; 031 } 032 033 void addItem(String medium) { 034 if (medium.equals("all")) { 035 array[0] = "all"; 036 current = 1; 037 return; 038 } 039 for (int i = 0; i < current; i++) { 040 if (medium.equals(array[i])) { 041 return; 042 } 043 } 044 if (current == array.length) { 045 String[] old = array; 046 array = new String[current + current]; 047 System.arraycopy(old, 0, array, 0, current); 048 } 049 array[current++] = medium; 050 } 051 052 /** 053 * Returns a string representation of this object. 054 */ 055 public String toString() { 056 int _i; 057 058 switch (current) { 059 case 0: 060 return ""; 061 case 1: 062 return array[0]; 063 default: 064 boolean not_done = true; 065 int i = 0; 066 StringBuffer buf = new StringBuffer(50); 067 do { 068 buf.append(array[i++]); 069 if (i == current) { 070 not_done = false; 071 } else { 072 buf.append(", "); 073 } 074 } while (not_done); 075 return buf.toString(); 076 } 077 } 078 }