/** * This method take string id from <code>GenericModel</code> object. * * @param model <code>GenericModel</code> object * @return the id as string type */ public static String idToString(GenericModel<?> model) { String id = null; if (model != null) { Long lid = model.getId(); id = lid != null ? lid.toString() : null; } return id; }
/** * Get model ids. * * @param set the objects with id * @return the List of ids */ public static Set<String> getGenericModelIds(Set<? extends GenericModel<?>> set) { Set<String> ids; if (set == null || set.isEmpty()) { ids = Collections.emptySet(); } else { ids = new HashSet<>(set.size()); for (GenericModel<?> model : set) { ids.add(model.getStringId()); } } return ids; }
/** * Get generic model ids. * * @param idSet the ids set * @param model the GenericModel instance * @param <V> the Set generic * @return set of generic model ids */ public static <V> Set<V> getGenericModelIds(Set<String> idSet, GenericModel model) { Set<V> dataSet = new HashSet<>(); for (String id : idSet) { dataSet.add((V) model.newInstance(id)); } return dataSet; }
/** * This method take string id from <code>GenericModel</code> object. * * @param model <code>GenericModel</code> object * @return the id as string type */ public static String idToString(GenericModel<? extends Object> model) { String id = null; if (model != null) { Long lid = model.getId(); id = lid != null ? lid.toString() : null; } return id; }
protected List<String> getIds(List<? extends GenericModel> modelList) { List<String> ids = new ArrayList<>(); for (GenericModel gm : modelList) { ids.add(gm.getStringId()); } Collections.sort(ids); return ids; }
protected abstract GenericModel<T> newInstance(Long id);
/** * Get string id. * * @param hasId the object that has id * @return id */ public static String getStringId(GenericModel<?> hasId) { String stringId = null; if (hasId != null) { Long id = hasId.getId(); stringId = getStringId(id); } return stringId; }
@SuppressWarnings("rawtypes") private List<String> getIds(Set<Topic> topics) { List<String> ids = Collections.emptyList(); if (topics != null && !topics.isEmpty()) { ids = new ArrayList<>(); for (GenericModel model : topics) { ids.add(model.getId().toString()); } } return ids; } }