コード例 #1
0
 /**
  * Returns the {@code String} representation of the given collection, or {@code null} if the given
  * collection is {@code null}.
  *
  * @param c the collection to format.
  * @return the {@code String} representation of the given collection.
  */
 public static String format(Collection<?> c) {
   if (c == null) return null;
   Iterator<?> i = c.iterator();
   if (!i.hasNext()) return "[]";
   StringBuilder b = new StringBuilder();
   b.append('[');
   for (; ; ) {
     Object e = i.next();
     b.append(e == c ? "(this Collection)" : toStringOf(e));
     if (!i.hasNext()) return b.append(']').toString();
     b.append(", ");
   }
 }
コード例 #2
0
ファイル: Beta013E.java プロジェクト: hiroshi-cl/wakaba
 public void run() {
   // Scanner sc = new Scanner(System.in);
   Scanner sc = new Scanner();
   StringBuilder sb = new StringBuilder(1000000);
   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
   final int N = sc.nextInt();
   final int M = sc.nextInt();
   final int K = (int) floor(sqrt(N));
   final int[] A = new int[N + 1];
   A[0] = 1;
   for (int i = 1; i <= N; i++) A[i] = sc.nextInt();
   final int[] next = new int[N + 1];
   final int[] step = new int[N + 1];
   final int[] last = new int[N + 1];
   for (int i = N; i > 0; i--) {
     int j = i + A[i];
     if (j > N || j / K > i / K) {
       last[i] = i;
       step[i] = 1;
       next[i] = j;
     } else {
       last[i] = last[j];
       step[i] = step[j] + 1;
       next[i] = next[j];
     }
   }
   for (int t = 0; t < M; t++)
     if (sc.nextInt() == 1) {
       int i = sc.nextInt();
       int j = 0;
       int k = 0;
       while (i <= N) {
         j += step[i];
         k = last[i];
         i = next[i];
       }
       sb.append(k).append(' ').append(j).append('\n');
       // System.out.println(k + " " + j);
     } else {
       int k = sc.nextInt();
       int b = k / K * K;
       A[k] = sc.nextInt();
       for (int i = min(b + K - 1, N); i >= b; i--) {
         int j = i + A[i];
         if (j > N || j / K > i / K) {
           last[i] = i;
           step[i] = 1;
           next[i] = j;
         } else {
           last[i] = last[j];
           step[i] = step[j] + 1;
           next[i] = next[j];
         }
       }
     }
   // System.out.flush();
   System.out.print(sb);
 }
コード例 #3
0
 protected boolean appendSubsection(
     StringBuilder builder, Iterable<XImportDeclaration> subSection, boolean needsNewline) {
   if (!isEmpty(subSection)) {
     if (needsNewline) builder.append(lineSeparator);
     for (XImportDeclaration declaration : isSort() ? sort(subSection) : subSection) {
       appendImport(builder, declaration);
     }
     return true;
   }
   return needsNewline;
 }
コード例 #4
0
 protected String serializeImports(List<XImportDeclaration> allDeclarations) {
   StringBuilder builder = new StringBuilder();
   if (needsPreceedingBlankLine()) builder.append(lineSeparator).append(lineSeparator);
   boolean needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return !input.isStatic();
                 }
               }),
           false);
   needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return input.isStatic() && !input.isExtension();
                 }
               }),
           needNewline);
   appendSubsection(
       builder,
       filter(
           allDeclarations,
           new Predicate<XImportDeclaration>() {
             @Override
             public boolean apply(XImportDeclaration input) {
               return input.isStatic() && input.isExtension();
             }
           }),
       needNewline);
   if (!isEmpty(allDeclarations)) builder.append(lineSeparator);
   return builder.toString();
 }
コード例 #5
0
 protected void addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) {
   StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend();
   if (importDeclarationsToAppend.length() == 0) return;
   importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
   importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource);
   int insertOffset = importRegion.getOffset() + importRegion.getLength();
   if (insertOffset != 0 && originalImportDeclarations.isEmpty())
     importDeclarationsToAppend.insert(0, lineSeparator);
   importDeclarationsToAppend.append(lineSeparator);
   int insertLength = -importRegion.getLength();
   insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength();
   ReplaceRegion appendDeclarations =
       new ReplaceRegion(
           new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString());
   acceptor.accept(appendDeclarations);
 }
コード例 #6
0
 protected void appendImport(StringBuilder builder, XImportDeclaration newImportDeclaration) {
   builder.append("import ");
   if (newImportDeclaration.isStatic()) {
     builder.append("static ");
     if (newImportDeclaration.isExtension()) {
       builder.append("extension ");
     }
   }
   String qualifiedTypeName = newImportDeclaration.getImportedNamespace();
   if (newImportDeclaration.getImportedType() != null) {
     qualifiedTypeName = serializeType(newImportDeclaration.getImportedType());
   }
   String escapedTypeName = nameValueConverter.toString(qualifiedTypeName);
   builder.append(escapedTypeName);
   if (newImportDeclaration.isStatic()) {
     builder.append(".");
     if (newImportDeclaration.isWildcard()) {
       builder.append("*");
     } else {
       builder.append(newImportDeclaration.getMemberName());
     }
   }
   builder.append(lineSeparator);
 }