import java.util.StringTokenizer; class IndexParser { static final String ALL = "tudo"; static final String DOT = "."; private int index = 0; private String word = ""; private String type = null; IndexParser(String w, int i) { index = i; word = w; } IndexParser(String str) { StringTokenizer tok = new StringTokenizer(str, DOT); word = tok.nextToken(); if (ALL.equals(word)) { if (tok.hasMoreTokens()) { word = tok.nextToken(); if (tok.hasMoreTokens()) type = tok.nextToken(); } } else { try { index = Integer.parseInt(word); if (tok.hasMoreTokens()) { word = tok.nextToken(); if (tok.hasMoreTokens()) type = tok.nextToken(); } else word = ""; } catch(NumberFormatException e) { index = 1; if (tok.hasMoreTokens()) type = tok.nextToken(); } } } boolean isAll() { return index == 0; } boolean hasType() { return type != null; } String getWord() { return word; } int getIndex() { return index; } String getType() { return type; } }