CPD Results

The following document contains the results of PMD's CPD 6.55.0.

Duplications

File Line
gov/nist/secauto/oscal/lib/profile/resolver/alter/AddVisitor.java 63
gov/nist/secauto/oscal/lib/profile/resolver/alter/RemoveVisitor.java 61
PARAM("param", Parameter.class),
    PART("part", ControlPart.class);

    @NonNull
    private static final Map<Class<?>, TargetType> CLASS_TO_TYPE;
    @NonNull
    private static final Map<String, TargetType> NAME_TO_TYPE;
    @NonNull
    private final String fieldName;
    @NonNull
    private final Class<?> clazz;

    static {
      {
        Map<Class<?>, TargetType> map = new ConcurrentHashMap<>();
        for (TargetType type : TargetType.values()) {
          map.put(type.getClazz(), type);
        }
        CLASS_TO_TYPE = CollectionUtil.unmodifiableMap(map);
      }

      {
        Map<String, TargetType> map = new ConcurrentHashMap<>();
        for (TargetType type : TargetType.values()) {
          map.put(type.fieldName(), type);
        }
        NAME_TO_TYPE = CollectionUtil.unmodifiableMap(map);
      }
    }

    /**
     * Get the target type associated with the provided {@code clazz}.
     *
     * @param clazz
     *          the class to identify the target type for
     * @return the associated target type or {@code null} if the class is not
     *         associated with a target type
     */
    @Nullable
    public static TargetType forClass(@NonNull Class<?> clazz) {
      Class<?> target = clazz;
      TargetType retval;
      // recurse over parent classes to find a match
      do {
        retval = CLASS_TO_TYPE.get(target);
      } while (retval == null && (target = target.getSuperclass()) != null);
      return retval;
    }

    /**
     * Get the target type associated with the provided field {@code name}.
     *
     * @param name
     *          the field name to identify the target type for
     * @return the associated target type or {@code null} if the name is not
     *         associated with a target type
     */
    @Nullable
    public static TargetType forFieldName(@Nullable String name) {
      return name == null ? null : NAME_TO_TYPE.get(name);
    }

    TargetType(@NonNull String fieldName, @NonNull Class<?> clazz) {
      this.fieldName = fieldName;
      this.clazz = clazz;
    }

    /**
     * Get the field name associated with the target type.
     *
     * @return the name
     */
    public String fieldName() {
      return fieldName;
    }

    /**
     * Get the bound class associated with the target type.
     *
     * @return the class
     */
    public Class<?> getClazz() {
      return clazz;
    }
  }
File Line
gov/nist/secauto/oscal/lib/model/control/catalog/AbstractCatalogGroup.java 49
gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java 72
@NonNull
  @Override
  public Stream<String> getReferencedParameterIds() {

    // get parameters referenced by the group's parts
    Stream<String> insertIds = CollectionUtil.listOrEmpty(getParts()).stream()
        // Get the full part hierarchy
        .flatMap(part -> Stream.concat(Stream.of(part), part.getPartsRecursively()))
        // Get the inserts for each part
        .flatMap(part -> part.getInserts(insert -> "param".equals(insert.getType().toString())))
        // Get the param ids for each insert
        .map(insert -> insert.getIdReference().toString())
        .flatMap(ObjectUtils::filterNull);

    // get parameters referenced by the control's parameters
    Stream<String> parameterIds = CollectionUtil.listOrEmpty(getParams()).stream()
        .flatMap(ObjectUtils::filterNull)
        .flatMap(param -> param.getParameterReferences());

    return ObjectUtils.notNull(
        Stream.concat(insertIds, parameterIds).distinct());
  }

  @NonNull
  public static Builder builder(@NonNull String id) {
    return new Builder(id);
  }

  public static class Builder {
    @NonNull
    private final String id;

    private String clazz;
    private MarkupLine title;
    private final List<Parameter> params = new LinkedList<>();
    private final List<Property> props = new LinkedList<>();
    private final List<Link> links = new LinkedList<>();
    private final List<ControlPart> parts = new LinkedList<>();
    private final List<CatalogGroup> groups = new LinkedList<>();
File Line
gov/nist/secauto/oscal/lib/model/control/catalog/AbstractCatalogGroup.java 150
gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java 166
CatalogGroup retval = new CatalogGroup();
      retval.setId(id);

      if (title == null) {
        throw new IllegalStateException("a title must be provided");
      }
      retval.setTitle(title);

      if (clazz != null) {
        retval.setClazz(clazz);
      }
      if (!params.isEmpty()) {
        retval.setParams(params);
      }
      if (!props.isEmpty()) {
        retval.setProps(props);
      }
      if (!links.isEmpty()) {
        retval.setLinks(links);
      }
      if (!parts.isEmpty()) {
        retval.setParts(parts);
      }
      if (!controls.isEmpty()) {