Set<HighlightInfo> (Collection<? extends HighlightInfo> infos) { Set<HighlightInfo> index = CollectionFactory.createCustomHashingStrategySet(new HashingStrategy<>() { @Override public int hashCode(HighlightInfo object) { return object == null ? 0 : Objects.hash(object.startOffset, object.endOffset); //good enough } @Override public boolean equals(HighlightInfo o1, HighlightInfo o2) { return o1==null || o2 == null ? o1 == o2 : matchesPattern(o1, o2, false); } }); index.addAll(infos); return index; }