IndexName implements Comparable<IndexName> { public static IndexName parse(final String nodeName) { String baseName = nodeName; int index = baseName.lastIndexOf('-'); if (index < 0) { return new IndexName(nodeName, true); } String last = baseName.substring(index + 1); baseName = baseName.substring(0, index); try { int v1 = Integer.parseInt(last); if (!baseName.endsWith("-custom")) { return new IndexName(nodeName, baseName, v1, 0); } baseName = baseName.substring(0, baseName.length() - "-custom".length()); index = baseName.lastIndexOf('-'); if (index < 0) { return new IndexName(nodeName, baseName, 0, v1); } last = baseName.substring(index + 1); baseName = baseName.substring(0, index); int v2 = Integer.parseInt(last); return new IndexName(nodeName, baseName, v2, v1); } catch (NumberFormatException e) { long now = System.currentTimeMillis(); if (nextLogWarnClear < now) { LOGGED_WARN.clear(); nextLogWarnClear = now + 5 * 60 * 1000; } if (LOGGED_WARN.add(nodeName)) { LOG.warn("Index name format error: " + nodeName); } return new IndexName(nodeName, false); } } private  IndexName(String nodeName, boolean isLegal); private  IndexName(String nodeName, String baseName, int productVersion, int customerVersion); static IndexName parse(final String nodeName); String toString(); @Override int compareTo(IndexName o); IndexName getLatestCustomized(List<IndexName> all); IndexName getLatestProduct(List<IndexName> all); static Collection<String> filterReplacedIndexes(Collection<String> indexPaths, NodeState rootState); String nextCustomizedName(); String getNodeName(); int getCustomerVersion(); int getProductVersion(); String getBaseName(); boolean isVersioned(); boolean isLegal();  }
@Test public void parse() { assertEquals("/lucene base=/lucene product=0 custom=0", IndexName.parse("/lucene").toString()); assertEquals("/lucene-1 base=/lucene versioned product=1 custom=0", IndexName.parse("/lucene-1").toString()); assertEquals("/lucene-2 base=/lucene versioned product=2 custom=0", IndexName.parse("/lucene-2").toString()); assertEquals("/lucene-custom-3 base=/lucene versioned product=0 custom=3", IndexName.parse("/lucene-custom-3").toString()); assertEquals("/lucene-4-custom-5 base=/lucene versioned product=4 custom=5", IndexName.parse("/lucene-4-custom-5").toString()); assertEquals("/lucene-12-custom-34 base=/lucene versioned product=12 custom=34", IndexName.parse("/lucene-12-custom-34").toString()); assertEquals("/lucene-abc base=/lucene-abc product=0 custom=0 illegal", IndexName.parse("/lucene-abc").toString()); assertEquals("/lucene-abc-custom-2 base=/lucene-abc-custom-2 product=0 custom=0 illegal", IndexName.parse("/lucene-abc-custom-2").toString()); }