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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. /*
  17. * (c) COPYRIGHT 1999 World Wide Web Consortium
  18. * (Massachusetts Institute of Technology, Institut National de Recherche
  19. * en Informatique et en Automatique, Keio University).
  20. * All Rights Reserved. http://www.w3.org/Consortium/Legal/
  21. *
  22. * $Id: MediaListImpl.java,v 1.4 2000/04/26 13:40:19 plehegar Exp $
  23. */
  24. package com.vaadin.sass.internal.parser;
  25. import java.io.Serializable;
  26. import org.w3c.css.sac.SACMediaList;
  27. /**
  28. * @version $Revision: 1.4 $
  29. * @author Philippe Le Hegaret
  30. */
  31. public class MediaListImpl implements SACMediaList, Serializable {
  32. /**
  33. *
  34. */
  35. private static final long serialVersionUID = 1L;
  36. String[] array = new String[10];
  37. int current;
  38. @Override
  39. public int getLength() {
  40. return current;
  41. }
  42. @Override
  43. public String item(int index) {
  44. if ((index < 0) || (index >= current)) {
  45. return null;
  46. }
  47. return array[index];
  48. }
  49. void addItem(String medium) {
  50. if (medium.equals("all")) {
  51. array[0] = "all";
  52. current = 1;
  53. return;
  54. }
  55. for (int i = 0; i < current; i++) {
  56. if (medium.equals(array[i])) {
  57. return;
  58. }
  59. }
  60. if (current == array.length) {
  61. String[] old = array;
  62. array = new String[current + current];
  63. System.arraycopy(old, 0, array, 0, current);
  64. }
  65. array[current++] = medium;
  66. }
  67. /**
  68. * Returns a string representation of this object.
  69. */
  70. @Override
  71. public String toString() {
  72. switch (current) {
  73. case 0:
  74. return "";
  75. case 1:
  76. return array[0];
  77. default:
  78. boolean not_done = true;
  79. int i = 0;
  80. StringBuffer buf = new StringBuffer(50);
  81. do {
  82. buf.append(array[i++]);
  83. if (i == current) {
  84. not_done = false;
  85. } else {
  86. buf.append(", ");
  87. }
  88. } while (not_done);
  89. return buf.toString();
  90. }
  91. }
  92. }