Skip to content

Commit

Permalink
add utility functions for base model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
c-eg committed Nov 25, 2024
1 parent 665c7de commit 1e69d41
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/info/movito/themoviedbapi/util/ModelUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package info.movito.themoviedbapi.util;

import java.util.Collection;
import java.util.List;

import info.movito.themoviedbapi.model.core.NamedIdElement;
import info.movito.themoviedbapi.model.core.NamedStringIdElement;

/**
* TMDB API Model Utility.
*/
public final class ModelUtil {
private ModelUtil() {
}

/**
* Gets a list of names (from the name field) from the items in the collection provided.
* For model classes extending {@link NamedIdElement}.
*
* @param collection the collection.
* @return the list of names.
*/
public static List<String> getNames(Collection<? extends NamedIdElement> collection) {
return collection.stream().map(NamedIdElement::getName).toList();
}

/**
* Gets a list of names (from the name field) from the items in the collection provided.
* For model classes extending {@link NamedStringIdElement}.
*
* @param collection the collection.
* @return the list of names.
*/
public static List<String> getNamesString(Collection<? extends NamedStringIdElement> collection) {
return collection.stream().map(NamedStringIdElement::getName).toList();
}
}
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@
exports info.movito.themoviedbapi.tools.builders.discover;
exports info.movito.themoviedbapi.tools.sortby;
exports info.movito.themoviedbapi.tools.model.time;
exports info.movito.themoviedbapi.util;
}

0 comments on commit 1e69d41

Please sign in to comment.