public boolean updateNewsStates(Collection<StatesUpdateInfo> statesUpdateInfos) {
   boolean changed = false;
   for (StatesUpdateInfo info : statesUpdateInfos) {
     long newsId = info.getNewsReference().getId();
     if (info.getOldState() == null) {
       boolean itemRemoved = fNewsIds[INews.State.NEW.ordinal()].removeByElement(newsId);
       if (!itemRemoved) {
         EnumSet<State> remainingStates = EnumSet.allOf(INews.State.class);
         remainingStates.remove(INews.State.NEW);
         remainingStates.remove(info.getNewState());
         for (INews.State state : remainingStates) {
           if (fNewsIds[state.ordinal()].removeByElement(newsId)) itemRemoved = true;
         }
       }
       if (itemRemoved) {
         changed = true;
         fNewsIds[info.getNewState().ordinal()].add(newsId);
       }
     } else if (fNewsIds[info.getOldState().ordinal()].removeByElement(newsId)) {
       changed = true;
       fNewsIds[info.getNewState().ordinal()].add(newsId);
     }
   }
   return changed;
 }
Esempio n. 2
0
 public static void updateGUITicks(BaseModProxy mod, boolean enable, boolean useClock) {
   ModLoaderModContainer mlmc =
       (ModLoaderModContainer) Loader.instance().getReversedModObjectList().get(mod);
   if (mlmc == null) {
     mlmc = (ModLoaderModContainer) Loader.instance().activeModContainer();
   }
   if (mlmc == null) {
     FMLLog.severe("Attempted to register ModLoader ticking for invalid BaseMod %s", mod);
     return;
   }
   EnumSet<TickType> ticks = mlmc.getGUITickHandler().ticks();
   // If we're enabled and we don't want clock ticks we get render ticks
   if (enable && !useClock) {
     ticks.add(TickType.RENDER);
   } else {
     ticks.remove(TickType.RENDER);
   }
   // If we're enabled but we want clock ticks, or we're server side we get world ticks
   if (enable && useClock) {
     ticks.add(TickType.CLIENT);
     ticks.add(TickType.WORLDLOAD);
   } else {
     ticks.remove(TickType.CLIENT);
     ticks.remove(TickType.WORLDLOAD);
   }
 }
Esempio n. 3
0
 private void postViewSwitched(int direction) {
   if (direction != 0) {
     if (direction > 0) {
       mCurrentAdapterIndex++;
       mCurrentBufferIndex++;
       mLazyInit.remove(LazyInit.LEFT);
       mLazyInit.add(LazyInit.RIGHT);
       if (mCurrentAdapterIndex > mBufferedItemCount) {
         recycleView(mLoadedViews.removeFirst());
         mCurrentBufferIndex--;
       }
       int newBufferIndex = mCurrentAdapterIndex + mBufferedItemCount;
       if (newBufferIndex < mAdapter.getCount())
         mLoadedViews.addLast(makeAndAddView(newBufferIndex, true));
     } else {
       mCurrentAdapterIndex--;
       mCurrentBufferIndex--;
       mLazyInit.add(LazyInit.LEFT);
       mLazyInit.remove(LazyInit.RIGHT);
       if (mAdapter.getCount() - 1 - mCurrentAdapterIndex > mBufferedItemCount) {
         recycleView(mLoadedViews.removeLast());
       }
       int newBufferIndex = mCurrentAdapterIndex - mBufferedItemCount;
       if (newBufferIndex > -1) {
         mLoadedViews.addFirst(makeAndAddView(newBufferIndex, false));
         mCurrentBufferIndex++;
       }
     }
     requestLayout();
     setVisibleView(mCurrentBufferIndex, true);
     if (viewSwitchListener != null) {
       viewSwitchListener.onSwitched(mLoadedViews.get(mCurrentBufferIndex), mCurrentAdapterIndex);
     }
   }
 }
 @SuppressWarnings("fallthrough")
 public RichConfiguration(Options options, AbstractDiagnosticFormatter formatter) {
   super(formatter.getConfiguration());
   features =
       formatter.isRaw()
           ? EnumSet.noneOf(RichFormatterFeature.class)
           : EnumSet.of(
               RichFormatterFeature.SIMPLE_NAMES,
               RichFormatterFeature.WHERE_CLAUSES,
               RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
   String diagOpts = options.get("diags");
   if (diagOpts != null) {
     for (String args : diagOpts.split(",")) {
       if (args.equals("-where")) {
         features.remove(RichFormatterFeature.WHERE_CLAUSES);
       } else if (args.equals("where")) {
         features.add(RichFormatterFeature.WHERE_CLAUSES);
       }
       if (args.equals("-simpleNames")) {
         features.remove(RichFormatterFeature.SIMPLE_NAMES);
       } else if (args.equals("simpleNames")) {
         features.add(RichFormatterFeature.SIMPLE_NAMES);
       }
       if (args.equals("-disambiguateTvars")) {
         features.remove(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
       } else if (args.equals("disambiguateTvars")) {
         features.add(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
       }
     }
   }
 }
Esempio n. 5
0
  /** Gets a set of all selected content types. */
  public EnumSet<ContentType> getContentType() {
    EnumSet<ContentType> result = EnumSet.allOf(ContentType.class);

    if (!getContentTypeNsfl()) result.remove(ContentType.NSFL);

    if (!getContentTypeNsfw()) result.remove(ContentType.NSFW);

    // leave at least sfw.
    if (result.size() > 1 && !getContentTypeSfw()) result.remove(ContentType.SFW);

    return result;
  }
 /**
  * Method to get a trimmed list of Certificate Types, removing any that have already been saved.
  *
  * @return the remaining certificate types.
  */
 public EnumSet<LaboratoryCertificateType> getCertificateTypes() {
   EnumSet<LaboratoryCertificateType> certificateTypes =
       EnumSet.allOf(LaboratoryCertificateType.class);
   for (LaboratoryCertificateType type : getLab().getCertificates().keySet()) {
     certificateTypes.remove(type);
     // A Lab can have a CLIA or a CLP, but not both.
     if (type == LaboratoryCertificateType.CLIA || type == LaboratoryCertificateType.CLP) {
       certificateTypes.remove(LaboratoryCertificateType.CLIA);
       certificateTypes.remove(LaboratoryCertificateType.CLP);
     }
   }
   return certificateTypes;
 }
Esempio n. 7
0
  private void addHandlers() {
    HeaderHandler headerHandler = new HeaderHandler();
    saxReader.addHandler("/swfdocument/header", headerHandler);
    saxReader.addHandler("/swfdocument/unknowntag", new UnknownTagHandler());

    EnumSet<TagType> tagTypes = EnumSet.allOf(TagType.class);
    tagTypes.remove(TagType.UNKNOWN_TAG);
    tagTypes.remove(TagType.END);
    tagTypes.remove(TagType.FILE_ATTRIBUTES);
    tagTypes.remove(TagType.SET_BACKGROUND_COLOR);
    for (TagType t : tagTypes) {
      saxReader.addHandler("/swfdocument/".concat(t.toString()), new TagHandler(t));
    }
  }
Esempio n. 8
0
 public void removeFilter(CardEnum e) {
   if (e instanceof ColorFlag) {
     colors.remove((ColorFlag) e);
   } else if (e instanceof Attribute) {
     attributes.remove((Attribute) e);
   } else if (e instanceof CardType) {
     if (e == CardType.TROOP && !isActive(CardType.CONSTANT)
         || e == CardType.CONSTANT && !isActive(CardType.TROOP)) {
       cardTypes.remove(CardType.ARTIFACT);
     }
     cardTypes.remove((CardType) e);
   } else {
     throw new RuntimeException("Unknown enum type");
   }
 }
Esempio n. 9
0
  public ActMood mostSpecificGeneralization(CD that) {
    if (this == that || this.equals(that)) return this;
    if (!(that instanceof ActMood))
      throw new UnsupportedOperationException("cannot handle argument of class " + that.getClass());
    final ActMood thatActMood = (ActMood) that;

    // First build the intersection of the implied concepts
    // the remainder is a single path of which we have to
    // find the most specific concept, i.e., the one who
    // has all others as parents, i.e., the one with the
    // largest set of implied concepts.
    EnumSet<ActMood> intersection = EnumSet.copyOf(getImpliedConcepts());
    intersection.removeAll(EnumSet.complementOf(thatActMood.getImpliedConcepts()));
    intersection.remove(root);

    // XXX: this iterative search is likely to be least optimal because
    // we probably have to search the path from the root here.
    // I don't know of any better way to do it right now though.

    ActMood mostSpecificKnownGeneralization = root;
    int maxKnownSpecificity = 1;

    for (ActMood candidate : intersection) {
      int specificity = candidate.getImpliedConcepts().size();
      if (specificity > maxKnownSpecificity) {
        maxKnownSpecificity = specificity;
        mostSpecificKnownGeneralization = candidate;
      }
    }

    return mostSpecificKnownGeneralization;
  }
  private EnumSet<ExecutableType> commonExecutableTypeChecks(
      ValidateOnExecution validateOnExecutionAnnotation) {
    if (validateOnExecutionAnnotation == null) {
      return EnumSet.noneOf(ExecutableType.class);
    }

    EnumSet<ExecutableType> executableTypes = EnumSet.noneOf(ExecutableType.class);
    if (validateOnExecutionAnnotation.type().length == 0) { // HV-757
      executableTypes.add(ExecutableType.NONE);
    } else {
      Collections.addAll(executableTypes, validateOnExecutionAnnotation.type());
    }

    // IMPLICIT cannot be mixed 10.1.2 of spec - Mixing IMPLICIT and other executable types is
    // illegal
    if (executableTypes.contains(ExecutableType.IMPLICIT) && executableTypes.size() > 1) {
      throw log.getMixingImplicitWithOtherExecutableTypesException();
    }

    // NONE can be removed 10.1.2 of spec - A list containing NONE and other types of executables is
    // equivalent to a
    // list containing the types of executables without NONE.
    if (executableTypes.contains(ExecutableType.NONE) && executableTypes.size() > 1) {
      executableTypes.remove(ExecutableType.NONE);
    }

    // 10.1.2 of spec - A list containing ALL and other types of executables is equivalent to a list
    // containing only ALL
    if (executableTypes.contains(ExecutableType.ALL)) {
      executableTypes = ALL_EXECUTABLE_TYPES;
    }

    return executableTypes;
  }
Esempio n. 11
0
  @Test
  public void test() {
    EnumSet<ParserFlags> myFlags = EnumSet.noneOf(ParserFlags.class);

    Command addCommand = new AddCommand();
    myFlags.add(ParserFlags.COMMAND_FLAG);
    myFlags.add(ParserFlags.DESCRIPTION_FLAG);

    assertTrue(addCommand.validate(myFlags));

    myFlags.remove(ParserFlags.COMMAND_FLAG);

    assertFalse(addCommand.validate(myFlags));

    myFlags = EnumSet.noneOf(ParserFlags.class);
    assertFalse(addCommand.validate(myFlags));

    myFlags.add(ParserFlags.DATE_FLAG);
    assertFalse(addCommand.validate(myFlags));

    myFlags.add(ParserFlags.PRIORITY_FLAG);
    assertFalse(addCommand.validate(myFlags));

    myFlags.add(ParserFlags.DESCRIPTION_FLAG);
    assertFalse(addCommand.validate(myFlags));

    myFlags.add(ParserFlags.COMMAND_FLAG);
    assertTrue(addCommand.validate(myFlags));
  }
Esempio n. 12
0
  /**
   * Both {@link VmRngDevice.Source.URANDOM} and {@link VmRngDevice.Source.RANDOM} are encoded using
   * {@link VmRngDevice.Source.URANDOM} for non-cluster entities.
   */
  private static RngValidationResult validateForNonClusterEntity(VmRngDevice.Source source) {
    final EnumSet<VmRngDevice.Source> allowedSources = EnumSet.allOf(VmRngDevice.Source.class);
    allowedSources.remove(VmRngDevice.Source.RANDOM);

    return allowedSources.contains(source)
        ? RngValidationResult.VALID
        : RngValidationResult.INVALID;
  }
 private void setFlag(Flag flag, boolean set) {
   if (set && !flagsEnum.contains(flag)) {
     flagsEnum.add(flag);
   } else if (!set) {
     flagsEnum.remove(flag);
     assert (!flagsEnum.contains(flag));
   }
 }
Esempio n. 14
0
 public Filter() {
   minCost = 0;
   maxCost = MasterDeck.getHighestCardCost();
   attributes = EnumSet.noneOf(Attribute.class);
   colors = EnumSet.allOf(ColorFlag.class);
   cardTypes = EnumSet.allOf(CardType.class);
   cardTypes.remove(CardType.CHAMPION);
   cardSets = EnumSet.allOf(CardSet.class);
 }
Esempio n. 15
0
  @Override
  public void setModeEnabled(TerminalMode mode, boolean enabled) {
    if (enabled) {
      myModes.add(mode);
    } else {
      myModes.remove(mode);
    }

    mode.setEnabled(this, enabled);
  }
Esempio n. 16
0
 public static void updateStandardTicks(BaseMod mod, boolean enable, boolean useClock) {
   ModLoaderModContainer mlmc = findOrBuildModContainer(mod);
   BaseModTicker ticker = mlmc.getGameTickHandler();
   EnumSet<TickType> ticks = ticker.ticks();
   // If we're enabled we get render ticks
   if (enable && !useClock) {
     ticks.add(TickType.RENDER);
   } else {
     ticks.remove(TickType.RENDER);
   }
   // If we're enabled but we want clock ticks, or we're server side we get game ticks
   if (enable && (useClock || FMLCommonHandler.instance().getSide().isServer())) {
     ticks.add(TickType.GAME);
     ticks.add(TickType.WORLDLOAD);
   } else {
     ticks.remove(TickType.GAME);
     ticks.remove(TickType.WORLDLOAD);
   }
 }
Esempio n. 17
0
 /**
  * Find the best transformer for the given value.
  *
  * @param candidate The candidate value.
  * @return The best transformer for the given value. Not null.
  */
 private static Transformer get(final Object candidate) {
   EnumSet<Transformer> transoformers = EnumSet.allOf(Transformer.class);
   transoformers.remove(NONE);
   for (Transformer transformer : transoformers) {
     if (transformer.apply(candidate)) {
       return transformer;
     }
   }
   return NONE;
 }
 /**
  * Get the default selections for the dialog.
  *
  * @return EnumSet containing dialog options to be selected.
  */
 protected EnumSet<DialogOption> getDefaultDialogOptionsSelections() {
   EnumSet<DialogOption> defaultOptions =
       EnumSet.of(
           DialogOption.CLEAR_CACHE,
           DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
           DialogOption.CLEAR_HISTORY);
   if (!mCanDeleteBrowsingHistory) {
     defaultOptions.remove(DialogOption.CLEAR_HISTORY);
   }
   return defaultOptions;
 }
 @EventHandler
 void onMarkerHighlight(MarkerHighlightEvent event) {
   Log.trace("onMarkerHighlight " + event);
   switch (event.getAction()) {
     case ADD:
       highlightedMarkers.add(event.getMarkerType());
       break;
     case REMOVE:
       highlightedMarkers.remove(event.getMarkerType());
       break;
   }
 }
Esempio n. 20
0
 public static void updateGUITicks(BaseMod mod, boolean enable, boolean useClock) {
   ModLoaderModContainer mlmc = findOrBuildModContainer(mod);
   EnumSet<TickType> ticks = mlmc.getGUITickHandler().ticks();
   // If we're enabled and we don't want clock ticks we get render ticks
   if (enable && !useClock) {
     ticks.add(TickType.RENDER);
     ticks.add(TickType.GUILOAD);
   } else {
     ticks.remove(TickType.RENDER);
   }
   // If we're enabled but we want clock ticks, or we're server side we get world ticks
   if (enable && useClock) {
     ticks.add(TickType.GAME);
     ticks.add(TickType.GUILOAD);
     ticks.add(TickType.WORLDLOAD);
   } else {
     ticks.remove(TickType.GAME);
     ticks.remove(TickType.GUILOAD);
     ticks.remove(TickType.WORLDLOAD);
   }
 }
Esempio n. 21
0
  public void moveRight() {
    if (body.getLinearVelocity().x < OBJECT_MAX_VELOCITY * OBJECT_VELO_AMPLIFIER) {
      body.applyForceToCenter(OBJECT_MOVEMENT_FORCE * OBJECT_MOVE_AMPLIFIER, 0, true);

      // if object facing the wrong way, correct it
      if (currentStates.contains(IntelliObjectState.FACING_LEFT)) {
        currentStates.remove(IntelliObjectState.FACING_LEFT);
        currentStates.add(IntelliObjectState.FACING_RIGHT);
        sprite = getSprite();
        sprite.flip(true, false);
      }
    }
  }
Esempio n. 22
0
 /**
  * Creates a copy of a Flag Set removing instances of FAIL_SILENTLY. The copy might be the same
  * instance if no change is required, and should be considered immutable.
  *
  * @param flags
  * @return might return the same instance
  */
 public static Set<Flag> copyWithoutRemotableFlags(Set<Flag> flags) {
   // FAIL_SILENTLY should not be sent to remote nodes
   if (flags != null && flags.contains(Flag.FAIL_SILENTLY)) {
     EnumSet<Flag> copy = EnumSet.copyOf(flags);
     copy.remove(Flag.FAIL_SILENTLY);
     if (copy.isEmpty()) {
       return InfinispanCollections.emptySet();
     } else {
       return copy;
     }
   } else {
     return flags;
   }
 }
Esempio n. 23
0
  @GwtIncompatible("java serialization not supported in GWT.")
  public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception {
    ImmutableSet<SomeEnum> original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B);
    int handleOffset = 6;
    byte[] serializedForm = serializeWithBackReference(original, handleOffset);
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedForm));

    ImmutableSet<?> deserialized = (ImmutableSet<?>) in.readObject();
    EnumSet<?> delegate = (EnumSet<?>) in.readObject();

    assertEquals(original, deserialized);
    assertTrue(delegate.remove(SomeEnum.A));
    assertTrue(deserialized.contains(SomeEnum.A));
  }
Esempio n. 24
0
  public void moveLeft() {
    // Apply force to move body unless it reached maximum velocity
    if (body.getLinearVelocity().x > -OBJECT_MAX_VELOCITY * OBJECT_VELO_AMPLIFIER) {
      body.applyForceToCenter(-OBJECT_MOVEMENT_FORCE * OBJECT_MOVE_AMPLIFIER, 0, true);

      // if object facing the wrong way, correct it
      if (currentStates.contains(IntelliObjectState.FACING_RIGHT)) {
        currentStates.remove(IntelliObjectState.FACING_RIGHT);
        currentStates.add(IntelliObjectState.FACING_LEFT);
        sprite = getSprite();
        sprite.flip(true, false);
      }
    }
  }
Esempio n. 25
0
  public void jump() {

    // get a list of world contacts
    Array<Contact> contacts = world.getContactList();

    // verify if body is grounded or still airborne
    for (Contact contact : contacts) {
      if (contact.getFixtureA().getBody().equals(body)
          || contact.getFixtureB().getBody().equals(body)) {
        currentStates.add(IntelliObjectState.GROUNDED);
        currentStates.remove(IntelliObjectState.AIRBORNE);
        OBJECT_JUMPS_LEFT = OBJECT_JUMPS_AVAILABLE;
      }
    }

    // if body can perform jump, then execute.
    if (OBJECT_JUMPS_LEFT > 0) {
      body.applyLinearImpulse(
          0, OBJECT_JUMP_IMPULSE, body.getPosition().x, body.getPosition().y, true);
      OBJECT_JUMPS_LEFT--;
      currentStates.add(IntelliObjectState.AIRBORNE);
      currentStates.remove(IntelliObjectState.GROUNDED);
    }
  }
 /**
  * Calculate which fields have no values across the whole range of titles. Iterates through all
  * the titles for each field value, until an entry is found or the end of the title list is
  * reached.
  *
  * @return a set of fields which are empty
  */
 private EnumSet<Field> findEmptyFields() {
   long s = System.currentTimeMillis();
   EnumSet<Field> empty = EnumSet.allOf(Field.class);
   for (Field f : Field.getFieldSet()) {
     // Check if any title has a value for this field
     for (KbartTitle kbt : titles) {
       if (kbt.hasFieldValue(f)) {
         empty.remove(f);
         break;
       }
     }
   }
   // Log the time, as this is an expensive way to monitor empty fields.
   // It should be done somehow during title conversion.
   log.debug("findEmptyFields() took " + (System.currentTimeMillis() - s) + "s");
   return empty;
 }
 /**
  * Handle the provided {@link InProcessTransformResult}, produced after evaluating the provided
  * {@link CommittedBundle} (potentially null, if the result of a root {@link PTransform}).
  *
  * <p>The result is the output of running the transform contained in the {@link
  * InProcessTransformResult} on the contents of the provided bundle.
  *
  * @param completedBundle the bundle that was processed to produce the result. Potentially {@code
  *     null} if the transform that produced the result is a root transform
  * @param completedTimers the timers that were delivered to produce the {@code completedBundle},
  *     or an empty iterable if no timers were delivered
  * @param result the result of evaluating the input bundle
  * @return the committed bundles contained within the handled {@code result}
  */
 public CommittedResult handleResult(
     @Nullable CommittedBundle<?> completedBundle,
     Iterable<TimerData> completedTimers,
     InProcessTransformResult result) {
   Iterable<? extends CommittedBundle<?>> committedBundles =
       commitBundles(result.getOutputBundles());
   // Update watermarks and timers
   EnumSet<OutputType> outputTypes = EnumSet.copyOf(result.getOutputTypes());
   if (Iterables.isEmpty(committedBundles)) {
     outputTypes.remove(OutputType.BUNDLE);
   } else {
     outputTypes.add(OutputType.BUNDLE);
   }
   CommittedResult committedResult =
       CommittedResult.create(
           result,
           completedBundle == null
               ? null
               : completedBundle.withElements((Iterable) result.getUnprocessedElements()),
           committedBundles,
           outputTypes);
   watermarkManager.updateWatermarks(
       completedBundle,
       result.getTimerUpdate().withCompletedTimers(completedTimers),
       committedResult,
       result.getWatermarkHold());
   // Update counters
   if (result.getCounters() != null) {
     mergedCounters.merge(result.getCounters());
   }
   // Update state internals
   CopyOnAccessInMemoryStateInternals<?> theirState = result.getState();
   if (theirState != null) {
     CopyOnAccessInMemoryStateInternals<?> committedState = theirState.commit();
     StepAndKey stepAndKey =
         StepAndKey.of(
             result.getTransform(), completedBundle == null ? null : completedBundle.getKey());
     if (!committedState.isEmpty()) {
       applicationStateInternals.put(stepAndKey, committedState);
     } else {
       applicationStateInternals.remove(stepAndKey);
     }
   }
   return committedResult;
 }
Esempio n. 28
0
 @Test
 public void testToEnumSet() {
   TimeUnit[] vals = TimeUnit.values();
   List<TimeUnit> enumValues =
       IntStreamEx.range(100).map(x -> x % vals.length).elements(vals).toList();
   checkShortCircuitCollector(
       "toEnumSet",
       EnumSet.allOf(TimeUnit.class),
       vals.length,
       enumValues::stream,
       MoreCollectors.toEnumSet(TimeUnit.class));
   enumValues = IntStreamEx.range(100).map(x -> x % (vals.length - 1)).elements(vals).toList();
   EnumSet<TimeUnit> expected = EnumSet.allOf(TimeUnit.class);
   expected.remove(vals[vals.length - 1]);
   checkShortCircuitCollector(
       "toEnumSet", expected, 100, enumValues::stream, MoreCollectors.toEnumSet(TimeUnit.class));
   checkCollectorEmpty(
       "Empty", EnumSet.noneOf(TimeUnit.class), MoreCollectors.toEnumSet(TimeUnit.class));
 }
  private Map<String, String> parseXnioOption(final XMLExtendedStreamReader reader)
      throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
    final int count = reader.getAttributeCount();
    String optionName = null;
    String optionValue = null;
    for (int i = 0; i < count; i++) {
      requireNoNamespaceAttribute(reader, i);
      final String value = reader.getAttributeValue(i);
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      required.remove(attribute);
      switch (attribute) {
        case NAME:
          {
            if (value.trim().isEmpty()) {
              throw ParseUtils.invalidAttributeValue(reader, i);
            }
            optionName = value;
            break;
          }
        case VALUE:
          {
            optionValue = value;
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }
    if (!required.isEmpty()) {
      throw missingRequired(reader, required);
    }
    // This element is just composed of attributes which we already processed, so no more content
    // is expected
    requireNoContent(reader);

    return Collections.singletonMap(optionName, optionValue);
  }
  /**
   * Parse a Triangle SingleDeclarationParser.
   *
   * <p>Single-Declaration ::= const Identifier ~ Expression | var Identifier : Type-Denoter | proc
   * Identifier (Formal-Parameter-Sequence) ~ Single-Command | func Identifier
   * (Formal-Parameter-Sequence) : Type-Denoter ~ Expression | Type Identifier ~ Type-Denoter
   *
   * <p>To be overridden by the specialized command parse subclasses.
   *
   * @param token the initial token.
   * @return the root node of the generated parse tree.
   * @throws Exception if an error occurred.
   */
  public void parse(Token token) throws Exception {
    SingleCommandParser singleCommand = null;
    ExpressionParser expression = null;
    FormalParameterSequenceParser formalParameterSequence = null;
    TypeDenoterParser typeDenoter = null;
    EnumSet<TriangleTokenType> syncSet = null;
    TypeSpec identifierType = TrianglePredefined.undefinedType;
    Token identifierToken = null;
    ICode routineICode = null;

    token = currentToken();

    switch ((TriangleTokenType) token.getType()) {
      case CONST:
        identifierToken = nextToken();
        syncSet = EnumSet.of(TILDE);
        syncSet.addAll(ExpressionParser.FIRST_FOLLOW_SET);
        synchronize(IDENTIFIER, MISSING_IDENTIFIER, syncSet);
        syncSet.remove(TILDE);
        token = synchronize(TILDE, MISSING_TILDE, syncSet);
        expression = new ExpressionParser(this);
        ICodeNode expressionNode = expression.parse(token);

        SymTabEntry constantId = symTabStack.lookupLocal(identifierToken.getText().toLowerCase());
        // Enter the new identifier into the symbol table
        // but don't set how it's defined yet.
        if (constantId == null) {
          constantId = symTabStack.enterLocal(identifierToken.getText().toLowerCase());
          constantId.setDefinition(DefinitionImpl.CONSTANT);
          constantId.setAttribute(CONSTANT_VALUE, expressionNode);
          constantId.appendLineNumber(identifierToken.getLineNumber());
          constantId.setTypeSpec(expressionNode.getTypeSpec());
        } else {
          errorHandler.flag(identifierToken, IDENTIFIER_REDEFINED, this);
        }
        break;
      case VAR:
        identifierToken = nextToken();
        syncSet = EnumSet.of(COLON);
        syncSet.addAll(TypeDenoterParser.FIRST_FOLLOW_SET);
        synchronize(IDENTIFIER, MISSING_IDENTIFIER, syncSet);

        syncSet.remove(COLON);
        token = synchronize(COLON, MISSING_COLON, syncSet);

        typeDenoter = new TypeDenoterParser(this);
        identifierType = typeDenoter.parse(token);

        SymTabEntry variableId = symTabStack.lookupLocal(identifierToken.getText().toLowerCase());
        // Enter the new identifier into the symbol table
        // but don't set how it's defined yet.
        if (variableId == null) {
          variableId = symTabStack.enterLocal(identifierToken.getText().toLowerCase());
          variableId.setDefinition(DefinitionImpl.VARIABLE);
          variableId.appendLineNumber(identifierToken.getLineNumber());
          variableId.setTypeSpec(identifierType);
        } else {
          errorHandler.flag(identifierToken, IDENTIFIER_REDEFINED, this);
        }
        break;
      case PROC:
        identifierToken = nextToken();
        routineICode = ICodeFactory.createICode();
        syncSet = EnumSet.of(LEFT_PAREN);
        syncSet.addAll(FormalParameterSequenceParser.FIRST_FOLLOW_SET);
        token = synchronize(IDENTIFIER, MISSING_IDENTIFIER, syncSet);
        syncSet.remove(LEFT_PAREN);
        token = synchronize(LEFT_PAREN, MISSING_LEFT_PAREN, syncSet);
        SymTabEntry procId = symTabStack.lookupLocal(identifierToken.getText().toLowerCase());
        // Enter the new identifier into the symbol table
        // but don't set how it's defined yet.
        if (procId == null) {
          procId = symTabStack.enterLocal(identifierToken.getText().toLowerCase());
          procId.setTypeSpec(TrianglePredefined.undefinedType);
          procId.setDefinition(DefinitionImpl.PROCEDURE);
          procId.appendLineNumber(identifierToken.getLineNumber());
          procId.setAttribute(ROUTINE_SYMTAB, symTabStack.push());
          procId.setAttribute(ROUTINE_ICODE, routineICode);
        } else {
          errorHandler.flag(identifierToken, IDENTIFIER_REDEFINED, this);
          procId = null;
        }

        formalParameterSequence = new FormalParameterSequenceParser(this);
        ArrayList<SymTabEntry> procParamList = formalParameterSequence.parse(token);
        syncSet = EnumSet.of(TILDE);
        syncSet.addAll(SingleCommandParser.FIRST_FOLLOW_SET);
        token = synchronize(RIGHT_PAREN, MISSING_RIGHT_PAREN, syncSet);
        syncSet.remove(TILDE);
        token = synchronize(TILDE, MISSING_TILDE, syncSet);
        singleCommand = new SingleCommandParser(this);
        routineICode.setRoot(singleCommand.parse(token));
        if (procId != null) {
          procId.setAttribute(ROUTINE_PARMS, procParamList);
        }
        symTabStack.pop();
        break;
      case FUNC:
        identifierToken = nextToken();
        routineICode = ICodeFactory.createICode();
        SymTabEntry funcId = symTabStack.lookupLocal(identifierToken.getText().toLowerCase());
        // Enter the new identifier into the symbol table
        // but don't set how it's defined yet.
        if (funcId == null) {
          funcId = symTabStack.enterLocal(identifierToken.getText().toLowerCase());
          funcId.setDefinition(DefinitionImpl.FUNCTION);
          funcId.appendLineNumber(identifierToken.getLineNumber());
          funcId.setTypeSpec(TrianglePredefined.undefinedType);
          funcId.setAttribute(ROUTINE_SYMTAB, symTabStack.push());
          funcId.setAttribute(ROUTINE_ICODE, routineICode);
        } else {
          errorHandler.flag(identifierToken, IDENTIFIER_REDEFINED, this);
          funcId = null;
        }
        syncSet = EnumSet.of(LEFT_PAREN);
        syncSet.addAll(FormalParameterSequenceParser.FIRST_FOLLOW_SET);
        token = synchronize(IDENTIFIER, MISSING_IDENTIFIER, syncSet);
        syncSet.remove(LEFT_PAREN);
        token = synchronize(LEFT_PAREN, MISSING_LEFT_PAREN, syncSet);
        formalParameterSequence = new FormalParameterSequenceParser(this);
        ArrayList<SymTabEntry> funcParamList = formalParameterSequence.parse(token);
        syncSet = EnumSet.of(COLON);
        syncSet.addAll(TypeDenoterParser.FIRST_FOLLOW_SET);
        synchronize(RIGHT_PAREN, MISSING_RIGHT_PAREN, syncSet);
        syncSet.remove(COLON);
        token = synchronize(COLON, MISSING_COLON, syncSet);
        Token typeToken = currentToken();
        typeDenoter = new TypeDenoterParser(this);
        TypeSpec funcType = typeDenoter.parse(token);
        syncSet = ExpressionParser.FIRST_FOLLOW_SET.clone();
        token = synchronize(TILDE, MISSING_TILDE, syncSet);
        expression = new ExpressionParser(this);
        routineICode.setRoot(expression.parse(token));
        if (funcId != null) {
          funcId.setTypeSpec(funcType);
          funcId.setAttribute(ROUTINE_PARMS, funcParamList);
          if (!routineICode.getRoot().getTypeSpec().equals(funcType)) {
            errorHandler.flag(typeToken, RETURN_TYPE_MISMATCH, this);
          }
        }
        symTabStack.pop();
        break;
      case TYPE:
        identifierToken = nextToken();
        syncSet = EnumSet.of(TILDE);
        syncSet.addAll(TypeDenoterParser.FIRST_FOLLOW_SET);
        synchronize(IDENTIFIER, MISSING_IDENTIFIER, syncSet);
        syncSet.remove(TILDE);
        token = synchronize(TILDE, MISSING_TILDE, syncSet);
        typeDenoter = new TypeDenoterParser(this);
        TypeSpec typeType = typeDenoter.parse(token);
        SymTabEntry typeId = symTabStack.lookupLocal(identifierToken.getText().toLowerCase());
        // Enter the new identifier into the symbol table
        // but don't set how it's defined yet.
        if (typeId == null) {
          typeId = symTabStack.enterLocal(identifierToken.getText().toLowerCase());
          typeId.setDefinition(DefinitionImpl.TYPE);
          typeId.appendLineNumber(identifierToken.getLineNumber());
          typeId.setTypeSpec(typeType);
        } else {
          errorHandler.flag(token, IDENTIFIER_REDEFINED, this);
        }
        break;
      default:
        errorHandler.flag(token, MISSING_DECLARATION, this);
        break;
    }
  }