Package 

Class SequenceUtils


  • 
    public class SequenceUtils
    
                        

    Sodrul Amin Shaon ** Md. Nafiul Alam Fuji ** Reve Systems ** 2022 Lets say we have sequence starting from 1 and highest valid sequence is 10 , then the sequence will be 1, 2, ... 7, 8, 9, 10, 1 ... and so on. We have to implement simple functions so that we can easily get distance, latestSequence and others from simple input of sequence numbers.

    • Method Summary

      Modifier and Type Method Description
      static boolean isSequenceInvalid(int sequenceNumber) Check if the given sequence number is invalid.
      static int distance2(int source, int destination)
      static int distance(int source, int destination) Determines if it has the shortest path to go from source to destination or from destination to source.If less steps required to go from source to destination then distance is positive.
      static int latestSequence(int a, int b)
      static int previousSequence(int currentSequence) Calculates the possible previous sequence of given current sequence
      static int nextSequence(int currentSequence) Calculates the possible next sequence of given current sequence
      static int nextSequencePlusN(int currentSequence, int n) Calculates the possible sequence + n of given current sequence
      static int compareMin(int a, int b)
      static int compareMax(int a, int b)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isSequenceInvalid

         static boolean isSequenceInvalid(int sequenceNumber)

        Check if the given sequence number is invalid.

        Parameters:
        sequenceNumber - sequence number to be checked for validation.
      • distance2

        @Deprecated() static int distance2(int source, int destination)
        Parameters:
        source - is previously got sequence
        destination - is recently got sequence
      • distance

         static int distance(int source, int destination)

        Determines if it has the shortest path to go from source to destination or from destination to source.If less steps required to go from source to destination then distance is positive. otherwise, negative.Let's say Max sequence is 100, source is 51 and destination is 0. distance will be 49.source is 50 and destination is 0. distance will be 50.source is 49 and destination is 0. distance will be -49.

        Parameters:
        source - is previously got sequence
        destination - is recently got sequence
      • latestSequence

         static int latestSequence(int a, int b)
        Parameters:
        a - is previously got sequence
        b - is recently got sequence
      • previousSequence

         static int previousSequence(int currentSequence)

        Calculates the possible previous sequence of given current sequence

        Parameters:
        currentSequence - The value of current sequence, for which previous sequence need to be calculated.
      • nextSequence

         static int nextSequence(int currentSequence)

        Calculates the possible next sequence of given current sequence

        Parameters:
        currentSequence - recently got sequence
      • nextSequencePlusN

         static int nextSequencePlusN(int currentSequence, int n)

        Calculates the possible sequence + n of given current sequence

        Parameters:
        currentSequence - recently got sequence
      • compareMin

         static int compareMin(int a, int b)
        Parameters:
        a - is 1st sequence
        b - is 2nd sequence
      • compareMax

         static int compareMax(int a, int b)
        Parameters:
        a - is 1st sequence
        b - is 2nd sequence