예제 #1
0
  /**
   * Search for a particular filter using a set of known indentification values in the Map of
   * filters.
   *
   * @param filters The filters map that should be searched.
   * @param filterIds The aliases for the target filter to be located.
   * @return the filter if found in the mapping or null if not found.
   */
  public static Map.Entry<Symbol, DescribedType> findFilter(
      Map<Symbol, Object> filters, Object[] filterIds) {

    if (filterIds == null || filterIds.length == 0) {
      StringBuilder ids = new StringBuilder();
      if (filterIds != null) {
        for (Object filterId : filterIds) {
          ids.append(filterId).append(" ");
        }
      }
      throw new IllegalArgumentException("Invalid Filter Ids array passed: " + ids);
    }

    if (filters == null || filters.isEmpty()) {
      return null;
    }

    for (Map.Entry<Symbol, Object> filter : filters.entrySet()) {
      if (filter.getValue() instanceof DescribedType) {
        DescribedType describedType = ((DescribedType) filter.getValue());
        Object descriptor = describedType.getDescriptor();

        for (Object filterId : filterIds) {
          if (descriptor.equals(filterId)) {
            return new AbstractMap.SimpleImmutableEntry<>(filter.getKey(), describedType);
          }
        }
      }
    }

    return null;
  }
예제 #2
0
  public TypeEncoding<DescribedType> getEncoding(final DescribedType val) {
    TypeEncoding underlyingEncoding =
        _encoder.getType(val.getDescribed()).getEncoding(val.getDescribed());
    TypeEncoding encoding = _encodings.get(underlyingEncoding);
    if (encoding == null) {
      encoding = new DynamicDescribedTypeEncoding(underlyingEncoding);
      _encodings.put(underlyingEncoding, encoding);
    }

    return encoding;
  }