Class ProvidenceHelper


  • public class ProvidenceHelper
    extends java.lang.Object
    Convenience methods for handling providence messages.
    • Method Detail

      • getTargetModifications

        public static <M extends PMessage<M,​F>,​F extends PField,​B extends PMessageBuilder<M,​F>> B getTargetModifications​(M source,
                                                                                                                                                 M target)
      • fromJsonResource

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> Message fromJsonResource​(java.lang.String path,
                                                                                                                          PMessageDescriptor<Message,​Field> descriptor)
                                                                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • arrayListFromJsonResource

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> java.util.ArrayList<Message> arrayListFromJsonResource​(java.lang.String path,
                                                                                                                                                        PMessageDescriptor<Message,​Field> descriptor)
                                                                                                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • fromResource

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> Message fromResource​(java.lang.String resource,
                                                                                                                      PMessageDescriptor<Message,​Field> descriptor,
                                                                                                                      Serializer serializer)
                                                                                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • arrayListFromResource

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> java.util.ArrayList<Message> arrayListFromResource​(java.lang.String path,
                                                                                                                                                    PMessageDescriptor<Message,​Field> descriptor,
                                                                                                                                                    Serializer serializer)
                                                                                                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • debugString

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> java.lang.String debugString​(Message message)
        Prints a pretty formatted string that is optimized for diffing (mainly for testing and debugging).
        Type Parameters:
        Message - The message type.
        Field - The message field type.
        Parameters:
        message - The message to stringify.
        Returns:
        The resulting string.
      • parseDebugString

        @Nonnull
        public static <Message extends PMessage<Message,​Field>,​Field extends PField> Message parseDebugString​(java.lang.String string,
                                                                                                                          PMessageDescriptor<Message,​Field> descriptor)
        Parses a pretty formatted string, and makes exceptions unchecked.
        Type Parameters:
        Message - The message type.
        Field - The message field type.
        Parameters:
        string - The message string to parse.
        descriptor - The message descriptor.
        Returns:
        The parsed message.
      • optionalInMessage

        @Nonnull
        public static <T> java.util.Optional<T> optionalInMessage​(PMessage message,
                                                                  PField... fields)
        Get a field value from a message with optional chaining. If the field is not set, or any message in the chain leading up to the last message is missing, it will return an empty optional. Otherwise the leaf field value. Note that this will only check for MESSAGE type if the message is present and needs to be looked up in.
        Type Parameters:
        T - The expected leaf value type.
        Parameters:
        message - The message to start looking up field values in.
        fields - Fields to look up in the message.
        Returns:
        Optional field value.