+/*
+ * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
package org.opendaylight.controller.config.yangjmxgenerator.plugin.util;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
+import java.util.List;
+import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
-import java.util.regex.Pattern;
-
public class StringUtil {
- private static final Logger logger = LoggerFactory.getLogger(StringUtils.class);
+ private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class);
/**
* @param list of strings to be joined by ','
return Optional.of(IOUtils.toString(in));
}
} catch (IOException e) {
- logger.warn("Cannot load copyright.txt", e);
+ LOG.warn("Cannot load copyright.txt", e);
}
*/
int basicIndent = 4;
StringBuilder sb = new StringBuilder();
- int intends = 0, empty = 0;
+ int indents = 0, empty = 0;
for (String line : split) {
- intends -= StringUtils.countMatches(line, "}");
- if (intends < 0) {
- intends = 0;
+ indents -= StringUtils.countMatches(line, "}");
+ if (indents < 0) {
+ indents = 0;
}
- if (line.isEmpty() == false) {
- sb.append(Strings.repeat(" ", basicIndent * intends));
+ if (!line.isEmpty()) {
+ sb.append(Strings.repeat(" ", basicIndent * indents));
sb.append(line);
sb.append("\n");
empty = 0;
sb.append("\n");
}
}
- intends += StringUtils.countMatches(line, "{");
+ indents += StringUtils.countMatches(line, "{");
}
return ensureEndsWithSingleNewLine(sb.toString());
}