You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MediaListImpl.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.4 2000/04/26 13:40:19 plehegar Exp $
  8. */
  9. package com.vaadin.sass.parser;
  10. import org.w3c.css.sac.SACMediaList;
  11. /**
  12. * @version $Revision: 1.4 $
  13. * @author Philippe Le Hegaret
  14. */
  15. public class MediaListImpl implements SACMediaList {
  16. String[] array = new String[10];
  17. int current;
  18. @Override
  19. public int getLength() {
  20. return current;
  21. }
  22. @Override
  23. public String item(int index) {
  24. if ((index < 0) || (index >= current)) {
  25. return null;
  26. }
  27. return array[index];
  28. }
  29. void addItem(String medium) {
  30. if (medium.equals("all")) {
  31. array[0] = "all";
  32. current = 1;
  33. return;
  34. }
  35. for (int i = 0; i < current; i++) {
  36. if (medium.equals(array[i])) {
  37. return;
  38. }
  39. }
  40. if (current == array.length) {
  41. String[] old = array;
  42. array = new String[current + current];
  43. System.arraycopy(old, 0, array, 0, current);
  44. }
  45. array[current++] = medium;
  46. }
  47. /**
  48. * Returns a string representation of this object.
  49. */
  50. @Override
  51. public String toString() {
  52. switch (current) {
  53. case 0:
  54. return "";
  55. case 1:
  56. return array[0];
  57. default:
  58. boolean not_done = true;
  59. int i = 0;
  60. StringBuffer buf = new StringBuffer(50);
  61. do {
  62. buf.append(array[i++]);
  63. if (i == current) {
  64. not_done = false;
  65. } else {
  66. buf.append(", ");
  67. }
  68. } while (not_done);
  69. return buf.toString();
  70. }
  71. }
  72. }