Interface Convertible

All Known Subinterfaces:
FixedFluidInv, FixedFluidInvView, FixedItemInv, FixedItemInv.CopyingFixedItemInv, FixedItemInv.ModifiableFixedItemInv, FixedItemInvView, LimitedFixedFluidInv, LimitedFixedItemInv
All Known Implementing Classes:
AbstractPartialFixedFluidInvView, AbstractPartialFixedItemInvView, CombinedFixedFluidInv, CombinedFixedFluidInvView, CombinedFixedItemInv, CombinedFixedItemInv.OfCopying, CombinedFixedItemInv.OfModifiable, CombinedFixedItemInvView, DelegatingFixedFluidInv, DelegatingFixedItemInv, DelegatingFixedItemInv.OfCopying, DelegatingFixedItemInv.OfModifiable, DirectFixedItemInv, EmptyFixedFluidInv, EmptyFixedItemInv, FixedInvEmiItemInv, FixedInventoryVanillaWrapper, FixedInventoryViewVanillaWrapper, FixedSidedInventoryVanillaWrapper, FullFixedItemInv, JumboFixedFluidInv, MappedFixedFluidInv, MappedFixedFluidInvView, MappedFixedItemInv, MappedFixedItemInv.OfCopying, MappedFixedItemInv.OfModifiable, MappedFixedItemInvView, SimpleFixedFluidInv, SimpleFixedItemInv, SimpleLimitedFixedFluidInv, SimpleLimitedFixedItemInv, SimpleLimitedFixedItemInv.OfCopying, SimpleLimitedFixedItemInv.OfModifiable, SlotFixedItemInv, SubFixedFluidInv, SubFixedFluidInvView, SubFixedItemInv, SubFixedItemInv.OfCopying, SubFixedItemInv.OfModifiable, SubFixedItemInvView

public interface Convertible
Simple interface for converting this object into another Class. It is always a good idea to check to see if this object is an instance of the desired class before calling convertTo(Class), because it is not required that it return itself.
  • Method Summary

    Modifier and Type Method Description
    <T> T convertTo​(java.lang.Class<T> otherType)
    Attempts to provide a variant of this in the given class form.
    static <T> T getAs​(java.lang.Object obj, java.lang.Class<T> clazz)
    Helper method for testing if the object is already an instance of the given class (if so returning it immediately), or if it is an instance of Convertible (if so returning convertTo(Class)), otherwise returning null.
    static <T> T offer​(java.lang.Class<T> clazz, java.lang.Object obj)
    A helper method for convertTo(Class) to quickly write implementations that only return a single other object
    static <T> T offer​(java.lang.Class<T> clazz, java.lang.Object... objects)
    A helper method for convertTo(Class) to quickly write implementations that return any of a few predefined objects.
  • Method Details

    • convertTo

      @Nullable <T> T convertTo​(java.lang.Class<T> otherType)
      Attempts to provide a variant of this in the given class form. This does not have to return "this" object if this is already an instance of the given class.

      Note: In order to be typesafe (and prevent crashes) it is recommended that you return Class.cast(Object) with the object you wish to return rather than just blindly cast to "T".

    • offer

      @Nullable static <T> T offer​(java.lang.Class<T> clazz, java.lang.Object obj)
      A helper method for convertTo(Class) to quickly write implementations that only return a single other object
    • offer

      @Nullable static <T> T offer​(java.lang.Class<T> clazz, java.lang.Object... objects)
      A helper method for convertTo(Class) to quickly write implementations that return any of a few predefined objects.
    • getAs

      @Nullable static <T> T getAs​(java.lang.Object obj, java.lang.Class<T> clazz)
      Helper method for testing if the object is already an instance of the given class (if so returning it immediately), or if it is an instance of Convertible (if so returning convertTo(Class)), otherwise returning null.