Esempio n. 1
0
  /**
   * Gets hotspotChoice child with given identifier or null.
   *
   * @param identifier given identifier
   * @return hotspotChoice with given identifier or null
   */
  public HotspotChoice getHotspotChoice(final Identifier identifier) {
    for (final HotspotChoice choice : getHotspotChoices()) {
      if (choice.getIdentifier() != null && choice.getIdentifier().equals(identifier)) {
        return choice;
      }
    }

    return null;
  }
Esempio n. 2
0
  @Override
  public boolean validateResponse(
      final ItemSessionController itemSessionController, final Value responseValue) {
    /* Extract response values */
    final Set<Identifier> responseChoiceIdentifiers = new HashSet<Identifier>();
    if (responseValue.isNull()) {
      /* (Empty response) */
    } else if (responseValue.getCardinality().isList()) {
      /* (Container response) */
      for (final SingleValue hotspotChoiceIdentifier : (ListValue) responseValue) {
        responseChoiceIdentifiers.add(
            ((IdentifierValue) hotspotChoiceIdentifier).identifierValue());
      }
    } else {
      /* (Single response - this won't actually happen) */
      responseChoiceIdentifiers.add(((IdentifierValue) responseValue).identifierValue());
    }

    /* Chheck min/max (if set) */
    final Integer maxChoices = getMaxChoices();
    final Integer minChoices = getMinChoices();
    if (maxChoices != null && minChoices != null) {
      if (responseChoiceIdentifiers.size() < minChoices.intValue()
          || responseChoiceIdentifiers.size() > maxChoices.intValue()) {
        return false;
      }
    }

    /* Check that each identifier is valid */
    final Set<Identifier> choiceIdentifiers = new HashSet<Identifier>();
    for (final HotspotChoice choice : getHotspotChoices()) {
      choiceIdentifiers.add(choice.getIdentifier());
    }
    for (final Identifier choiceIdentifier : responseChoiceIdentifiers) {
      if (!choiceIdentifiers.contains(choiceIdentifier)) {
        return false;
      }
    }

    return true;
  }