retrieveTagsInBetweenOf static method

List<String> retrieveTagsInBetweenOf(
  1. List<String> allTags,
  2. String oldTag,
  3. String newTag
)

Given a List that contains all the tags of a component, returns a new List that contains only the tags between the oldTag and the newTag, including the newTag (but not the oldTag).

Implementation

static List<String> retrieveTagsInBetweenOf(
    List<String> allTags, String oldTag, String newTag) {
  int oldTagIndex = allTags.indexOf(oldTag) + 1;
  int newTagIndex = allTags.indexOf(newTag);

  newTagIndex = newTagIndex == -1 ? allTags.length - 1 : newTagIndex;
  // Include the element at [newTagIndex] in the resulting sublist.
  newTagIndex++;

  List<String> inBetweenTags = allTags.sublist(oldTagIndex, newTagIndex);
  return inBetweenTags;
}