Skip to content

Commit

Permalink
G2-1659 castIfInstanceOptional
Browse files Browse the repository at this point in the history
  • Loading branch information
gdgib committed Oct 8, 2024
1 parent 1b15563 commit f06d923
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.g2forge.alexandria.java.type;

import java.util.Optional;
import java.util.stream.Stream;

import com.g2forge.alexandria.annotations.note.Note;
Expand All @@ -14,6 +15,11 @@ public default Stream<T> castIfInstance(Object value) {
return Stream.of(cast(value));
}

public default Optional<T> castIfInstanceOptional(Object value) {
if (!isInstance(value)) return Optional.empty();
return Optional.of(cast(value));
}

@Note(type = NoteType.TODO, value = "All implementations of this method need to be implemented in a generic-safe manner")
public default boolean isAssignableFrom(IDynamicType<?> type) {
throw new NotYetImplementedError();
Expand Down

0 comments on commit f06d923

Please sign in to comment.