/** * Tests whether this {@code ChannelId} matches the given {@code ChannelId}. * * <p>If the given {@code ChannelId} is {@link #isWild() wild}, then it matches only if it is * equal to this {@code ChannelId}. * * <p>If this {@code ChannelId} is non-wild, then it matches only if it is equal to the given * {@code ChannelId}. * * <p>Otherwise, this {@code ChannelId} is either shallow or deep wild, and matches {@code * ChannelId}s with the same number of equal segments (if it is shallow wild), or {@code * ChannelId}s with the same or a greater number of equal segments (if it is deep wild). * * @param channelId the channelId to match * @return true if this {@code ChannelId} matches the given {@code ChannelId} */ public boolean matches(ChannelId channelId) { resolve(); if (channelId.isWild()) return equals(channelId); switch (_wild) { case 0: { return equals(channelId); } case 1: { if (channelId._segments.length != _segments.length) return false; for (int i = _segments.length - 1; i-- > 0; ) if (!_segments[i].equals(channelId._segments[i])) return false; return true; } case 2: { if (channelId._segments.length < _segments.length) return false; for (int i = _segments.length - 1; i-- > 0; ) if (!_segments[i].equals(channelId._segments[i])) return false; return true; } default: { throw new IllegalStateException(); } } }
/** * @param id the channel to test * @return whether this {@code ChannelId} is the parent of the given {@code ChannelId} * @see #isAncestorOf(ChannelId) */ public boolean isParentOf(ChannelId id) { resolve(); if (isWild() || depth() != id.depth() - 1) return false; for (int i = _segments.length; i-- > 0; ) { if (!_segments[i].equals(id._segments[i])) return false; } return true; }
@Override public String toString() { return _id.toString(); }
public boolean isService() { return _id.isService(); }
public boolean isMeta() { return _id.isMeta(); }
public String getId() { return _id.toString(); }
public boolean isWild() { return _id.isWild(); }