Пример #1
0
  /**
   * 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();
        }
    }
  }
Пример #2
0
  /**
   * @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;
  }
Пример #3
0
 /**
  * @return whether this {@code ChannelId} is either {@link #isShallowWild() shallow wild} or
  *     {@link #isDeepWild() deep wild}
  */
 public boolean isWild() {
   resolve();
   return _wild > 0;
 }
Пример #4
0
 /**
  * @return The list of wilds channels that match this channel, or the empty list if this channel
  *     is already wild.
  */
 public List<String> getWilds() {
   resolve();
   return _wilds;
 }
Пример #5
0
 /**
  * @param i the segment index
  * @return the i-nth segment of this channel, or null if no such segment exist
  * @see #depth()
  */
 public String getSegment(int i) {
   resolve();
   if (i >= _segments.length) return null;
   return _segments[i];
 }
Пример #6
0
 /**
  * @return the {@code ChannelId} parent of this {@code ChannelId}
  * @see #isParentOf(ChannelId)
  */
 public String getParent() {
   resolve();
   return _parent;
 }
Пример #7
0
 /**
  * @return how many segments this {@code ChannelId} is made of
  * @see #getSegment(int)
  */
 public int depth() {
   resolve();
   return _segments.length;
 }
Пример #8
0
 /**
  * Deep wild {@code ChannelId}s end with a double wild character "**" and {@link
  * #matches(ChannelId) match} non wild channels with the same or greater {@link #depth() depth}.
  *
  * <p>Example: {@code /foo/**} matches {@code /foo/bar} and {@code /foo/bar/baz}.
  *
  * @return whether this {@code ChannelId} is a deep wild channel id
  */
 public boolean isDeepWild() {
   resolve();
   return _wild > 1;
 }