@SuppressWarnings("unchecked") @Override protected K getObjectId(T value) { if (value != null && value instanceof HasId) { return (K) ((HasId) value).getId(); } else { return null; } }
/** * Get data transfer object ids. * * @param set the objects with id * @return the List of ids */ public static List<String> getDtoIds(Set<HasId> set) { List<String> ids; if (set == null || set.isEmpty()) { ids = Collections.emptyList(); } else { ids = new ArrayList<>(set.size()); for (HasId hasId : set) { ids.add(hasId.getId()); } } return ids; }
/** * Get Long id from object with id. * * @param hasId the object with id * @return id */ public static Long getLongId(HasId hasId) { Long longId = null; if (hasId != null) { String id = hasId.getId(); longId = getLongId(id); } return longId; }
/** * Checks whether the given object's ID is blank or can be parsed as <code>long</code>. * * @param object An identifiable object to check * @return <code>true</code> if the given object's ID is blank or can be parsed as * <code>long</code>, <code>false</code> otherwise. */ public static boolean isValidSqlObject(HasId object) { boolean correct = false; if (object != null) { String id = object.getId(); if (StringUtils.isNotBlank(id)) { try { Long.parseLong(id); correct = true; } catch (NumberFormatException cause) { LOG.debug("Exception during ID validation: the ID is not blank, but cannot be parsed as " + "long."); } } else { correct = true; } } return correct; }
protected List<String> getIdsDto(List<? extends HasId> hId) { List<String> ids = new ArrayList<>(); for (HasId id : hId) { ids.add(id.getId()); } Collections.sort(ids); return ids; } }
/** * Convert DTO to thrift DataStruct. * * @param <T> the DTO generic type * @param dto the DTO * @return the thrift DataStruct */ public static <T extends HasId> DataStruct toDataStruct(T dto) { DataStruct dataStruct = new DataStruct(); if (dto != null) { dataStruct.setKey(dto.getId()); dataStruct.setData(DtoByteMarshaller.toBytes(dto)); } return dataStruct; }
public class ToId implements Function<HasId, Long> { public Long apply(HasId hasId) { return hasId.getId(); } }
public boolean containsId(List<HasId> list, long id) { for (HasId object : list) { if (object.getId() == id) { return true; } } return false; }