-
public class SequenceUtilsSodrul 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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intMAX_VALID_SEQUENCEpublic final static intMIN_VALID_SEQUENCE
-
Method Summary
Modifier and Type Method Description static booleanisSequenceInvalid(int sequenceNumber)Check if the given sequence number is invalid. static intdistance2(int source, int destination)static intdistance(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 intlatestSequence(int a, int b)static intpreviousSequence(int currentSequence)Calculates the possible previous sequence of given current sequence static intnextSequence(int currentSequence)Calculates the possible next sequence of given current sequence static intnextSequencePlusN(int currentSequence, int n)Calculates the possible sequence + n of given current sequence static intcompareMin(int a, int b)static intcompareMax(int a, int b)-
-
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 sequencedestination- 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 sequencedestination- is recently got sequence
-
latestSequence
static int latestSequence(int a, int b)
- Parameters:
a- is previously got sequenceb- 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 sequenceb- is 2nd sequence
-
compareMax
static int compareMax(int a, int b)
- Parameters:
a- is 1st sequenceb- is 2nd sequence
-
-
-
-