Skip to content

Commit

Permalink
update getObject methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffz committed Apr 8, 2024
1 parent e5d8e16 commit e5f0732
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) {

this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef);
}

return this;
}
}
Expand Down Expand Up @@ -412,10 +412,19 @@ <M extends U, U> void writeOutput(Path path, M object, Optional<Class<U>> superC
* </ul>
*/
public <T> T getFirstObject(Class<T> classRef) {
for (Object object : this.objects) {
int index = -1;
for (int i = 0; i < this.objects.size(); i++) {
Object object = this.objects.get(i);

if (classRef.isAssignableFrom(object.getClass())) {
return classRef.cast(object);
index = i;
break;
}

}

if (index > -1) {
return classRef.cast(this.objects.remove(index));
}

throw new ContractException(CoreTranslationError.UNKNOWN_CLASSREF);
Expand All @@ -429,10 +438,13 @@ public <T> T getFirstObject(Class<T> classRef) {
*/
public <T> List<T> getObjects(Class<T> classRef) {
List<T> objects = new ArrayList<>();
for (Object object : this.objects) {
for (int i = 0; i < this.objects.size(); i++) {
Object object = this.objects.get(i);

if (classRef.isAssignableFrom(object.getClass())) {
objects.add(classRef.cast(object));
objects.add(classRef.cast(this.objects.remove(i)));
}

}

return objects;
Expand All @@ -442,7 +454,12 @@ public <T> List<T> getObjects(Class<T> classRef) {
* Returns the entire list of read in objects
*/
public List<Object> getObjects() {
return this.objects;
List<Object> objects = new ArrayList<>();
for (int i = 0; i < this.objects.size(); i++) {
objects.add(this.objects.remove(i));
}

return objects;
}

}

0 comments on commit e5f0732

Please sign in to comment.