public static void verifyCommand( String args[], @SuppressWarnings("unused") String help, Pattern[] patterns, int low, int high) { String message = ""; if (args.length > high) { message = "too many arguments"; } else if (args.length < low) { message = "too few arguments"; } else { for (int i = 0; patterns != null && i < patterns.length && i < args.length; i++) { if (patterns[i] != null) { Matcher m = patterns[i].matcher(args[i]); if (!m.matches()) message += String.format( "Argument %s (%s) does not match %s%n", i, args[i], patterns[i].pattern()); } } } if (message.length() != 0) { StringBuilder sb = new StringBuilder(); String del = "${"; for (String arg : args) { sb.append(del); sb.append(arg); del = ";"; } sb.append("}, is not understood. "); sb.append(message); throw new IllegalArgumentException(sb.toString()); } }
public String getCoordinates(RevisionRef r) { StringBuilder sb = new StringBuilder(r.groupId).append(":").append(r.artifactId).append(":"); if (r.classifier != null) sb.append(r.classifier).append("@"); sb.append(r.version); return sb.toString(); }
private CIJobStatus deleteCI(CIJob job, List<String> builds) throws PhrescoException { S_LOGGER.debug("Entering Method CIManagerImpl.deleteCI(CIJob job)"); S_LOGGER.debug("Job name " + job.getName()); cli = getCLI(job); String deleteType = null; List<String> argList = new ArrayList<String>(); S_LOGGER.debug("job name " + job.getName()); S_LOGGER.debug("Builds " + builds); if (CollectionUtils.isEmpty(builds)) { // delete job S_LOGGER.debug("Job deletion started"); S_LOGGER.debug("Command " + FrameworkConstants.CI_JOB_DELETE_COMMAND); deleteType = DELETE_TYPE_JOB; argList.add(FrameworkConstants.CI_JOB_DELETE_COMMAND); argList.add(job.getName()); } else { // delete Build S_LOGGER.debug("Build deletion started"); deleteType = DELETE_TYPE_BUILD; argList.add(FrameworkConstants.CI_BUILD_DELETE_COMMAND); argList.add(job.getName()); StringBuilder result = new StringBuilder(); for (String string : builds) { result.append(string); result.append(","); } String buildNos = result.substring(0, result.length() - 1); argList.add(buildNos); S_LOGGER.debug("Command " + FrameworkConstants.CI_BUILD_DELETE_COMMAND); S_LOGGER.debug("Build numbers " + buildNos); } try { int status = cli.execute(argList); String message = deleteType + " deletion started in jenkins"; if (status == FrameworkConstants.JOB_STATUS_NOTOK) { deleteType = deleteType.substring(0, 1).toLowerCase() + deleteType.substring(1); message = "Error while deleting " + deleteType + " in jenkins"; } S_LOGGER.debug("Delete CI Status " + status); S_LOGGER.debug("Delete CI Message " + message); return new CIJobStatus(status, message); } finally { if (cli != null) { try { cli.close(); } catch (IOException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) " + e.getLocalizedMessage()); } } catch (InterruptedException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) " + e.getLocalizedMessage()); } } } } }
// 过滤整数字符,把所有非0~9的字符全部删除 private void filterInt(StringBuilder builder) { for (int i = builder.length() - 1; i >= 0; i--) { int cp = builder.codePointAt(i); if (cp > '9' || cp < '0') { builder.deleteCharAt(i); } } }
/** * Test that <code>Clob.getCharacterStream(long,long)</code> works on CLOBs that are streamed from * store. (DERBY-2891) */ public void testGetCharacterStreamLongOnLargeClob() throws Exception { getConnection().setAutoCommit(false); // create large (>32k) clob that can be read from store final int size = 33000; StringBuilder sb = new StringBuilder(size); for (int i = 0; i < size; i += 10) { sb.append("1234567890"); } final int id = BlobClobTestSetup.getID(); PreparedStatement ps = prepareStatement("insert into blobclob(id, clobdata) values (?,cast(? as clob))"); ps.setInt(1, id); ps.setString(2, sb.toString()); ps.executeUpdate(); ps.close(); Statement s = createStatement(); ResultSet rs = s.executeQuery("select clobdata from blobclob where id = " + id); assertTrue(rs.next()); Clob c = rs.getClob(1); // request a small region of the clob BufferedReader r = new BufferedReader(c.getCharacterStream(4L, 3L)); assertEquals("456", r.readLine()); r.close(); c.free(); rs.close(); s.close(); rollback(); }
public StringBuilder getQualifiedName(StringBuilder b, boolean generic) { if (getEnclosingType() instanceof ClassRef) { getEnclosingType().getQualifiedName(b, generic).append('$'); } else if (getEnclosingType() instanceof NamespaceRef) { getEnclosingType().getQualifiedName(b, generic).append('.'); } b.append(ident.simpleName); if (generic && ident.templateArguments != null) { int args = 0; for (int i = 0, n = ident.templateArguments.length; i < n; i++) { TemplateArg arg = ident.templateArguments[i]; if (!(arg instanceof TypeRef)) { continue; } if (args == 0) { b.append('<'); } else { b.append(", "); } ((TypeRef) arg).getQualifiedName(b, generic); args++; } if (args > 0) { b.append('>'); } } return b; }
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { StringBuilder builder = new StringBuilder(string); // 过滤用户输入的所有字符 filterInt(builder); super.insertString(fb, offset, builder.toString(), attr); }
public static void printViewPatterns() { processedViewsForPatterns = new HashSet<ViewTrace>(); HashMap<String, Integer> viewPatterns = new HashMap<String, Integer>(); ps.println("ViewPatterns ------------------- \n"); for (ViewTrace trace : viewsRegistry) { if (processedViewsForPatterns.contains(trace)) { continue; } ViewTrace v = trace.getRootView(); StringBuilder p = new StringBuilder(); p.append("PATTERN "); extractViewPattern(0, v, p); p.append("\n"); String pattern = p.toString(); Integer count = viewPatterns.get(pattern); if (count == null) { viewPatterns.put(pattern, 1); } else { viewPatterns.put(pattern, count + 1); } } processedViewsForPatterns = null; for (Map.Entry<String, Integer> e : viewPatterns.entrySet()) { ps.print("(" + e.getValue() + ") "); ps.println(e.getKey()); } }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{firstBound=").append(firstBound()); sb.append(", interfaceBounds=[]}"); return sb.toString(); }
private void setSvnCredential(CIJob job) throws JDOMException, IOException { S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential"); try { String jenkinsTemplateDir = Utility.getJenkinsTemplateDir(); String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML; if (debugEnabled) { S_LOGGER.debug("credentialFilePath ... " + credentialFilePath); } File credentialFile = new File(credentialFilePath); SvnProcessor processor = new SvnProcessor(credentialFile); // DataInputStream in = new DataInputStream(new FileInputStream(credentialFile)); // while (in.available() != 0) { // System.out.println(in.readLine()); // } // in.close(); processor.changeNodeValue("credentials/entry//userName", job.getUserName()); processor.changeNodeValue("credentials/entry//password", job.getPassword()); processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName())); // jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setSvnCredential " + e.getLocalizedMessage()); } }
public String toString() { StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()).append('{'); for (TypedValues typed : _values) { sb.append(typed); } return sb.append('}').toString(); }
static String toString(Type[] types) { StringBuilder sb = new StringBuilder(); for (Type t : types) { sb.append(toString(t)).append(", "); } return sb.substring(0, sb.length() - 2); // drop last , }
public static void printSite(Site s, StringBuilder out) { if (s == null) { out.append("(null)"); return; } StackTraceElement[] st = s.site(); int interestingSitesPrinted = 0; for (int i = s.offset; i < st.length; i++) { StackTraceElement e = st[i]; String fileName = e.getFileName(); if (THIS_FILE_NAME.equals(fileName)) { continue; } out.append(" " + e.getMethodName() + "(" + e.getFileName() + ":" + e.getLineNumber() + ")"); interestingSitesPrinted++; if (interestingSitesPrinted <= SITES_TO_PRINT) { continue; } if (fileName == null || "View.java".equals(fileName)) { continue; } String methodName = e.getMethodName(); if (skipMethods.contains(methodName)) { continue; } break; } }
@Override public String toString() { StringBuilder b = new StringBuilder(); b.append(simpleName); appendTemplateArgs(b, templateArguments); return b.toString(); }
private static String or(String... tokens) { StringBuilder buf = new StringBuilder(); for (String t : tokens) { if (buf.length() > 0) buf.append('|'); buf.append(t); } return buf.toString(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{firstBound=").append(firstBound()); sb.append(", interfaceBounds=").append(Arrays.deepToString(interfaceBounds())); sb.append('}'); return sb.toString(); }
@Override public String toString() { StringBuilder b = new StringBuilder(); for (Class<?> ann : annotations) { b.append(ann.getSimpleName()).append(' '); } b.append((type instanceof Class<?>) ? ((Class<?>) type).getSimpleName() : type.toString()); return b.toString(); }
/** * Builds the key that uniquely identifies the MBeanServerConnection that would be created by * this builder * * @return the unique MBeanServerConnection key */ private String buildKey() { StringBuilder b = new StringBuilder(); b.append(channel.getId()); b.append(domain); if (remoteAddress != null) { b.append(remoteAddress.toString()); } return b.toString(); }
/** * Returns a string representation of all found arguments. * * @param args array with arguments * @return string representation */ static String foundArgs(final Value[] args) { // compose found arguments final StringBuilder sb = new StringBuilder(); for (final Value v : args) { if (sb.length() != 0) sb.append(", "); sb.append(v instanceof Jav ? Util.className(((Jav) v).toJava()) : v.seqType()); } return sb.toString(); }
public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { if (string != null) { StringBuilder builder = new StringBuilder(string); // 过滤用户替换的所有字符 filterInt(builder); string = builder.toString(); } super.replace(fb, offset, length, string, attr); }
/** * This methods provides a readable classname. If the supplied name parameter denotes an array * this method returns either the classname of the component type for arrays of java reference * types or the name of the primitive type for arrays of java primitive types followed by n-times * "[]" where 'n' denotes the arity of the array. Otherwise, if the supplied name doesn't denote * an array it returns the same classname. */ public static String getReadableClassName(String name) { String className = getArrayClassName(name); if (className == null) return name; int index = name.lastIndexOf("["); StringBuilder brackets = new StringBuilder(className); for (int i = 0; i <= index; i++) { brackets.append("[]"); } return brackets.toString(); }
public String toString() { StringBuilder str = new StringBuilder(80); str.append("return "); if (getExpression() != null) str.append(getExpression().toString()); str.append(";"); return str.toString(); }
private void end(StringBuilder ans, Pretty pretty, String indent) { if (endEncloser == null) return; if (!pretty.pretty) ans.append(endEncloser); else { Utilities.assureEndsWithNewLine(ans); ans.append(indent + endEncloser); if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment); Utilities.assureEndsWithNewLine(ans); } }
public String toString() { StringBuilder str = new StringBuilder(80); Iterator iter = children.iterator(); str.append(iter.next().toString()); while (iter.hasNext()) str.append("[" + iter.next().toString() + "]"); return str.toString(); }
private static String functionSig(Method method, Object[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < args.length; i++) { if (i > 0) sb.append(","); sb.append(TypeUtil.toCodeStringLimited(args[i])); } return FunctionRegistry.functionName(method.getDeclaringClass().getName(), method.getName()) + "(" + sb.toString() + ")"; }
@Override public String toString() { StringBuilder b = new StringBuilder(); if (enclosingType != null) { b.append(enclosingType).append('.'); } b.append(ident); return b.toString(); }
public static StringBuilder implode(StringBuilder b, Iterable<?> items, String sep) { boolean first = true; for (Object item : items) { if (first) { first = false; } else { b.append(sep); } b.append(item); } return b; }
private void start(StringBuilder ans, Pretty pretty, String indent) { if (startEncloser == null) return; if (!pretty.pretty) { ans.append(startEncloser); } else { String comment; if (pretty.comments && startComment.length() > 0) comment = " #" + startComment; else comment = ""; ans.append(indent + startEncloser + comment); Utilities.assureEndsWithNewLine(ans); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); String del = "["; for (Link r = this; r != null; r = r.previous) { sb.append(del); sb.append(r.key); del = ","; } sb.append("]"); return sb.toString(); }
static void appendArgs(StringBuilder b, char pre, char post, Object[] params) { b.append(pre); if (params != null) { for (int i = 0; i < params.length; i++) { if (i != 0) { b.append(", "); } b.append(params[i]); } } b.append(post); }