@Override public IndexFamily getCurrentFamily() { if (indices == null) { return IndexFamily.NULL; } for (Index index : indices) { if (index != null) { return index.getFamily(); } } return IndexFamily.NULL; }
/** * Turns indices into strings for easier comparison and changelog message concatentation. * * @param indices * @return */ private Set<String> stringifyIndices(List<Index> indices) { Set<String> original = new HashSet<>(); for (Index index : indices) { if (index != null && index.getId() != Index.UNSAVED_ID) { original.add(index.getFamily().getName() + " - " + index.getLabel()); } } return original; }
@Override public void setIndices(List<Index> originalIndices) { List<Index> indices = new ArrayList<>(); for (Index index : originalIndices) { if (index != null) { indices.add(index); } } Index.sort(indices); IndexFamily current = null; for (Index index : indices) { if (index == null) continue; if (current == null) { current = index.getFamily(); } else { if (current.getId() != index.getFamily().getId()) { throw new IllegalArgumentException(String.format( "Indices not all from the same family. (%d:%s vs %d:%s)", current.getId(), current.getName(), index.getFamily().getId(), index.getFamily().getName())); } } } this.indices = indices; }
public String getLabel() { if (getSequence() == null || getFamily().hasFakeSequence()) return getName(); return getName() + " (" + getSequence() + ")"; }
public static IndexDto asDto(@Nonnull Index from, boolean includeFamily) { IndexDto dto = new IndexDto(); dto.setId(from.getId()); dto.setLabel(from.getLabel()); dto.setName(from.getName()); dto.setPosition(from.getPosition()); dto.setSequence(from.getSequence()); if (includeFamily) { dto.setFamily(asDto(from.getFamily(), false)); } return dto; }
dto.setIndexFamilyName(from.getIndices().get(0).getFamily().getName()); for (Index index : from.getIndices()) { switch (index.getPosition()) {