/libformula-1.1.3/source/org/pentaho/reporting/libraries/formula/typing/DefaultType.java

# · Java · 94 lines · 61 code · 10 blank · 23 comment · 10 complexity · 7049699f896f0dfbea41a8c261761b09 MD5 · raw file

  1. /*
  2. * This program is free software; you can redistribute it and/or modify it under the
  3. * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
  4. * Foundation.
  5. *
  6. * You should have received a copy of the GNU Lesser General Public License along with this
  7. * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
  8. * or from the Free Software Foundation, Inc.,
  9. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU Lesser General Public License for more details.
  14. *
  15. * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved.
  16. */
  17. package org.pentaho.reporting.libraries.formula.typing;
  18. import java.util.HashMap;
  19. import java.util.HashSet;
  20. /**
  21. * Creation-Date: 02.11.2006, 09:37:54
  22. *
  23. * @author Thomas Morgner
  24. */
  25. public abstract class DefaultType implements Type
  26. {
  27. private HashSet flags;
  28. private HashMap properties;
  29. private boolean locked;
  30. private static final long serialVersionUID = -8206983276033867416L;
  31. protected DefaultType()
  32. {
  33. }
  34. public boolean isLocked()
  35. {
  36. return locked;
  37. }
  38. public void lock()
  39. {
  40. this.locked = true;
  41. }
  42. public void addFlag(final String name)
  43. {
  44. if (locked)
  45. {
  46. throw new IllegalStateException();
  47. }
  48. if (flags == null)
  49. {
  50. flags = new HashSet();
  51. }
  52. flags.add(name);
  53. }
  54. public boolean isFlagSet(final String name)
  55. {
  56. if (flags == null)
  57. {
  58. return false;
  59. }
  60. return flags.contains(name);
  61. }
  62. public void setProperty(final String name, final Object value)
  63. {
  64. if (locked)
  65. {
  66. throw new IllegalStateException();
  67. }
  68. if (properties == null)
  69. {
  70. properties = new HashMap();
  71. }
  72. properties.put(name, value);
  73. }
  74. public Object getProperty(final String name)
  75. {
  76. // The type system has no properties yet. This is done later, when we
  77. // deal with real meta-data
  78. if (properties == null)
  79. {
  80. return null;
  81. }
  82. return properties.get(name);
  83. }
  84. }