<T> T resolve(String name, Map<String, T> map) { if (name.startsWith(".")) { // If name starts with a '.', the rest of it is fully qualified. T result = map.get(name.substring(1)); if (result != null) return result; } else { // We've got a name suffix, like 'Person' or 'protos.Person'. Start the search from with the // longest prefix like foo.bar.Baz.Quux, shortening the prefix until we find a match. String prefix = resolveContext(); while (!prefix.isEmpty()) { T result = map.get(prefix + '.' + name); if (result != null) return result; // Strip the last nested class name or package name from the end and try again. int dot = prefix.lastIndexOf('.'); prefix = dot != -1 ? prefix.substring(0, dot) : ""; } T result = map.get(name); if (result != null) return result; } return null; }
<T> T resolve(String name, Map<String, T> map) { if (name.startsWith(".")) { // If name starts with a '.', the rest of it is fully qualified. T result = map.get(name.substring(1)); if (result != null) return result; } else { // We've got a name suffix, like 'Person' or 'protos.Person'. Start the search from with the // longest prefix like foo.bar.Baz.Quux, shortening the prefix until we find a match. String prefix = resolveContext(); while (!prefix.isEmpty()) { T result = map.get(prefix + '.' + name); if (result != null) return result; // Strip the last nested class name or package name from the end and try again. int dot = prefix.lastIndexOf('.'); prefix = dot != -1 ? prefix.substring(0, dot) : ""; } T result = map.get(name); if (result != null) return result; } return null; }
<T> T resolve(String name, Map<String, T> map) { if (name.startsWith(".")) { // If name starts with a '.', the rest of it is fully qualified. T result = map.get(name.substring(1)); if (result != null) return result; } else { // We've got a name suffix, like 'Person' or 'protos.Person'. Start the search from with the // longest prefix like foo.bar.Baz.Quux, shortening the prefix until we find a match. String prefix = resolveContext(); while (!prefix.isEmpty()) { T result = map.get(prefix + '.' + name); if (result != null) return result; // Strip the last nested class name or package name from the end and try again. int dot = prefix.lastIndexOf('.'); prefix = dot != -1 ? prefix.substring(0, dot) : ""; } T result = map.get(name); if (result != null) return result; } return null; }