budget/src/main/java/budget/backend/stores/TagStore.java
@Override
  public Tag define(iTag parent, String name) throws IllegalArgumentException
  {
    try{
      //find parent
      if (map.containsKey(parent.getId())){
        // create new ID
        String newId = parent.getId();
        int firstZero = newId.indexOf("0");
        if (firstZero > 0){
          newId = newId.substring(0, firstZero);
          if (parent.getDescendants().size() == 9) 
            throw new IllegalArgumentException("Parent descendants out of bound");
          else
            newId += String.valueOf(parent.getDescendants().size()+1);
          while (newId.length() < 9) newId += "0";
        } else {
          throw new IllegalArgumentException("Tree structure is at maximum height!");
        }
        iTag t = new Tag(parent, new LinkedList<Tag>(),newId, name);
        dataChecker.verifyTag((Tag) t);
        // add new tag to the structure
        parent.addDescendant((Tag) t);
        map.put(newId, t);
        return (Tag) t;
      }
      //parent was not found
      else 
        throw new IllegalArgumentException("structure does not contain the given parent object!");
    }
    catch(Exception e){
      throw e;
    }
  }
/**
   * Define a new tag. Generate new ID given the parent Tag, and put the new object in the structure
   * @parent
   * @name
   * @throws IllegalArgumentException
   */
Define a new tag. Generate new ID given the parent Tag, and put the new object in the structure
@parent
@name
@throws IllegalArgumentException
Define a new tag . Generate new ID given the parent Tag and put the new object in the structure @parent @name @throws IllegalArgumentException
@Override
  public Tag define(iTag parent, String name) throws IllegalArgumentException
  {
    try{
      if (map.containsKey(parent.getId())){
        String newId = parent.getId();
        int firstZero = newId.indexOf("0");
        if (firstZero > 0){
          newId = newId.substring(0, firstZero);
          if (parent.getDescendants().size() == 9) 
            throw new IllegalArgumentException("Parent descendants out of bound");
          else
            newId += String.valueOf(parent.getDescendants().size()+1);
          while (newId.length() < 9) newId += "0";
        } else {
          throw new IllegalArgumentException("Tree structure is at maximum height!");
        }
        iTag t = new Tag(parent, new LinkedList<Tag>(),newId, name);
        dataChecker.verifyTag((Tag) t);
        parent.addDescendant((Tag) t);
        map.put(newId, t);
        return (Tag) t;
      }
      else 
        throw new IllegalArgumentException("structure does not contain the given parent object!");
    }
    catch(Exception e){
      throw e;
    }
  }
@ Override public Tag define ( iTag parent , String name ) throws IllegalArgumentException { try { if ( map . containsKey ( parent . getId ( ) ) ) { String newId = parent . getId ( ) ; int firstZero = newId . indexOf ( "0" ) ; if ( firstZero > 0 ) { newId = newId . substring ( 0 , firstZero ) ; if ( parent . getDescendants ( ) . size ( ) == 9 ) throw new IllegalArgumentException ( "Parent descendants out of bound" ) ; else newId += String . valueOf ( parent . getDescendants ( ) . size ( ) + 1 ) ; while ( newId . length ( ) < 9 ) newId += "0" ; } else { throw new IllegalArgumentException ( "Tree structure is at maximum height!" ) ; } iTag t = new Tag ( parent , new LinkedList < Tag > ( ) , newId , name ) ; dataChecker . verifyTag ( ( Tag ) t ) ; parent . addDescendant ( ( Tag ) t ) ; map . put ( newId , t ) ; return ( Tag ) t ; } else throw new IllegalArgumentException ( "structure does not contain the given parent object!" ) ; } catch ( Exception e ) { throw e ; } }
Define a new tag.
Define a new tag .
//find parent // create new ID // add new tag to the structure //parent was not found