/** * converts back slashes to forward slashes removes double slashes inside the path, e.g. "x/y//z" * => "x/y/z" */ @NotNull public static String normalize(@NotNull String path) { final StringBuilder result = new StringBuilder(path.length()); int start = 0; boolean separator = false; if (SystemInfo.isWindows && (path.startsWith("//") || path.startsWith("\\\\"))) { start = 2; result.append("//"); separator = true; } for (int i = start; i < path.length(); ++i) { final char c = path.charAt(i); if (c == '/' || c == '\\') { if (!separator) result.append('/'); separator = true; } else { result.append(c); separator = false; } } return result.toString(); }
private void read() throws FileNotFoundException { mapKeyWords = new HashMap<>(); StringBuilder sb = new StringBuilder(); try { BufferedReader in = new BufferedReader(new FileReader(fNameInput)); try { // В цикле построчно считываем файл String s; while ((s = in.readLine()) != null) { sb.append(s); sb.append("\n"); } } finally { // Также не забываем закрыть файл in.close(); } } catch (IOException e) { throw new RuntimeException(e); } String[] str = sb.toString().split(" "); for (String s : str) { if (keyWords.findString(s) == 1) { putStringToMap(s); } } System.out.println(mapKeyWords); }
public static void main(String[] args) { InputReader1 sc = new InputReader1(System.in); int N = sc.nextInt(); for (int i = 0; i <= N; i++) map.add(new ArrayList<Edge>()); for (int i = 1; i < N; i++) { int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt(); map.get(x).add(new Edge(y, i)); map.get(y).add(new Edge(x, i)); edges[i] = z; } StringBuilder op = new StringBuilder(); for (int i = 1; i <= N; i++) { dfs(i, 0, -1); } int temp = ans / 2; op.append(temp).append("\n"); int Q = sc.nextInt(); while (Q-- > 0) { ans = 0; int edgeNumber = sc.nextInt(), newEdgeCost = sc.nextInt(); edges[edgeNumber] = newEdgeCost; for (int i = 1; i <= N; i++) { dfs(i, 0, -1); } temp = ans / 2; op.append(temp).append("\n"); } System.out.println(op); }
private String getTag(Document d) { StringBuilder ab = new StringBuilder( d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0].replace( "E:\\I:\\ACM_complete_dataset\\", "")); return ab.substring(0, ab.indexOf("\\")).toString(); }
@Override public String getHeaderField(final String field) { final List<String> values = headers.get(field); final StringBuilder sb = new StringBuilder(); for (final String v : values) sb.append(v).append(';'); return sb.substring(0, sb.length() - 1); }
/** * Returns a tooltip for the specified options string. * * @param opts serialization options * @return string */ private static String tooltip(final Options opts) { final StringBuilder sb = new StringBuilder("<html><b>").append(PARAMETERS).append(":</b><br>"); for (final Option<?> so : opts) { if (!(so instanceof OptionsOption)) sb.append("\u2022 ").append(so).append("<br/>"); } return sb.append("</html>").toString(); }
static { // jquery权限验证 sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"../globalRes/js/jquery_easyui/themes/gray/easyui.css\"/>"); sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"../globalRes/js/jquery_easyui/themes/icon.css\"/>"); sb.append( "<script type=\"text/javascript\" src=\"../globalRes/js/jquery-1.7.2.min.js\"></script>"); sb.append( "<script type=\"text/javascript\" src=\"../globalRes/js/jquery_easyui/jquery.easyui.min.js\"></script>"); sb.append( "<script type=\"text/javascript\" src=\"../globalRes/js/jquery-automic-global.js\"></script>"); sb.append("<script tepe=\"text/javascript\">"); // 常规权限验证 sb.append( "$j(document).ready(function(){$j.messager.alert('信息提示','无权访问!','warning',function(){window.history.go(-1);});})"); sb.append("</script>"); // jquery权限验证信息补全 sbJQuery.append("{\"noJQueryPriv\":\"无权访问!\"}"); /** 此处<noFlexPriv></mess>,必须原样使用,直接可以写入信息, 供flex中FaultEvent调用,捕获异常事件及无权信息... */ sbFlex.append("<noFlexPriv>无权访问</noFlexPriv0>"); }
/** * Writes begin layer operator "%AI5_BeginLayer" and various parameters to output. Layer is * visible and enabled. * * @param layerName <code>String</code>, name of layer * @param colorIndex <code>int</code>, index to color associated with layer * @param pw <code>PrintWriter</code> for file output */ public static void beginLayer(String layerName, int colorIndex, PrintWriter pw) { StringBuilder buf = new StringBuilder(100); buf.append("%AI5_BeginLayer\n"); buf.append("1 1 1 1 0 0 " + colorIndex + " 255 79 79 Lb\n"); buf.append("(" + layerName + ") Ln\n"); pw.print(buf.toString()); }
public static String buildFileName(String prefix, String date, String suffix) { StringBuilder sb = new StringBuilder(); sb.append(prefix); sb.append(date); sb.append(suffix); return sb.toString(); }
public void composition_tokenizer(String comp_line) { comp_line = remove_for_agg(comp_line); String c_name = get_first(comp_line, "COMPOSITION"); String comp_name = get_latter(comp_line, "COMPOSITION"); StringBuilder construct_param = new StringBuilder(); construct_param.append(comp_name); construct_param.append("_"); construct_param.append(Integer.toString(param_count)); String param = construct_param.toString(); param_count++; if (output.get(c_name) != null) { comp_name = get_latter(comp_line, "COMPOSITION"); output.get(c_name).add_parameters(param); output.get(c_name).add_comp(param); } else { comp_name = get_first(comp_line, "COMPOSITION"); output.put(c_name, classes[object_count]); output.get(c_name).set_weird_name(c_name); current_class = c_name; object_count++; output.get(c_name).add_parameters(param); output.get(c_name).add_comp(param); } }
public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line; StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { int k = Integer.parseInt(line); List<Integer> xd = new ArrayList<Integer>(); List<Integer> yd = new ArrayList<Integer>(); for (int y = k + 1; y <= 2 * k; ++y) { if (k * y % (y - k) == 0) { int x = k * y / (y - k); xd.add(x); yd.add(y); } } sb.append(xd.size() + "\n"); for (int i = 0; i < xd.size(); ++i) sb.append(String.format("1/%d = 1/%d + 1/%d\n", k, xd.get(i), yd.get(i))); } System.out.print(sb); in.close(); System.exit(0); }
void handleRequest(InputStream in, OutputStream out) throws IOException { boolean newline = false; StringBuilder sb = new StringBuilder(); while (true) { int ch = in.read(); if (ch < 0) { throw new EOFException(); } sb.append((char) ch); if (ch == '\r') { // empty } else if (ch == '\n') { if (newline) { // 2nd newline in a row, end of request break; } newline = true; } else { newline = false; } } String request = sb.toString(); if (request.startsWith("GET / HTTP/1.") == false) { throw new IOException("Invalid request: " + request); } out.write("HTTP/1.0 200 OK\r\n\r\n".getBytes()); }
private String computeSignature(String httpMethod, Map<String, String> parameters) { String[] sortedKeys = parameters.keySet().toArray(new String[] {}); Arrays.sort(sortedKeys); final String SEPARATOR = "&"; StringBuilder sbStringToSign = new StringBuilder(); sbStringToSign.append(String.format("%s\n/app/\n", httpMethod)); String signature = ""; try { int count = 0; for (String key : sortedKeys) { if (count != 0) { sbStringToSign.append(SEPARATOR); } sbStringToSign .append(percentEncode(key)) .append("=") .append(percentEncode(parameters.get(key))); count++; } String strToSign = sbStringToSign.toString(); signature = calculateSignature(secretAppKey, strToSign); } catch (UnsupportedEncodingException e) { } catch (Exception e) { } return signature; }
protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws IOException { Reader in = null; try { if (encoding == null) { encoding = GeneralUtils.DEFAULT_FILE_CHARSET_NAME; } in = new BufferedReader(new InputStreamReader(contentStream, encoding), DEFAULT_BUFFER_SIZE); StringBuilder buffer = new StringBuilder(DEFAULT_BUFFER_SIZE); char[] readBuffer = new char[2048]; int n = in.read(readBuffer); while (n > 0) { buffer.append(readBuffer, 0, n); n = in.read(readBuffer); } document.set(buffer.toString()); } finally { if (in != null) { ContentUtils.close(in); } else { ContentUtils.close(contentStream); } } }
public String toString() { StringBuilder ret = new StringBuilder(); InetAddress local = null, remote = null; String local_str, remote_str; Socket tmp_sock = sock; if (tmp_sock == null) ret.append("<null socket>"); else { // since the sock variable gets set to null we want to make // make sure we make it through here without a nullpointer exception local = tmp_sock.getLocalAddress(); remote = tmp_sock.getInetAddress(); local_str = local != null ? Util.shortName(local) : "<null>"; remote_str = remote != null ? Util.shortName(remote) : "<null>"; ret.append( '<' + local_str + ':' + tmp_sock.getLocalPort() + " --> " + remote_str + ':' + tmp_sock.getPort() + "> (" + ((System.currentTimeMillis() - last_access) / 1000) + " secs old)"); } tmp_sock = null; return ret.toString(); }
public String readFromFile(String fileName) { StringBuilder sb = new StringBuilder(); try { if (exists(fileName) == false) { // todo - исправь это плиз, а то выебу DONE throw new FileNotFoundException(); } else { File file = new File(String.valueOf(fileName)); String s; try { BufferedReader bufferedReaderIn = new BufferedReader(new FileReader(file.getAbsoluteFile())); try { while ((s = bufferedReaderIn.readLine()) != null) { sb.append(s).append(" "); } } finally { bufferedReaderIn.close(); } } catch (IOException e) { throw new RuntimeException(e); } } } catch (FileNotFoundException e) { log.error("File not found"); } return sb.toString(); }
@Override protected void writeConnectors(StringBuilder output) throws Exception { String[] connectorClasses = getConnectorClasses(); String[] connectorNames = getConnectorNames(); for (int i = 0; i < connectorNames.length; i++) { output.append( " <repositoryconnector name=\"" + connectorNames[i] + "\" class=\"" + connectorClasses[i] + "\"/>\n"); } String[] outputClasses = getOutputClasses(); String[] outputNames = getOutputNames(); for (int i = 0; i < outputNames.length; i++) { output.append( " <outputconnector name=\"" + outputNames[i] + "\" class=\"" + outputClasses[i] + "\"/>\n"); } String[] authorityClasses = getAuthorityClasses(); String[] authorityNames = getAuthorityNames(); for (int i = 0; i < authorityNames.length; i++) { output.append( " <authorityconnector name=\"" + authorityNames[i] + "\" class=\"" + authorityClasses[i] + "\"/>\n"); } }
// ****** public void reset() { // consumption = new float [size][size]; // Oxygen = new float [size][size]; Age = new int[size][size]; stemBirthCounter = new int[size][size]; stemBirthsTotal = new int[size][size]; stemDeathCounter = new int[size][size]; // TACDeathCounter = new int [size][size]; // TACBirthCounter = new int [size][size]; StringBuilder initGenome = new StringBuilder(); for (int i = 0; i < lengthGenome; i++) { initGenome.append("0"); } ; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) { carriedGenome[i][j] = (StringBuilder) initGenome; // carriedGenome[i][j] = (StringBuilder) initGenome; // Oxygen[i][j]=initOxygen; Age[i][j] = 0; stemBirthCounter[i][j] = 0; } resetCells(); }
public void solve() throws Exception { int x = sc.nextInt(); int y = sc.nextInt(); StringBuilder sb = new StringBuilder(); String p = null; String m = null; if (x >= 0) { p = "E"; m = "W"; } else { p = "W"; m = "E"; } x = abs(x); for (int i = 0; i < x; i++) { sb.append(m + p); } if (y >= 0) { p = "N"; m = "S"; } else { p = "S"; m = "N"; } y = abs(y); for (int i = 0; i < y; i++) { sb.append(m + p); } out.println(sb); }
private void makeName(String uri) { String name; int slash = uri.lastIndexOf('/'); if (slash > -1) { name = uri.substring(slash + 1); uri = uri.substring(0, (uri.length() - 1) - name.length()); while (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } slash = uri.lastIndexOf('/'); if (slash > -1) { name = uri.substring(slash + 1) + '_' + name; } } else { name = uri; } StringBuilder buf = new StringBuilder(name.length()); for (int ix = 0, ixz = name.length(); ix < ixz; ix++) { char c = name.charAt(ix); if (c < '0' || (c > '9' && c < '@') || (c > 'Z' && c < '_') || (c > '_' && c < 'a') || c > 'z') { c = '_'; } else if (ix == 0 && c >= '0' && c <= '9') { c = '_'; } buf.append(c); } className = buf.toString(); }
/** * 计算文档的特征向量 * * @param docStr 文档字符串 * @param docID 文档标号 * @param CDM 数据处理类 * @return */ public String FeatureVectorOfDoc( FeatureMaker FM, String docStr, int docID, CategorizingDataManager CDM) { StringBuilder sb = new StringBuilder(); String[] features = FM.getFeatureFromDoc(docStr); Map<Integer, Number> FeatureVector = new HashMap<Integer, Number>(); Map<String, Integer> dic = CDM.dic; for (String word : features) { Integer wordID = dic.get(word); if (wordID != null) { // 为特征词典中含有的词语 if (!FeatureVector.containsKey(wordID)) // 如果还没有为此词语计算权重 FeatureVector.put(wordID, getWight(docID, wordID, CDM)); } } // 对标号进行排序(libSVM格式要求) Integer[] keys = new Integer[] {}; keys = FeatureVector.keySet().toArray(keys); Arrays.sort( keys, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1 - o2; } }); for (Integer wordID : keys) { sb.append(wordID + ":" + FeatureVector.get(wordID) + " "); } return sb.toString(); }
private String paramsToQueryString(Map<String, String> params) throws UnsupportedEncodingException { if (params == null || params.size() == 0) { return null; } String[] sortedKeys = params.keySet().toArray(new String[] {}); Arrays.sort(sortedKeys); StringBuilder paramString = new StringBuilder(); boolean first = true; for (String key : sortedKeys) { Object val = params.get(key); if (!first) { paramString.append("&"); } if (val instanceof String) { paramString.append(URLEncoder.encode(key, ENCODING)); if (val != null) { String strValue = (String) val; paramString.append("=").append(URLEncoder.encode(strValue, ENCODING)); } } first = false; } return paramString.toString(); }
private String getSingleLineOfChildren(final List children) { final StringBuilder result = new StringBuilder(); final Iterator childrenIt = children.iterator(); boolean isFirst = true; while (childrenIt.hasNext()) { final Object child = childrenIt.next(); if (!(child instanceof ContentNode)) { return null; } else { String content = child.toString(); // if first item trims it from left if (isFirst) { content = Utils.ltrim(content); } // if last item trims it from right if (!childrenIt.hasNext()) { content = Utils.rtrim(content); } if (content.indexOf('\n') >= 0 || content.indexOf('\r') >= 0) { return null; } result.append(content); } isFirst = false; } return result.toString(); }
public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 1; i <= 200003; i++) SegmentTree[i] = new node(); for (int i = 1; i <= N; i++) a[i] = Integer.parseInt(st.nextToken()); build(1, 1, N); int M = Integer.parseInt(br.readLine()); StringBuilder op = new StringBuilder(); while (M-- > 0) { String inp[] = br.readLine().split(" "); int type = Integer.parseInt(inp[0]); if (type == 1) { int left = Integer.parseInt(inp[1]); int right = Integer.parseInt(inp[2]); int ans = query(1, 1, N, left, right).maxSum; op.append(ans).append("\n"); } else { int x = Integer.parseInt(inp[1]); int y = Integer.parseInt(inp[2]); update(1, 1, N, x, y); } } System.out.println(op); }
public static String normalizePath(String path) { if (!path.contains("./")) { return path; } boolean absolute = path.startsWith("/"); String[] elements = path.split(Repository.SEPARATOR); LinkedList<String> list = new LinkedList<String>(); for (String e : elements) { if ("..".equals(e)) { if (list.isEmpty() || "..".equals(list.getLast())) { list.add(e); } else { list.removeLast(); } } else if (!".".equals(e) && e.length() > 0) { list.add(e); } } StringBuilder sb = new StringBuilder(path.length()); if (absolute) { sb.append("/"); } int count = 0, last = list.size() - 1; for (String e : list) { sb.append(e); if (count++ < last) sb.append("/"); } return sb.toString(); }
public String toString() { StringBuilder sb = new StringBuilder(); for (Pair<Integer, Integer> a : sureAlignments) { sb.append(a + "; "); } return sb.toString(); }
// прочитать весь json в строку private static String readAll() throws IOException { StringBuilder data = new StringBuilder(); try { HttpURLConnection con = (HttpURLConnection) ((new URL(PRODUCT_URL).openConnection())); con.setRequestMethod("GET"); con.setDoInput(true); String s; try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) { while ((s = in.readLine()) != null) { data.append(s); } } } catch (MalformedURLException e) { e.printStackTrace(); throw new MalformedURLException("Url is not valid"); } catch (ProtocolException e) { e.printStackTrace(); throw new ProtocolException("No such protocol, it must be POST,GET,PATCH,DELETE etc."); } catch (IOException e) { e.printStackTrace(); throw new IOException("cannot read from server"); } return data.toString(); }
public String toString() { StringBuilder out = new StringBuilder(); Formatter formatter = new Formatter(out, Locale.US); for (int topic = 0; topic < numTopics; topic++) { formatter.format("Topic %d", topic); for (TopicScores scores : diagnostics) { formatter.format("\t%s=%.4f", scores.name, scores.scores[topic]); } formatter.format("\n"); for (int position = 0; position < topicTopWords[topic].length; position++) { if (topicTopWords[topic][position] == null) { break; } formatter.format(" %s", topicTopWords[topic][position]); for (TopicScores scores : diagnostics) { if (scores.wordScoresDefined) { formatter.format("\t%s=%.4f", scores.name, scores.topicWordScores[topic][position]); } } out.append("\n"); } } return out.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("LineColor"); sb.append(super.toString()); return sb.toString(); }
/** Do a Zappos Search and return the result and returns the result */ public String GetResult(int page) throws IOException { String urlStr = "http://api.zappos.com/Search?key=" + zapposKey + "&term=&limit=100&sort={\"price\":\"asc\"}"; if (page != 0) { urlStr += "&page=" + page; } URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (conn.getResponseCode() != 200) { throw new IOException(conn.getResponseMessage()); } // Buffer the result into a string BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); conn.disconnect(); return sb.toString(); }