001    package com.thaiopensource.validate.nrl;
002    
003    class ElementsOrAttributes {
004      private static final int ELEMENTS_FLAG = 01;
005      private static final int ATTRIBUTES_FLAG = 02;
006    
007      static final ElementsOrAttributes NEITHER = new ElementsOrAttributes(0);
008      static final ElementsOrAttributes ELEMENTS = new ElementsOrAttributes(ELEMENTS_FLAG);
009      static final ElementsOrAttributes ATTRIBUTES = new ElementsOrAttributes(ATTRIBUTES_FLAG);
010      static final ElementsOrAttributes BOTH = new ElementsOrAttributes(ELEMENTS_FLAG|ATTRIBUTES_FLAG);
011    
012      private static final ElementsOrAttributes values[] = {
013        NEITHER,
014        ELEMENTS,
015        ATTRIBUTES,
016        BOTH
017      };
018    
019      private int flags = 0;
020    
021      private ElementsOrAttributes(int flags) {
022        this.flags = flags;
023      }
024    
025      ElementsOrAttributes addElements() {
026        return values[flags | ELEMENTS_FLAG];
027      }
028    
029      ElementsOrAttributes addAttributes() {
030        return values[flags | ATTRIBUTES_FLAG];
031      }
032    
033      boolean containsAttributes() {
034        return (flags & ATTRIBUTES_FLAG) != 0;
035      }
036    
037      boolean containsElements() {
038        return (flags & ELEMENTS_FLAG) != 0;
039      }
040    
041    }