BemState (@NotNull String className, String elementSeparator, String modifierSeparator) { final BemState result = new BemState(); int indexOfElementSeparator = className.indexOf(elementSeparator); if (indexOfElementSeparator >= 0) { result.setBlock(className.substring(0, indexOfElementSeparator)); result.setElement(className.substring(indexOfElementSeparator + elementSeparator.length())); int lastIndexOfElementSeparator = className.lastIndexOf(elementSeparator); assert lastIndexOfElementSeparator >= 0; int indexOfModifierSeparator = className.indexOf(modifierSeparator, lastIndexOfElementSeparator + elementSeparator.length()); if (indexOfModifierSeparator >= 0) { result.setModifier(className.substring(indexOfModifierSeparator + modifierSeparator.length())); result.setElement(className.substring(indexOfElementSeparator + elementSeparator.length(), indexOfModifierSeparator)); } } else { int indexOfModifierSeparator = className.indexOf(modifierSeparator); if (indexOfModifierSeparator >= 0) { result.setBlock(className.substring(0, indexOfModifierSeparator)); result.setModifier(className.substring(indexOfModifierSeparator + modifierSeparator.length())); } } return result; }