code: public MessageSet getCachedMessagesWhere(Predicate<Message> filter) {
          synchronized (messages) {
              return messages.values().stream()
                      .map(Reference::get)
                      .filter(Objects::nonNull)
                      .filter(filter)
                      .collect(Collectors.toCollection(MessageSetImpl::new));
          }
      }
docs: Get messages from the cache that satisfy a given condition.
  
  @param filter The filter for messages to be included.
  @return A set of cached messages satisfying the condition.