class PointSelector implements DistinctMarketDataSelector {

  @Override
  public DistinctMarketDataSelector findMatchingSelector(ValueSpecification valueSpecification,
                                                         String calcConfigName,
                                                         final SelectorResolver resolver) {
    if (_calcConfigNames != null && !_calcConfigNames.contains(calcConfigName)) {
      return null;
    }
    if (!MarketDataRequirementNames.MARKET_VALUE.equals(valueSpecification.getValueName())) {
      return null;
    }
    ExternalIdBundle specificationIdBundle = createIds(valueSpecification);
    Set<ExternalId> specificationIds = new HashSet<>(specificationIdBundle.getExternalIds());
    if (_ids != null) {
      specificationIds.retainAll(_ids);
      if (specificationIds.isEmpty()) {
        return null;
      }
    }
    
    if (_idMatchScheme != null && _idMatchPattern != null) {
      if (FluentIterable.from(specificationIds).allMatch(new Predicate<ExternalId>() {
        @Override
        public boolean apply(ExternalId externalId) {
          return !_idMatchScheme.equals(externalId.getScheme());
        }
      })) {
        return null;
      }
      if (FluentIterable.from(specificationIds).allMatch(new Predicate<ExternalId>() {
        @Override
        public boolean apply(ExternalId externalId) {
          return !_idMatchPattern.getPattern().matcher(externalId.getValue()).matches();
        }
      })) {
        return null;
      }
    }
    if (_idLikeScheme != null && _idLikePattern != null) {
      if (FluentIterable.from(specificationIds).allMatch(new Predicate<ExternalId>() {
        @Override
        public boolean apply(ExternalId externalId) {
          return !_idLikeScheme.equals(externalId.getScheme());
        }
      })) {
        return null;
      }
      if (FluentIterable.from(specificationIds).allMatch(new Predicate<ExternalId>() {
        @Override
        public boolean apply(ExternalId externalId) {
          return !_idLikePattern.getPattern().matcher(externalId.getValue()).matches();
        }
      })) {
        return null;
      }
    }
    if (_securityTypes != null) {
      if (FluentIterable.from(specificationIds).allMatch(new Predicate<ExternalId>() {
        @Override
        public boolean apply(ExternalId externalId) {
          Security security = resolver.resolveSecurity(externalId);
          return !_securityTypes.contains(security.getSecurityType().toLowerCase());
        }
      })) {
        return null;
      }
    }
    return this;
  }

    PointSelector(Set<String> calcConfigNames,
                              Set<ExternalId> ids,
                              ExternalScheme idMatchScheme,
                              Pattern idMatchPattern,
                              ExternalScheme idLikeScheme,
                              Pattern idLikePattern,
                              Set<String> securityTypes);

}