Exemplo n.º 1
0
  public boolean bibaWrite(String[] arguments) {
    String subject, object, subjectLevel, objectLevel;
    HashSet<String> subjectCategories, objectCategories;

    if (!(arguments.length == 2 || arguments.length == 3)) {
      return false;
    }

    subject = arguments[0];
    object = arguments[1];
    // arguments[2] can be the value (ignored)

    if (!this.subjectLevels.containsKey(subject)
        || !this.objectLevels.containsKey(object)
        || !this.subjectCategories.containsKey(subject)
        || !this.objectCategories.containsKey(object)) {
      return false;
    }

    subjectLevel = this.subjectLevels.get(subject);
    objectLevel = this.objectLevels.get(object);
    subjectCategories = this.subjectCategories.get(subject);
    objectCategories = this.objectCategories.get(object);

    if (this.levels.indexOf(subjectLevel) < this.levels.indexOf(objectLevel)) {
      return false;
    }

    if (!subjectCategories.containsAll(objectCategories)) {
      return false;
    }

    System.out.println("Subject '" + subject + "' writes object '" + object + "'.");
    return true;
  }
Exemplo n.º 2
0
  public boolean bibaRead(String[] arguments) {
    String subject, object, subjectLevel, objectLevel;
    HashSet<String> subjectCategories, objectCategories;

    if (arguments.length != 2) {
      return false;
    }

    subject = arguments[0];
    object = arguments[1];

    if (!this.subjectLevels.containsKey(subject)
        || !this.objectLevels.containsKey(object)
        || !this.subjectCategories.containsKey(subject)
        || !this.objectCategories.containsKey(object)) {
      return false;
    }

    subjectLevel = this.subjectLevels.get(subject);
    objectLevel = this.objectLevels.get(object);
    subjectCategories = this.subjectCategories.get(subject);
    objectCategories = this.objectCategories.get(object);

    if (this.levels.indexOf(subjectLevel) > this.levels.indexOf(objectLevel)) {
      return false;
    }

    if (!subjectCategories.containsAll(objectCategories)) {
      return false;
    }

    System.out.println("Subject '" + subject + "' reads object '" + object + "'.");
    return true;
  }