/* (non-Javadoc)
@see com.ibm.ws.sib.msgstore.ItemCollection#findFirstMatchingItemStream(com.ibm.ws.sib.msgstore.Filter)
168982
public final ItemStream findFirstMatchingItemStream(Filter filter) throws MessageStoreException 
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "findFirstMatchingItemStream", filter);

        ItemStream item = (ItemStream) _itemStreams.findFirstMatching(filter);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "findFirstMatchingItemStream", item);
        return item;
    }
1161116
private void findMatches(Match match, int n) throws IOException {
    if (n > 0) {
      int largestMatchingEndPosition = match.endPosition();
      Set<Integer> list = ignoreItem.getFullEndPositionList(spans.docID(),
          match.endPosition());
      // try to find matches with existing queue
      if (!queueSpans.isEmpty()) {
        Match span;
        for (int i = 0; i < queueSpans.size(); i++) {
          span = queueSpans.get(i);
          if (match.endPosition() == span.startPosition()
              || (list != null && list.contains(span.startPosition()))) {
            findMatches(new Match(match.startPosition(), span.endPosition()),
                (n - 1));
            largestMatchingEndPosition = Math.max(largestMatchingEndPosition,
                span.endPosition());
          }
        }
      }
      // extend queue if necessary and possible
      while (!lastSpan && (largestMatchingEndPosition >= lastStartPosition)) {
        if (spans.nextStartPosition() == NO_MORE_POSITIONS) {
          lastSpan = true;
        } else {
          Match span = new Match(spans.startPosition(), spans.endPosition());
          queueSpans.add(span);
          lastStartPosition = spans.startPosition();
          // check if this provides new match
          if (match.endPosition() == span.startPosition()
              || (list != null && list.contains(span.startPosition()))) {
            findMatches(new Match(match.startPosition(), span.endPosition()),
                (n - 1));
            largestMatchingEndPosition = Math.max(largestMatchingEndPosition,
                span.endPosition());
          }
        }
      }
    } else {
      // only unique spans
      if (!queueMatches.contains(match)) {
        queueMatches.add(match);
      }
    }
  }
297445
@SuppressWarnings("unchecked")
  public <S, D> ConditionalConverter<S, D> getFirstSupported(Class<?> sourceType,
      Class<?> destinationType) {
    ConditionalConverter<S, D> firstPartialMatchConverter = null;

    for (ConditionalConverter<?, ?> converter : converters) {
      MatchResult matchResult = converter.match(sourceType, destinationType);
      if (matchResult == MatchResult.FULL)
        return (ConditionalConverter<S, D>) converter;
      if (firstPartialMatchConverter == null
          && matchResult == MatchResult.PARTIAL)
        firstPartialMatchConverter = (ConditionalConverter<S, D>) converter;
    }
    return firstPartialMatchConverter;
  }
1087695
public boolean isFilterMatch(BaseMessageHeader messageHeader)
    {
        boolean bMatch = super.isFilterMatch(messageHeader);
        if (bMatch)
        {
            if (m_bPrivate)
                bMatch = false; // Only a matching SessionMessageHeader will be sent.
            if ((messageHeader != null)
                && (this.getObjectKey() != null)
                && (messageHeader instanceof SessionMessageHeader)
                && (((SessionMessageHeader)messageHeader).getObjectKey() != null)
                && (!this.getObjectKey().equals(((SessionMessageHeader)messageHeader).getObjectKey())))
                    bMatch = false;   // No match!
            else
                    bMatch = true;    // Match!
        }
        return bMatch;    // MATCH!!!
    }
1062390
private Filter createValueMatchFilter(
      FilterAdapterContext context, SingleColumnValueFilter filter) throws IOException {
    ValueFilter valueFilter = new ValueFilter(filter.getOperator(), filter.getComparator());
    return delegateAdapter.toFilter(context, valueFilter);
  }
32088
public static <T extends AnnotationDesc> T findFirst(T[] original, Predicate<T> filter) {
		for (final T element : original) {
			if (filter.test(element)) {
				return element;
			}
		}
		return null;
	}
811955
protected EofMatch findEof(Match matches[]) {
        EofMatch ourEof = null;
        for (int i = 0; i < matches.length; i++) {
            if (matches[i] instanceof EofMatch)
                ourEof = (EofMatch) matches[i];
        }

        if (ourEof == null) {
            // Have to create our own
            ourEof = new EofMatch();
        }

        return ourEof;
    }
49886
public Listitem findMatchingItem(String label) {
        for (Listitem item : getChildren(Listitem.class)) {
            if (label.equalsIgnoreCase(item.getLabel())) {
                return item;
            }
        }
        
        return null;
    }
665460
public T getFirst() {
        Optional<Rsp<T>> retval=values().stream().filter(rsp -> rsp.getValue() != null).findFirst();
        return retval.isPresent()? retval.get().getValue() : null;
    }
1070548
public boolean filterMatches(AbstractItem item) throws MessageStoreException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "filterMatches", item);

    boolean result = true;
    
    // If messages are classified by XD, then check the classification up front.
    // If the index is 0, then there is no classification
    if(classIndex>0)
    {
      // If we're classifying then the classification property must match this
      // filter's classification
      result = false;
      
      //Do not throw exception if Message not available in the store
      boolean throwExceptionIfMessageNotAvailable = false;
      
      // Need to get the classification out of the message
      String keyClassification = ((SIMPMessage)item).getMessageControlClassification(throwExceptionIfMessageNotAvailable);              

      if(keyClassification != null && keyClassification.equalsIgnoreCase(classificationName))
        result = true;
      else
      {
        if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
          SibTr.debug(tc, "filter class: " + classificationName + ", message class: " + keyClassification);
      }
    }
    
    // If we still have a potential match, then drive any selector
    // processing through the parent class.
    if(result)
      result = parentFilter.filterMatches(item);

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "filterMatches", Boolean.valueOf(result));
    
    return result;
  }
314586
public final AbstractItem _findById(long itemID) throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "_findById", Long.valueOf(itemID));

        AbstractItem item = null;
        AbstractItemLink itemLink = getLink(itemID);
        if (null != itemLink)
        {
            item = itemLink.getItem();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "_findById", item);
        return item;
    }
67048
public final AbstractItem findFirstMatching(Filter filter) throws MessageStoreException
    {
        AbstractItem item = null;
        for (int priority = Priorities.HIGHEST_PRIORITY; null == item
                && priority >= Priorities.LOWEST_PRIORITY; priority--)
        {
            LinkedList tl = _prioritySublists[priority];
            if (null != tl)
            {
                item = tl.findFirstMatching(filter);
            }
        }
        return item;
    }
494994
public final AbstractItem removeFirstMatching(Filter filter, Transaction transaction) throws MessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "removeFirstMatching", new Object[] { filter, transaction});

        PrioritizedList refs = _references();
        AbstractItem item = refs.removeFirstMatching(filter, (PersistentTransaction)transaction);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "removeFirstMatching", item);
        return item;
    }
168395
private List<TopLevelItem> getItems(boolean recurse) {
        SortedSet<String> names;
        List<TopLevelItem> items = new ArrayList<>();

        synchronized (this) {
            names = new TreeSet<>(jobNames);
        }

        ItemGroup<? extends TopLevelItem> parent = getOwner().getItemGroup();
        List<TopLevelItem> parentItems = new ArrayList<>(parent.getItems());
        includeItems(parent, parentItems, names);

        Boolean statusFilter = this.statusFilter; // capture the value to isolate us from concurrent update
        Iterable<? extends TopLevelItem> candidates;
        if (recurse) {
            candidates = parent.getAllItems(TopLevelItem.class);
        } else {
            candidates = parent.getItems();
        }
        for (TopLevelItem item : candidates) {
            if (!names.contains(item.getRelativeNameFrom(getOwner().getItemGroup()))) continue;
            // Add if no status filter or filter matches enabled/disabled status:
            if(statusFilter == null || !(item instanceof ParameterizedJobMixIn.ParameterizedJob) // TODO or better to call the more generic Job.isBuildable?
                              || ((ParameterizedJobMixIn.ParameterizedJob)item).isDisabled() ^ statusFilter)
                items.add(item);
        }

        // check the filters
        Iterable<ViewJobFilter> jobFilters = getJobFilters();
        List<TopLevelItem> allItems = new ArrayList<>(parentItems);
        if (recurse) allItems = expand(allItems, new ArrayList<>());
    	for (ViewJobFilter jobFilter: jobFilters) {
    		items = jobFilter.filter(items, allItems, this);
    	}
        // for sanity, trim off duplicates
        items = new ArrayList<>(new LinkedHashSet<>(items));
        
        return items;
    }
655671
def FindFirst(params, ctxt, scope, stream, coord, interp):
    
    global FIND_MATCHES_ITER
    FIND_MATCHES_ITER = _find_helper(params, ctxt, scope, stream, coord, interp)

    try:
        first = six.next(FIND_MATCHES_ITER)
        return first.start() + FIND_MATCHES_START_OFFSET
    except StopIteration as e:
        return -1
1264145
public final AbstractItem next(long lockID) throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "next", Long.valueOf(lockID));

        final AbstractItemLink lockedMatchingLink = _next(lockID);

        // retrieve the item from the link
        AbstractItem lockedMatchingItem = null;
        if (null != lockedMatchingLink)
        {
            lockedMatchingItem = lockedMatchingLink.getItem();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "next", lockedMatchingItem);
        return lockedMatchingItem;
    }
109624
private MessageProcessorSearchResults matchMessage(MessageItem msg)
                    throws SIDiscriminatorSyntaxException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(
                        tc,
                        "matchMessage",
                        new Object[] { msg });

        //Extract the message from the MessageItem
        JsMessage jsMsg = msg.getMessage();

        //  Match Consumers is only called for PubSub targets.
        TopicAuthorization topicAuth = _messageProcessor.getDiscriminatorAccessChecker();
        MessageProcessorSearchResults searchResults = new MessageProcessorSearchResults(topicAuth);

        // Defect 382250, set the unlockCount from MsgStore into the message
        // in the case where the message is being redelivered.
        int redelCount = msg.guessRedeliveredCount();

        if (redelCount > 0)
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(tc, "Set deliverycount into message: " + redelCount);
            jsMsg.setDeliveryCount(redelCount);
        }

        // Get the matching consumers from the matchspace
        _matchspace.retrieveMatchingOutputHandlers(
                                                   _destination,
                                                   jsMsg.getDiscriminator(),
                                                   (MatchSpaceKey) jsMsg,
                                                   searchResults);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(
                       tc,
                       "matchMessage",
                       new Object[] { searchResults });

        return searchResults;
    }