protected String getResult() { return result.length() != 0 ? result.substring(1) : ""; } }
private void removeFirstEmptyLine() { int len = NL.length(); if (buf.substring(0, len).equals(NL)) { buf.delete(0, len); } }
/** * @param addr byte array of a MAC address. * @return hex formatted MAC address. */ public static String formatAddress(byte[] addr) { StringBuilder buf = new StringBuilder(24); for (byte b: addr) { buf.append(String.format("%02x:", b & 0xff)); } return buf.substring(0, buf.length() - 1); }
/** * Creates a new ephemeral port based on the ID of the specified channel. * Note that we prepend an upper-case character so that it never conflicts with * the addresses created by a user, which are always lower-cased on construction time. */ LocalAddress(Channel channel) { StringBuilder buf = new StringBuilder(16); buf.append("local:E"); buf.append(Long.toHexString(channel.hashCode() & 0xFFFFFFFFL | 0x100000000L)); buf.setCharAt(7, ':'); id = buf.substring(6); strVal = buf.toString(); }
/** * @param addr byte array of a MAC address. * @return hex formatted MAC address. */ public static String formatAddress(byte[] addr) { StringBuilder buf = new StringBuilder(24); for (byte b: addr) { buf.append(String.format("%02x:", b & 0xff)); } return buf.substring(0, buf.length() - 1); }
private boolean regionMatch(final StringBuilder string, final int index, final String test) { boolean matches = false; if( index >= 0 && index + test.length() - 1 < string.length() ) { final String substring = string.substring( index, index + test.length()); matches = substring.equals( test ); } return matches; }
private CodeBlock generateSeeMethodJavadocInternal( TypeName nameOfClassContainingMethod, String methodName, List<Object> safeParameterNames) { StringBuilder javadocString = new StringBuilder("@see $T#$L("); List<Object> javadocArgs = new ArrayList<>(); javadocArgs.add(nameOfClassContainingMethod); javadocArgs.add(methodName); for (Object param : safeParameterNames) { javadocString.append("$T, "); javadocArgs.add(param); } if (javadocArgs.size() > 2) { javadocString = new StringBuilder(javadocString.substring(0, javadocString.length() - 2)); } javadocString.append(")\n"); return CodeBlock.of(javadocString.toString(), javadocArgs.toArray(new Object[0])); }
/** * Creates a new ephemeral port based on the ID of the specified channel. * Note that we prepend an upper-case character so that it never conflicts with * the addresses created by a user, which are always lower-cased on construction time. */ LocalAddress(Channel channel) { StringBuilder buf = new StringBuilder(16); buf.append("local:E"); buf.append(Long.toHexString(channel.hashCode() & 0xFFFFFFFFL | 0x100000000L)); buf.setCharAt(7, ':'); id = buf.substring(6); strVal = buf.toString(); }
/** * Joins Strings with EOL character * * @param start the starting String * @param linePrefix the prefix for each line to be joined * @param lines collection to join */ public static String join(String start, String linePrefix, Collection<?> lines) { if (lines.isEmpty()) { return ""; } StringBuilder out = new StringBuilder(start); for (Object line : lines) { out.append(linePrefix).append(line).append("\n"); } return out.substring(0, out.length() - 1); //lose last EOL }
/** * Append the query string of the current request to the target redirect URL. * @param targetUrl the StringBuilder to append the properties to * @param request the current request * @since 4.1 */ protected void appendCurrentQueryParams(StringBuilder targetUrl, HttpServletRequest request) { String query = request.getQueryString(); if (StringUtils.hasText(query)) { // Extract anchor fragment, if any. String fragment = null; int anchorIndex = targetUrl.indexOf("#"); if (anchorIndex > -1) { fragment = targetUrl.substring(anchorIndex); targetUrl.delete(anchorIndex, targetUrl.length()); } if (targetUrl.toString().indexOf('?') < 0) { targetUrl.append('?').append(query); } else { targetUrl.append('&').append(query); } // Append anchor fragment, if any, to end of URL. if (fragment != null) { targetUrl.append(fragment); } } }
private StringBuilder createNewOptionAndCall(boolean memoize, MethodSpec.Builder methodSpecBuilder, String start, List<ParameterSpec> specs) { StringBuilder createNewOptionAndCall = new StringBuilder(start); if (!specs.isEmpty()) { methodSpecBuilder.addParameters(specs); for (ParameterSpec parameter : specs) { createNewOptionAndCall.append(parameter.name); // use the Application Context to avoid memory leaks. if (memoize && isAndroidContext(parameter)) { createNewOptionAndCall.append(".getApplicationContext()"); } createNewOptionAndCall.append(", "); } createNewOptionAndCall = new StringBuilder( createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2)); } createNewOptionAndCall.append(")"); return createNewOptionAndCall; }
private static String mergeLeavesIntoCollocatedString(Tree[] trees) { StringBuilder sb = new StringBuilder(160); for (Tree t: trees) { ArrayList<TaggedWord> sent = t.taggedYield(); for (TaggedWord aSent : sent) { sb.append(aSent.word()).append('_'); } } return sb.substring(0,sb.length() -1); }
public String ackSetsToString(){ StringBuilder sb = new StringBuilder(); for (QuorumVerifierAcksetPair qvAckset : qvAcksetPairs) { sb.append(qvAckset.getAckset().toString()).append(","); } return sb.substring(0, sb.length()-1); }
private static String mergeLeavesIntoCollocatedString(Tree t) { StringBuilder sb = new StringBuilder(160); ArrayList<TaggedWord> sent = t.taggedYield(); for (TaggedWord aSent : sent) { sb.append(aSent.word()).append('_'); } return sb.substring(0,sb.length() -1); }
private String layoutInspect() { ThreadContext context = getRuntime().getCurrentContext(); StringBuilder sb = new StringBuilder(); for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) { sb.append(Utils.unescapeIdentifier(fdef.getName())); sb.append(": "); sb.append(getField(context, fdef).inspect()); sb.append(", "); } return sb.substring(0, sb.length() - 2); }
private String newLongValue() { StringBuilder buf = new StringBuilder(2 * data.length + 5); int i = 0; i = appendHexDumpField(buf, i, MACHINE_ID.length); i = appendHexDumpField(buf, i, PROCESS_ID_LEN); i = appendHexDumpField(buf, i, SEQUENCE_LEN); i = appendHexDumpField(buf, i, TIMESTAMP_LEN); i = appendHexDumpField(buf, i, RANDOM_LEN); assert i == data.length; return buf.substring(0, buf.length() - 1); }
private static TypeSpec generate(List<TypeElement> libraryModules, Class<? extends Annotation> annotation) { AnnotationSpec.Builder annotationBuilder = AnnotationSpec.builder(Index.class); String value = getAnnotationValue(annotation); for (TypeElement childModule : libraryModules) { annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString()); } StringBuilder indexerName = new StringBuilder( INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_"); for (TypeElement element : libraryModules) { indexerName.append(element.getQualifiedName().toString().replace(".", "_")); indexerName.append("_"); } indexerName = new StringBuilder(indexerName.substring(0, indexerName.length() - 1)); return TypeSpec.classBuilder(indexerName.toString()) .addAnnotation(annotationBuilder.build()) .addModifiers(Modifier.PUBLIC) .build(); }
private String newLongValue() { StringBuilder buf = new StringBuilder(2 * data.length + 5); int i = 0; i = appendHexDumpField(buf, i, MACHINE_ID.length); i = appendHexDumpField(buf, i, PROCESS_ID_LEN); i = appendHexDumpField(buf, i, SEQUENCE_LEN); i = appendHexDumpField(buf, i, TIMESTAMP_LEN); i = appendHexDumpField(buf, i, RANDOM_LEN); assert i == data.length; return buf.substring(0, buf.length() - 1); }
void run() throws IOException { List<String> results = new ArrayList<>(); for (TestCase testCase : testCases) { results.addAll(testCase.test(strategy)); } if (results.isEmpty()) { return; } StringBuilder failure = new StringBuilder("Failing Tests:\n"); for (String result : results) { failure.append(result).append("\n"); } fail(failure.substring(0, failure.length() - 1)); }
public CodeWriter startLineWithNum(int sourceLine) { if (sourceLine == 0) { startLine(); return this; } if (ADD_LINE_NUMBERS) { newLine(); attachSourceLine(sourceLine); String ln = "/* " + sourceLine + " */ "; add(ln); if (indentStr.length() > ln.length()) { add(indentStr.substring(ln.length())); } } else { startLine(); attachSourceLine(sourceLine); } return this; }