Here you can find the source of getClasses(String input)
Parameter | Description |
---|---|
input | The tag to get the classes out of. |
public static List<String> getClasses(String input)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//ww w .j ava2 s . co m * @param input * The tag to get the classes out of. * @return An empty list if there is no class name in the tag name, otherwise the classes. */ public static List<String> getClasses(String input) { if (!input.contains(".")) return Collections.emptyList(); // check to see if it even has a dot ArrayList<String> classes = new ArrayList<>(); // keep searching for new classes while (input.contains(".")) { input = input.substring(input.indexOf('.') + 1); // trim down the string // slightly less annoying to just do it down here than in every branch up there classes.add("." + input.substring(0, endOfType(input))); } return Collections.unmodifiableList(classes); } /** * Finds where the type ends (i.e. a . or # appears and ends the current element) * * @param input * The input to process. * @return Where the closest # or . is or the end of line. */ private static int endOfType(String input) { int nextClass = input.indexOf('.'); // find the next class int nextID = input.indexOf('#'); // find the next id int nextInstructor = input.indexOf('&'); // find the next instructor // we're done with this loop, none were found if (nextClass == -1 && nextID == -1 && nextInstructor == -1) { return input.length(); } // invalidate all of these so that min() returns the closest one if (nextClass == -1) nextClass = Integer.MAX_VALUE; if (nextID == -1) nextID = Integer.MAX_VALUE; if (nextInstructor == -1) nextInstructor = Integer.MAX_VALUE; // return the index closest to the beginning return Math.min(nextClass, Math.min(nextID, nextInstructor)); } }