Creates a new Relation and adds it to this set. Uses the default relation implementation at SimpleRelation. @param type the type for the new relation. @param members the annotation IDs for the annotations that are members in this relation. @return the newly created {@link R
(String type, int... members)
| 174 | * @return the newly created {@link Relation} instance. |
| 175 | */ |
| 176 | public Relation addRelation(String type, int... members) |
| 177 | throws IllegalArgumentException { |
| 178 | |
| 179 | if(members.length < 2) |
| 180 | throw new IllegalArgumentException( |
| 181 | "A relation needs to have atleast two members"); |
| 182 | |
| 183 | for(int member : members) { |
| 184 | if(!indexById.containsKey(member) && annSet.get(member) == null) |
| 185 | throw new IllegalArgumentException( |
| 186 | "Member must be from within this annotation set"); |
| 187 | } |
| 188 | |
| 189 | if(type == null || type.trim().equals("")) |
| 190 | throw new IllegalArgumentException("A relation must have a type"); |
| 191 | |
| 192 | // now we have sanity checked the params create the relation |
| 193 | Relation rel = |
| 194 | new SimpleRelation( |
| 195 | ((DocumentImpl)annSet.getDocument()).getNextAnnotationId(), |
| 196 | type, members); |
| 197 | |
| 198 | // add the relation to the set |
| 199 | add(rel); |
| 200 | |
| 201 | // return the relation to the calling method |
| 202 | return rel; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Adds an externally-created {@link Relation} instance. |
nothing calls this directly
no test coverage detected