List of usage examples for com.liferay.portal.kernel.util StringPool PLUS
String PLUS
To view the source code for com.liferay.portal.kernel.util StringPool PLUS.
Click Source Link
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getYldToMaturity(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (i <= 5) { jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.DASH + yldToMaturityRange[i][1]); } else {//from w w w .jav a 2 s . c o m jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.PLUS); } for (int j = 0; j < durationRange.length; j++) { jsonObject.put((int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1], 0.0d); jsonObject.put("index" + j, (i + StringPool.COLON + j)); } jsonArray.put(jsonObject); } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalValueOfBonds = 0.0; while (rs.next()) { double dur_mid = rs.getDouble("dur_mid"); double yld_ytm_bid = rs.getDouble("yld_ytm_bid"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; for (int i = 0; i < yldToMaturityRange.length; i++) { if (yld_ytm_bid > yldToMaturityRange[i][0] && yld_ytm_bid <= yldToMaturityRange[i][1]) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { if (dur_mid > durationRange[j][0] && dur_mid <= durationRange[j][1]) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) + currentMarketValue); } } } } } rs.close(); stmt.close(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) * 100 / totalValueOfBonds); } } // append a summary row JSONObject summary = JSONFactoryUtil.createJSONObject(); summary.put("summary", true); summary.put("yldToMaturityRange", "Total"); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; if (Double.isNaN(summary.getDouble(key))) { summary.put(key, jsonObj.getDouble(key)); } else { summary.put(key, summary.getDouble(key) + jsonObj.getDouble(key)); } } } jsonArray.put(summary); } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.inikah.slayer.model.impl.RelativeImpl.java
License:Open Source License
public String getIdd(String defaultValue) { String idd = StringPool.PLUS; Phone phone = BridgeLocalServiceUtil.getPhone(getRelativeId(), Relative.class.getName(), true); if (Validator.isNotNull(phone)) { idd += phone.getExtension();/* w w w . j a v a 2s . co m*/ } else { idd += defaultValue; } return idd; }
From source file:com.liferay.portlet.wiki.engines.antlrwiki.translator.XhtmlTranslator.java
License:Open Source License
protected String getHeadingMarkup(String prefix, String text) { StringBundler sb = new StringBundler(5); sb.append(_HEADING_ANCHOR_PREFIX);// w w w . ja v a 2 s . c o m sb.append(prefix); sb.append(StringPool.DASH); sb.append(text.trim()); return StringUtil.replace(sb.toString(), StringPool.SPACE, StringPool.PLUS); }
From source file:com.liferay.sync.util.JSONWebServiceActionParametersMap.java
License:Open Source License
@Override public Object put(String key, Object value) { int pos = key.indexOf(CharPool.COLON); if (key.startsWith(StringPool.DASH)) { key = key.substring(1);//from w w w . j a va 2s . c o m value = null; } else if (key.startsWith(StringPool.PLUS)) { key = key.substring(1); String typeName = null; if (pos != -1) { typeName = key.substring(pos); key = key.substring(0, pos - 1); } else { if (value != null) { typeName = value.toString(); value = Void.TYPE; } } if (typeName != null) { if (_parameterTypes == null) { _parameterTypes = new HashMap<>(); } _parameterTypes.put(key, typeName); } if (Validator.isNull(GetterUtil.getString(value))) { value = Void.TYPE; } } else if (pos != -1) { String typeName = key.substring(pos + 1); key = key.substring(0, pos); if (_parameterTypes == null) { _parameterTypes = new HashMap<>(); } _parameterTypes.put(key, typeName); if (Validator.isNull(GetterUtil.getString(value))) { value = Void.TYPE; } } pos = key.indexOf(CharPool.PERIOD); if (pos != -1) { String baseName = key.substring(0, pos); String innerName = key.substring(pos + 1); if (_innerParameters == null) { _innerParameters = new HashMap<>(); } List<NameValue<String, Object>> values = _innerParameters.get(baseName); if (values == null) { values = new ArrayList<>(); _innerParameters.put(baseName, values); } values.add(new NameValue<String, Object>(innerName, value)); return value; } return super.put(key, value); }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected void checkRegexPattern(String regexPattern, String fileName, int lineCount) { int i = regexPattern.indexOf("Pattern.compile("); if (i == -1) { return;//from w w w .j a va 2 s . c o m } regexPattern = regexPattern.substring(i + 16); regexPattern = stripQuotes(regexPattern, CharPool.QUOTE); i = regexPattern.indexOf(StringPool.COMMA); if (i != -1) { regexPattern = regexPattern.substring(0, i); } else { regexPattern = StringUtil.replaceLast(regexPattern, ");", StringPool.BLANK); } regexPattern = StringUtil.replace(regexPattern, StringPool.PLUS, StringPool.BLANK); if (Validator.isNull(regexPattern)) { processErrorMessage(fileName, "create pattern as global var: " + fileName + " " + lineCount); } }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected String formatJava(String fileName, String absolutePath, String content) throws Exception { StringBundler sb = new StringBundler(); try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new UnsyncStringReader(content))) { String line = null;/*from w w w.j a va 2 s. c o m*/ String previousLine = StringPool.BLANK; int lineCount = 0; String ifClause = StringPool.BLANK; String packageName = StringPool.BLANK; String regexPattern = StringPool.BLANK; while ((line = unsyncBufferedReader.readLine()) != null) { lineCount++; line = trimLine(line, false); if (line.startsWith("package ")) { packageName = line.substring(8, line.length() - 1); } if (line.startsWith("import ")) { if (line.endsWith(".*;")) { processErrorMessage(fileName, "import: " + fileName + " " + lineCount); } int pos = line.lastIndexOf(StringPool.PERIOD); if (pos != -1) { String importPackageName = line.substring(7, pos); if (importPackageName.equals(packageName)) { continue; } } } if (line.contains(StringPool.TAB + "for (") && line.contains(":") && !line.contains(" :")) { line = StringUtil.replace(line, ":", " :"); } // LPS-42924 if (line.contains("PortalUtil.getClassNameId(") && fileName.endsWith("ServiceImpl.java")) { processErrorMessage(fileName, "Use classNameLocalService.getClassNameId: " + fileName + " " + lineCount); } // LPS-42599 if (!isExcluded(_hibernateSQLQueryExclusions, absolutePath) && line.contains("= session.createSQLQuery(") && content.contains("com.liferay.portal.kernel.dao.orm.Session")) { line = StringUtil.replace(line, "createSQLQuery", "createSynchronizedSQLQuery"); } line = replacePrimitiveWrapperInstantiation(fileName, line, lineCount); String trimmedLine = StringUtil.trimLeading(line); // LPS-45649 if (trimmedLine.startsWith("throw new IOException(") && line.contains("e.getMessage()")) { line = StringUtil.replace(line, ".getMessage()", StringPool.BLANK); } // LPS-45492 if (trimmedLine.contains("StopWatch stopWatch = null;")) { processErrorMessage(fileName, "Do not set stopwatch to null: " + fileName + " " + lineCount); } checkStringBundler(trimmedLine, fileName, lineCount); checkEmptyCollection(trimmedLine, fileName, lineCount); if (trimmedLine.startsWith("* @deprecated") && _addMissingDeprecationReleaseVersion) { if (!trimmedLine.startsWith("* @deprecated As of ")) { line = StringUtil.replace(line, "* @deprecated", "* @deprecated As of " + getMainReleaseVersion()); } else { String version = trimmedLine.substring(20); version = StringUtil.split(version, StringPool.SPACE)[0]; version = StringUtil.replace(version, StringPool.COMMA, StringPool.BLANK); if (StringUtil.count(version, StringPool.PERIOD) == 1) { line = StringUtil.replaceFirst(line, version, version + ".0"); } } } if (trimmedLine.startsWith("* @see ") && (StringUtil.count(trimmedLine, StringPool.AT) > 1)) { processErrorMessage(fileName, "Do not use @see with another annotation: " + fileName + " " + lineCount); } checkInefficientStringMethods(line, fileName, absolutePath, lineCount); if (trimmedLine.startsWith(StringPool.EQUAL)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (line.contains("ActionForm form")) { processErrorMessage(fileName, "Rename form to actionForm: " + fileName + " " + lineCount); } if (line.contains("ActionMapping mapping")) { processErrorMessage(fileName, "Rename mapping to ActionMapping: " + fileName + " " + lineCount); } if (fileName.contains("/upgrade/") && line.contains("rs.getDate(")) { processErrorMessage(fileName, "Use rs.getTimeStamp: " + fileName + " " + lineCount); } if (!trimmedLine.equals("{") && line.endsWith("{") && !line.endsWith(" {")) { line = StringUtil.replaceLast(line, "{", " {"); } line = sortExceptions(line); if (trimmedLine.startsWith("if (") || trimmedLine.startsWith("else if (") || trimmedLine.startsWith("while (") || Validator.isNotNull(ifClause)) { ifClause = ifClause + line + StringPool.NEW_LINE; if (line.endsWith(") {")) { String newIfClause = checkIfClause(ifClause, fileName, lineCount); if (!ifClause.equals(newIfClause) && content.contains(ifClause)) { return StringUtil.replace(content, ifClause, newIfClause); } ifClause = StringPool.BLANK; } else if (line.endsWith(StringPool.SEMICOLON)) { ifClause = StringPool.BLANK; } } if (trimmedLine.startsWith("Pattern ") || Validator.isNotNull(regexPattern)) { regexPattern = regexPattern + trimmedLine; if (trimmedLine.endsWith(");")) { // LPS-41084 checkRegexPattern(regexPattern, fileName, lineCount); regexPattern = StringPool.BLANK; } } if (!trimmedLine.contains(StringPool.DOUBLE_SLASH) && !trimmedLine.startsWith(StringPool.STAR)) { String strippedQuotesLine = stripQuotes(trimmedLine, CharPool.QUOTE); for (int x = 0;;) { x = strippedQuotesLine.indexOf(StringPool.EQUAL, x + 1); if (x == -1) { break; } char c = strippedQuotesLine.charAt(x - 1); if (Character.isLetterOrDigit(c)) { line = StringUtil.replace(line, c + "=", c + " ="); break; } if (x == (strippedQuotesLine.length() - 1)) { break; } c = strippedQuotesLine.charAt(x + 1); if (Character.isLetterOrDigit(c)) { line = StringUtil.replace(line, "=" + c, "= " + c); break; } } while (trimmedLine.contains(StringPool.TAB)) { line = StringUtil.replaceLast(line, StringPool.TAB, StringPool.SPACE); trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.TAB, StringPool.SPACE); } if (line.contains(StringPool.TAB + StringPool.SPACE) && !previousLine.endsWith("&&") && !previousLine.endsWith("||") && !previousLine.contains(StringPool.TAB + "((") && !previousLine.contains(StringPool.TAB + StringPool.LESS_THAN) && !previousLine.contains(StringPool.TAB + StringPool.SPACE) && !previousLine.contains(StringPool.TAB + "for (") && !previousLine.contains(StringPool.TAB + "implements ") && !previousLine.contains(StringPool.TAB + "throws ")) { line = StringUtil.replace(line, StringPool.TAB + StringPool.SPACE, StringPool.TAB); } while (trimmedLine.contains(StringPool.DOUBLE_SPACE) && !trimmedLine.contains(StringPool.QUOTE + StringPool.DOUBLE_SPACE) && !fileName.contains("Test")) { line = StringUtil.replaceLast(line, StringPool.DOUBLE_SPACE, StringPool.SPACE); trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.DOUBLE_SPACE, StringPool.SPACE); } if (!line.contains(StringPool.QUOTE)) { int pos = line.indexOf(") "); if (pos != -1) { String linePart = line.substring(pos + 2); if (Character.isLetter(linePart.charAt(0)) && !linePart.startsWith("default") && !linePart.startsWith("instanceof") && !linePart.startsWith("throws")) { line = StringUtil.replaceLast(line, StringPool.SPACE + linePart, linePart); } } if ((trimmedLine.startsWith("private ") || trimmedLine.startsWith("protected ") || trimmedLine.startsWith("public ")) && !line.contains(StringPool.EQUAL) && line.contains(" (")) { line = StringUtil.replace(line, " (", "("); } if (line.contains(" [")) { line = StringUtil.replace(line, " [", "["); } for (int x = -1;;) { int posComma = line.indexOf(StringPool.COMMA, x + 1); int posSemicolon = line.indexOf(StringPool.SEMICOLON, x + 1); if ((posComma == -1) && (posSemicolon == -1)) { break; } x = Math.min(posComma, posSemicolon); if (x == -1) { x = Math.max(posComma, posSemicolon); } if (line.length() > (x + 1)) { char nextChar = line.charAt(x + 1); if ((nextChar != CharPool.APOSTROPHE) && (nextChar != CharPool.CLOSE_PARENTHESIS) && (nextChar != CharPool.SPACE) && (nextChar != CharPool.STAR)) { line = StringUtil.insert(line, StringPool.SPACE, x + 1); } } if (x > 0) { char previousChar = line.charAt(x - 1); if (previousChar == CharPool.SPACE) { line = line.substring(0, x - 1).concat(line.substring(x)); } } } } if ((line.contains(" && ") || line.contains(" || ")) && line.endsWith(StringPool.OPEN_PARENTHESIS)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.endsWith(StringPool.PLUS) && !trimmedLine.startsWith(StringPool.OPEN_PARENTHESIS)) { int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS); if (openParenthesisCount > closeParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } int x = strippedQuotesLine.indexOf(", "); if (x != -1) { String linePart = strippedQuotesLine.substring(0, x); int closeParenthesisCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS); if (closeParenthesisCount > openParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } else if (trimmedLine.endsWith(StringPool.COMMA) && !trimmedLine.startsWith("for (")) { int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS); if (closeParenthesisCount < openParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } if (line.contains(StringPool.COMMA) && !line.contains(StringPool.CLOSE_PARENTHESIS) && !line.contains(StringPool.GREATER_THAN) && !line.contains(StringPool.QUOTE) && line.endsWith(StringPool.OPEN_PARENTHESIS)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (line.endsWith(" +") || line.endsWith(" -") || line.endsWith(" *") || line.endsWith(" /")) { x = line.indexOf(" = "); if (x != -1) { int y = line.indexOf(StringPool.QUOTE); if ((y == -1) || (x < y)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } } if (line.endsWith(" throws") || (previousLine.endsWith(StringPool.OPEN_PARENTHESIS) && line.contains(" throws ") && line.endsWith(StringPool.OPEN_CURLY_BRACE))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.startsWith(StringPool.PERIOD) || (line.endsWith(StringPool.PERIOD) && line.contains(StringPool.EQUAL))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && line.endsWith(StringPool.OPEN_CURLY_BRACE)) { Matcher matcher = _lineBreakPattern.matcher(trimmedLine); if (!matcher.find()) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } } if (line.contains(" ") && !line.matches("\\s*\\*.*")) { if (!fileName.endsWith("StringPool.java")) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } } if (line.contains(" {") && !line.matches("\\s*\\*.*")) { processErrorMessage(fileName, "{:" + fileName + " " + lineCount); } int lineLength = getLineLength(line); if (!line.startsWith("import ") && !line.startsWith("package ") && !line.matches("\\s*\\*.*")) { if (fileName.endsWith("Table.java") && line.contains("String TABLE_SQL_CREATE = ")) { } else if (fileName.endsWith("Table.java") && line.contains("String TABLE_SQL_DROP = ")) { } else if (fileName.endsWith("Table.java") && line.contains(" index IX_")) { } else if (lineLength > _MAX_LINE_LENGTH) { if (!isExcluded(_lineLengthExclusions, absolutePath, lineCount) && !isAnnotationParameter(content, trimmedLine)) { String truncateLongLinesContent = getTruncateLongLinesContent(content, line, trimmedLine, lineCount); if (truncateLongLinesContent != null) { return truncateLongLinesContent; } processErrorMessage(fileName, "> 80: " + fileName + " " + lineCount); } } else { int lineLeadingTabCount = getLeadingTabCount(line); int previousLineLeadingTabCount = getLeadingTabCount(previousLine); if (!trimmedLine.startsWith("//")) { if (previousLine.endsWith(StringPool.COMMA) && previousLine.contains(StringPool.OPEN_PARENTHESIS) && !previousLine.contains("for (") && (lineLeadingTabCount > previousLineLeadingTabCount)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if ((lineLeadingTabCount == previousLineLeadingTabCount) && (previousLine.endsWith(StringPool.EQUAL) || previousLine.endsWith(StringPool.OPEN_PARENTHESIS))) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } if (Validator.isNotNull(trimmedLine)) { if (((previousLine.endsWith(StringPool.COLON) && previousLine.contains(StringPool.TAB + "for ")) || (previousLine.endsWith(StringPool.OPEN_PARENTHESIS) && previousLine.contains(StringPool.TAB + "if "))) && ((previousLineLeadingTabCount + 2) != lineLeadingTabCount)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (previousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && ((previousLineLeadingTabCount + 1) != lineLeadingTabCount)) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } } if (previousLine.endsWith(StringPool.PERIOD)) { int x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS); if ((x != -1) && ((getLineLength(previousLine) + x) < _MAX_LINE_LENGTH) && (trimmedLine.endsWith(StringPool.OPEN_PARENTHESIS) || (trimmedLine.charAt(x + 1) != CharPool.CLOSE_PARENTHESIS))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } int diff = lineLeadingTabCount - previousLineLeadingTabCount; if (trimmedLine.startsWith("throws ") && ((diff == 0) || (diff > 1))) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } if ((diff == 2) && (previousLineLeadingTabCount > 0) && line.endsWith(StringPool.SEMICOLON) && !previousLine.contains(StringPool.TAB + "try (")) { line = StringUtil.replaceFirst(line, StringPool.TAB, StringPool.BLANK); } if ((previousLine.contains(" class ") || previousLine.contains(" enum ")) && previousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && Validator.isNotNull(line) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } String combinedLinesContent = getCombinedLinesContent(content, fileName, absolutePath, line, trimmedLine, lineLength, lineCount, previousLine, lineLeadingTabCount, previousLineLeadingTabCount); if (combinedLinesContent != null) { return combinedLinesContent; } } } if (lineCount > 1) { sb.append(previousLine); if (Validator.isNotNull(previousLine) && Validator.isNotNull(trimmedLine) && !previousLine.contains("/*") && !previousLine.endsWith("*/")) { String trimmedPreviousLine = StringUtil.trimLeading(previousLine); if ((trimmedPreviousLine.startsWith("// ") && !trimmedLine.startsWith("// ")) || (!trimmedPreviousLine.startsWith("// ") && trimmedLine.startsWith("// "))) { sb.append("\n"); } else if (!trimmedPreviousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedPreviousLine.endsWith(StringPool.COLON) && (trimmedLine.startsWith("for (") || trimmedLine.startsWith("if ("))) { sb.append("\n"); } else if (previousLine.endsWith(StringPool.TAB + StringPool.CLOSE_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_PARENTHESIS) && !trimmedLine.startsWith(StringPool.DOUBLE_SLASH) && !trimmedLine.equals("*/") && !trimmedLine.startsWith("catch ") && !trimmedLine.startsWith("else ") && !trimmedLine.startsWith("finally ") && !trimmedLine.startsWith("while ")) { sb.append("\n"); } } sb.append("\n"); } previousLine = line; } sb.append(previousLine); } String newContent = sb.toString(); if (newContent.endsWith("\n")) { newContent = newContent.substring(0, newContent.length() - 1); } return newContent; }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected String getCombinedLinesContent(String content, String fileName, String absolutePath, String line, String trimmedLine, int lineLength, int lineCount, String previousLine, int lineTabCount, int previousLineTabCount) { if (Validator.isNull(line) || Validator.isNull(previousLine) || isExcluded(_fitOnSingleLineExclusions, absolutePath, lineCount)) { return null; }// w w w . j a va 2 s . com String trimmedPreviousLine = StringUtil.trimLeading(previousLine); if (line.contains("// ") || line.contains("*/") || line.contains("*/") || previousLine.contains("// ") || previousLine.contains("*/") || previousLine.contains("*/")) { return null; } int tabDiff = lineTabCount - previousLineTabCount; if (previousLine.endsWith(" extends")) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, "extends", tabDiff, false, false, false); } if (previousLine.endsWith(" implements")) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, "implements ", tabDiff, false, false, false); } if (trimmedLine.startsWith("+ ") || trimmedLine.startsWith("- ") || trimmedLine.startsWith("|| ") || trimmedLine.startsWith("&& ")) { int pos = trimmedLine.indexOf(StringPool.SPACE); String linePart = trimmedLine.substring(0, pos); return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, linePart, tabDiff, true, true, false); } int previousLineLength = getLineLength(previousLine); if ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH) { if (trimmedPreviousLine.startsWith("for ") && previousLine.endsWith(StringPool.COLON) && line.endsWith(StringPool.OPEN_CURLY_BRACE)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } if (line.endsWith(StringPool.SEMICOLON) && !previousLine.endsWith(StringPool.COLON) && !previousLine.endsWith(StringPool.OPEN_BRACKET) && !previousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && !previousLine.endsWith(StringPool.OPEN_PARENTHESIS) && !previousLine.endsWith(StringPool.PERIOD) && (lineTabCount == (previousLineTabCount + 1))) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } if ((trimmedPreviousLine.startsWith("if ") || trimmedPreviousLine.startsWith("else ")) && (previousLine.endsWith("||") || previousLine.endsWith("&&")) && line.endsWith(StringPool.OPEN_CURLY_BRACE)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } if ((trimmedLine.startsWith("extends ") || trimmedLine.startsWith("implements ") || trimmedLine.startsWith("throws")) && (line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON)) && (lineTabCount == (previousLineTabCount + 1))) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.OPEN_PARENTHESIS)) { String nextLine = getNextLine(content, lineCount); if (nextLine.endsWith(StringPool.SEMICOLON)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, true); } } } if (((trimmedLine.length() + previousLineLength) <= _MAX_LINE_LENGTH) && (previousLine.endsWith(StringPool.OPEN_BRACKET) || previousLine.endsWith(StringPool.OPEN_PARENTHESIS) || previousLine.endsWith(StringPool.PERIOD)) && line.endsWith(StringPool.SEMICOLON)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, false, false); } if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.SEMICOLON)) { String tempLine = trimmedLine; for (int pos = 0;;) { pos = tempLine.indexOf(StringPool.DASH); if (pos == -1) { pos = tempLine.indexOf(StringPool.PLUS); } if (pos == -1) { pos = tempLine.indexOf(StringPool.SLASH); } if (pos == -1) { pos = tempLine.indexOf(StringPool.STAR); } if (pos == -1) { pos = tempLine.indexOf("||"); } if (pos == -1) { pos = tempLine.indexOf("&&"); } if (pos == -1) { break; } String linePart = tempLine.substring(0, pos); int openParenthesisCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS); int closeParenthesisCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS); if (openParenthesisCount == closeParenthesisCount) { return null; } tempLine = tempLine.substring(0, pos) + tempLine.substring(pos + 1); } int x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS); if (x == 0) { x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS, 1); } if (x != -1) { int y = trimmedLine.indexOf(StringPool.CLOSE_PARENTHESIS, x); int z = trimmedLine.indexOf(StringPool.QUOTE); if (((x + 1) != y) && ((z == -1) || (z > x))) { char previousChar = trimmedLine.charAt(x - 1); if ((previousChar != CharPool.CLOSE_PARENTHESIS) && (previousChar != CharPool.OPEN_PARENTHESIS) && (previousChar != CharPool.SPACE) && (previousLineLength + 1 + x) < _MAX_LINE_LENGTH) { String linePart = trimmedLine.substring(0, x + 1); if (linePart.startsWith(StringPool.OPEN_PARENTHESIS) && !linePart.contains(StringPool.CLOSE_PARENTHESIS)) { return null; } return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, linePart, tabDiff, true, true, false); } } } } if (previousLine.endsWith(StringPool.COMMA) && (previousLineTabCount == lineTabCount) && !previousLine.contains(StringPool.CLOSE_CURLY_BRACE) && (line.endsWith(") {") || !line.endsWith(StringPool.OPEN_CURLY_BRACE))) { int x = trimmedLine.indexOf(StringPool.COMMA); if (x != -1) { while ((previousLineLength + 1 + x) < _MAX_LINE_LENGTH) { String linePart = trimmedLine.substring(0, x + 1); if (isValidJavaParameter(linePart)) { if (trimmedLine.equals(linePart)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } else { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, linePart + StringPool.SPACE, tabDiff, true, true, false); } } String partAfterComma = trimmedLine.substring(x + 1); int pos = partAfterComma.indexOf(StringPool.COMMA); if (pos == -1) { break; } x = x + pos + 1; } } else if (!line.endsWith(StringPool.OPEN_PARENTHESIS) && !line.endsWith(StringPool.PLUS) && !line.endsWith(StringPool.PERIOD) && (!trimmedLine.startsWith("new ") || !line.endsWith(StringPool.OPEN_CURLY_BRACE)) && ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, true, false); } } if (!previousLine.endsWith(StringPool.OPEN_PARENTHESIS)) { return null; } if (StringUtil.count(previousLine, StringPool.OPEN_PARENTHESIS) > 1) { int pos = trimmedPreviousLine.lastIndexOf(StringPool.OPEN_PARENTHESIS, trimmedPreviousLine.length() - 2); if ((pos > 0) && Character.isLetterOrDigit(trimmedPreviousLine.charAt(pos - 1))) { String filePart = trimmedPreviousLine.substring(pos + 1); if (!filePart.contains(StringPool.CLOSE_PARENTHESIS) && !filePart.contains(StringPool.QUOTE)) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, filePart, tabDiff, false, false, false); } } } if ((trimmedLine.length() + previousLineLength) > _MAX_LINE_LENGTH) { return null; } if (line.endsWith(StringPool.COMMA)) { String strippedQuotesLine = stripQuotes(trimmedLine, CharPool.QUOTE); int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS); int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS); if (closeParenthesisCount > openParenthesisCount) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, false, false); } } if (((line.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedLine.startsWith("new ")) || line.endsWith(StringPool.CLOSE_PARENTHESIS)) && (trimmedPreviousLine.startsWith("else ") || trimmedPreviousLine.startsWith("if ") || trimmedPreviousLine.startsWith("private ") || trimmedPreviousLine.startsWith("protected ") || trimmedPreviousLine.startsWith("public "))) { return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount, previousLine, null, tabDiff, false, false, false); } return null; }
From source file:org.rsc.liferay.solr.SolrIndexSearcher.java
License:Open Source License
protected SolrQuery translateQuery(long companyId, Query query, Sort[] sorts, int start, int end) throws Exception { QueryConfig queryConfig = query.getQueryConfig(); SolrQuery solrQuery = new SolrQuery(); if (queryConfig.isHighlightEnabled()) { solrQuery.setHighlight(true);//from w ww . j av a 2 s .c om solrQuery.setHighlightFragsize(queryConfig.getHighlightFragmentSize()); solrQuery.setHighlightSnippets(queryConfig.getHighlightSnippetSize()); String localizedContentName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.CONTENT); String localizedTitleName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.TITLE); solrQuery.setParam("hl.fl", Field.CONTENT, localizedContentName, Field.TITLE, localizedTitleName); } solrQuery.setIncludeScore(queryConfig.isScoreEnabled()); QueryTranslatorUtil.translateForSolr(query); String queryString = query.toString(); StringBundler sb = new StringBundler(6); sb.append(queryString); sb.append(StringPool.SPACE); sb.append(StringPool.PLUS); sb.append(Field.COMPANY_ID); sb.append(StringPool.COLON); sb.append(companyId); solrQuery.setQuery(sb.toString()); if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS)) { solrQuery.setRows(0); } else { solrQuery.setRows(end - start); solrQuery.setStart(start); } if (sorts != null) { for (Sort sort : sorts) { if (sort == null) { continue; } String sortFieldName = sort.getFieldName(); if (DocumentImpl.isSortableTextField(sortFieldName)) { sortFieldName = DocumentImpl.getSortableFieldName(sortFieldName); } ORDER order = ORDER.asc; if (Validator.isNull(sortFieldName) || !sortFieldName.endsWith("sortable")) { sortFieldName = "score"; order = ORDER.desc; } if (sort.isReverse()) { order = ORDER.desc; } solrQuery.addSort(new SortClause(sortFieldName, order)); } } return solrQuery; }
From source file:org.rsc.liferay.solr.SolrIndexWriter.java
License:Open Source License
@Override public void deletePortletDocuments(SearchContext searchContext, String portletId) throws SearchException { try {//w w w . j ava 2s.co m long companyId = searchContext.getCompanyId(); StringBundler sb = null; if (companyId > 0) { sb = new StringBundler(9); sb.append(StringPool.PLUS); sb.append(Field.COMPANY_ID); sb.append(StringPool.COLON); sb.append(companyId); sb.append(StringPool.SPACE); } if (sb == null) { sb = new StringBundler(4); } sb.append(StringPool.PLUS); sb.append(Field.PORTLET_ID); sb.append(StringPool.COLON); sb.append(portletId); _solrServer.deleteByQuery(sb.toString()); if (_commit) { _solrServer.commit(); } } catch (Exception e) { _log.error(e, e); throw new SearchException(e.getMessage()); } }
From source file:org.rsc.liferay.solr.SolrSpellCheckIndexWriter.java
License:Open Source License
protected void addQuerySeparator(StringBundler sb) { sb.append(StringPool.SPACE); sb.append(StringPool.PLUS); }