Class MapHasher<Type>

java.lang.Object
com.zenith.mc.item.hashing.MapHasher<Type>
Type Parameters:
Type - the type this MapHasher encodes.

public class MapHasher<Type> extends Object
MapHashers are used to encode a Type to a map-like structure, which is then hashed using a MinecraftHashEncoder.

MapHashers store the Type they are encoding, but it isn't directly accessible. Instead, extractor functions are used to extract specific properties of the Type.

  • Method Details

    • acceptConstant

      public <Value> MapHasher<Type> acceptConstant(String key, MinecraftHasher<Value> hasher, Value value)
      Adds a constant Value to the map.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the constant in.
      hasher - the hasher used to hash a Value.
      value - the Value.
    • accept

      public <Value> MapHasher<Type> accept(String key, MinecraftHasher<Value> hasher, Function<Type,Value> extractor)
      Extracts a Value from a Type using the extractor, and adds it to the map.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the Value in.
      hasher - the hasher used to hash a Value.
      extractor - the function that extracts a Value from a Type.
    • accept

      public MapHasher<Type> accept(MapBuilder<Type> builder)
      Applies the MapBuilder to this MapHasher, essentially adding all the keys it defines here.
    • accept

      public <Value> MapHasher<Type> accept(MapBuilder<Value> builder, Function<Type,Value> extractor)
      Extracts a Value from a Type using the extractor, and applies the given MapBuilder for it to this MapHasher, essentially adding the keys it defines here.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      builder - the MapBuilder that encodes a Value.
      extractor - the function that extracts a Value from a Type.
    • accept

      public <Value> MapHasher<Type> accept(Function<Type,Value> extractor, Function<Value, MapBuilder<Type>> builderDispatcher)
      Extracts a Value from a Type using the extractor, then dispatches a MapBuilder from the Value using the builderDispatcher, and applies it to this MapHasher, essentially adding the keys it defines here.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      extractor - the function that extracts a Value from a Type.
      builderDispatcher - the function that dispatches a MapBuilder from a Value.
    • optionalNullable

      public <Value> MapHasher<Type> optionalNullable(String key, MinecraftHasher<Value> hasher, Function<Type,Value> extractor)
      Extracts a Value from a Type using the extractor, and adds it to the map if it is not null.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the Value in.
      hasher - the hasher used to hash a Value.
      extractor - the function that extracts a Value from a Type.
    • optional

      public <Value> MapHasher<Type> optional(String key, MinecraftHasher<Value> hasher, Function<Type, Optional<Value>> extractor)
      Extracts an Optional of a Value from a Type using the extractor, and adds it to the map if it is present.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the Value in.
      hasher - the hasher used to hash a Value.
      extractor - the function that extracts a Value from a Type.
    • optional

      public <Value> MapHasher<Type> optional(String key, MinecraftHasher<Value> hasher, Function<Type,Value> extractor, Value defaultValue)
      Extracts a Value from a Type using the extractor, and adds it to the map if it's not equal to defaultValue.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the Value in.
      hasher - the hasher used to hash a Value.
      extractor - the function that extracts a Value from a Type.
      defaultValue - the default Value. The Value won't be added to the map if it equals the default.
    • acceptList

      public <Value> MapHasher<Type> acceptList(String key, MinecraftHasher<Value> valueHasher, Function<Type, List<Value>> extractor)
      Extracts a list of Values from a Type, and adds it to the map.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the list of Values in.
      valueHasher - the hasher used to hash a single Value.
      extractor - the function that extracts a list of Values from a Type.
    • optionalList

      public <Value> MapHasher<Type> optionalList(String key, MinecraftHasher<Value> valueHasher, Function<Type, List<Value>> extractor)
      Extracts a list of Values from a Type, and adds it to the map if it is not empty.
      Type Parameters:
      Value - the type of the value.
      Parameters:
      key - the key to put the list of Values in.
      valueHasher - the hasher used to hash a single Value.
      extractor - the function that extracts a list of Values from a Type.
    • build

      public com.google.common.hash.HashCode build()