class Metadata {
  private Metadata() {
    throw new IllegalStateException("Utility class");
  }

  public static Optional<String> getKind(Builder builder) {
    try {
      Method method = builder.getClass().getMethod("getKind");
      Object o = method.invoke(builder);
      if (o instanceof String) {
        return Optional.of((String) o);
      }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
      //ignore
    }
    return Optional.empty();
  }

  public static Optional<ObjectMeta> getMetadata(Builder builder) {
    try {
      Method method = builder.getClass().getMethod("buildMetadata");
      Object o = method.invoke(builder);
      if (o instanceof ObjectMeta) {
        return Optional.of((ObjectMeta) o);
      }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
      //ignore
    }
    return Optional.empty();
  }

  public static boolean addToLabels(Builder builder, String key, String value) {<FILL_FUNCTION_BODY>}

  public static boolean removeFromLabels(Builder builder, String key) {
    try {
      Method editMethod = builder.getClass().getMethod("editOrNewMetadata");
      Object o = editMethod.invoke(builder);
      if (o instanceof ObjectMetaFluent) {
        ObjectMetaFluent fluent = (ObjectMetaFluent) o;
        fluent.removeFromLabels(key);
        Method endMethod = fluent.getClass().getMethod("endMetadata");
        endMethod.invoke(fluent);
        return true;
      }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
      //ignore
    }
    return false;
  }

  /**
   * Create a {@link Predicate} that checks that a resource builder doesn't match the name and kind.
   *
   * @param candidate The specified resource.
   * @return The predicate.
   */
  public static Predicate<VisitableBuilder<? extends HasMetadata, ?>> matching(
      HasMetadata candidate) {
    return matching(candidate.getApiVersion(), candidate.getKind(),
        candidate.getMetadata().getName());
  }

  /**
   * Create a {@link Predicate} that checks that a resource builder doesn't match the name and kind.
   *
   * @param apiVersion the API version the resources must match
   * @param kind The specified kind.
   * @param name The specified name.
   * @return The predicate.
   */
  public static Predicate<VisitableBuilder<? extends HasMetadata, ?>> matching(String apiVersion,
      String kind, String name) {
    return builder -> {
      HasMetadata item = builder.build();
      ObjectMeta metadata = item.getMetadata();
      return apiVersion.equals(item.getApiVersion()) &&
          kind != null && kind.equals(item.getKind()) &&
          name != null && name.equals(metadata.getName());
    };
  }
}

    try {
      Method editMethod = builder.getClass().getMethod("editOrNewMetadata");
      Object o = editMethod.invoke(builder);
      if (o instanceof ObjectMetaFluent) {
        ObjectMetaFluent fluent = (ObjectMetaFluent) o;
        fluent.addToLabels(key, value);
        Method endMethod = fluent.getClass().getMethod("endMetadata");
        endMethod.invoke(fluent);
        return true;
      }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
      //ignore
    }
    return false;
  
<no_super_class>