コード例 #1
0
 /** Notification that the invariants have broken, triggers an error. */
 private void invariantsBroken(Object key, Object value) {
   String mapBefore = _map.toString();
   String setBefore = _sortedSet.toString();
   String mapSizeBefore = "" + _map.size();
   String setSizeBefore = "" + _sortedSet.size();
   stabilize();
   String mapAfter = _map.toString();
   String setAfter = _sortedSet.toString();
   String mapSizeAfter = "" + _map.size();
   String setSizeAfter = "" + _sortedSet.size();
   Assert.silent(
       false,
       "key: "
           + key
           + ", value: "
           + value
           + "\nbefore stabilization: "
           + "\nsize of map: "
           + mapSizeBefore
           + ", set: "
           + setSizeBefore
           + "\nmap: "
           + mapBefore
           + "\nset: "
           + setBefore
           + "\nafter stabilization: "
           + "\nsize of map "
           + mapSizeAfter
           + ", set: "
           + setSizeAfter
           + "\nmap: "
           + mapAfter
           + "\nset: "
           + setAfter);
 }
コード例 #2
0
  /**
   * Add dependencies element for the given bundle to the string buffer.
   *
   * @param el element to add the dependencies to.
   * @param ba The bundle archive to defining the coordinates.
   * @param prefix Whitespace to add before the new element.
   */
  private void addDependencies(Element el, BundleArchive ba, String prefix) {
    final Element dependencies = el.getOwnerDocument().createElement("dependencies");
    final String prefix1 = prefix + "  ";
    final String prefix2 = prefix1 + "  ";

    el.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix1));
    el.appendChild(dependencies);
    el.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix));

    for (final Entry<BundleArchive, SortedSet<String>> depEntry : selectCtDeps(ba).entrySet()) {
      final BundleArchives.BundleArchive depBa = depEntry.getKey();
      final SortedSet<String> pkgNames = depEntry.getValue();

      dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix2));
      dependencies.appendChild(el.getOwnerDocument().createComment(pkgNames.toString()));

      final Element dependency = el.getOwnerDocument().createElement("dependency");
      addMavenCoordinates(dependency, depBa);
      if (pkgNames.contains("org.osgi.framework")) {
        dependency.setAttribute("scope", "provided");
      }

      dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix2));
      dependencies.appendChild(dependency);
      dependencies.appendChild(el.getOwnerDocument().createTextNode("\n"));
    }
    dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix1));

    if (0 < ba.pkgUnprovidedMap.size()) {
      log("  Imports without any provider: " + ba.pkgUnprovidedMap, Project.MSG_DEBUG);
    }
  }
コード例 #3
0
  public static SortedSet calculate(
      String expression, SortedSet A, SortedSet B, SortedSet C, SortedSet D, SortedSet F) {
    SortedSet result = null;

    result = RPN.calculateRPN(RPN.convertToRPN(expression), A, B, C, D, F);
    Log.i("Bsdfsfs", "Start calculate reverse expression: " + result.toString());
    return result;
  }
コード例 #4
0
ファイル: UserAdmin.java プロジェクト: niketkumar/lumify
 private String privilegesAsString(Set<Privilege> privileges) {
   SortedSet<Privilege> sortedPrivileges =
       new TreeSet<Privilege>(
           new Comparator<Privilege>() {
             @Override
             public int compare(Privilege p1, Privilege p2) {
               return p1.ordinal() - p2.ordinal();
             }
           });
   sortedPrivileges.addAll(privileges);
   return sortedPrivileges.toString().replaceAll(" ", "");
 }
 @Test
 public void testSendAndReceive() throws Exception {
   container.setMessageListener(
       new MessageListener() {
         @Override
         public void onMessage(Message msg) {
           try {
             processed.add(((TextMessage) msg).getText());
           } catch (JMSException e) {
             throw new IllegalStateException(e);
           }
         }
       });
   container.initializeProxy();
   container.start();
   jmsTemplate.convertAndSend("queue", "foo");
   jmsTemplate.convertAndSend("queue", "bar");
   SortedSet<String> result = new TreeSet<String>();
   for (int i = 0; i < 2; i++) {
     result.add(processed.poll(5, TimeUnit.SECONDS));
   }
   assertEquals("[bar, foo]", result.toString());
 }
コード例 #6
0
  public static void main(String args[]) throws URISyntaxException {
    long startTime = System.nanoTime();
    DefinitionTableVisitor.DEFAULT_DEBUG_DEFTBL_VISITOR = true;

    String fileName = null;
    Dialect extension = SectionManager.DEFAULT_EXTENSION;
    boolean debug = false;
    boolean printSchRefs = false;
    boolean hideWarnings = false;
    boolean checkDefTblConsistency = false;
    int fileArgIndex = 0;
    for (int i = 0; i < args.length && fileName == null; i++, fileArgIndex++) {
      if ("-y".equals(args[i])) {
        checkDefTblConsistency = true;
      } else if ("-h".equals(args[i])) {
        hideWarnings = true;
      } else if ("-p".equals(args[i])) {
        printSchRefs = true;
      } else if ("--debug".equals(args[i])) {
        debug = true;
      } else if (args[i].startsWith("-e")) {
        final String ext = args[i].substring(2).toUpperCase();
        try {
          extension = Dialect.valueOf(ext);
        } catch (IllegalArgumentException e) {
          System.err.println("Unknown CZT extension " + ext);
          System.exit(-1);
        }
      } else if (args[i].startsWith("-")) {
        System.err.println("Ignoring unknown argument " + args[i]);
      } else {
        fileName = args[i];
        System.out.println("Processing " + fileName);
      }
    }
    assert fileName != null;
    System.out.println();

    SectionManager manager = new SectionManager(extension);
    manager.setProperty(PROP_VCG_RAISE_TYPE_WARNINGS, String.valueOf(false));
    manager.setProperty(PROP_VCG_CHECK_DEFTBL_CONSISTENCY, String.valueOf(checkDefTblConsistency));
    manager.setProperty(
        TypecheckPropertiesKeys.PROP_TYPECHECK_WARNINGS_OUTPUT,
        String.valueOf(hideWarnings ? WarningOutput.HIDE : WarningOutput.SHOW));
    manager.setTracing(debug);
    manager.putCommand(getCommandInfoType(), getCommand(manager));
    DefinitionTable table = null;
    File file = new File(fileName);
    String sourceName = SourceLocator.getSourceName(file.getName());
    SourceLocator.addCZTPathFor(file, manager);
    manager.put(
        new Key<net.sourceforge.czt.session.Source>(
            sourceName, net.sourceforge.czt.session.Source.class),
        new net.sourceforge.czt.session.FileSource(file));
    Key<Spec> specKey = new Key<Spec>(sourceName, Spec.class);
    Key<SectTypeEnvAnn> typeKey = new Key<SectTypeEnvAnn>(sourceName, SectTypeEnvAnn.class);
    Key<DefinitionTable> defTblKey = new Key<DefinitionTable>(sourceName, DefinitionTable.class);
    long setupTime = System.nanoTime();
    boolean exceptionThrown = false;
    try {
      manager.get(specKey);
    } catch (CommandException ex) {
      System.out.println("Parsing errors!");
      handleCmdException(ex, -2);
    }
    long parseTime = System.nanoTime();
    try {
      manager.get(typeKey);
    } catch (CommandException ex) {
      System.out.println("Typechecking errors!");
      handleCmdException(ex, -3);
    }
    long typeTime = System.nanoTime();
    try {
      table = manager.get(defTblKey);
    } catch (CommandException ex) {
      handleCmdException(ex, 0); // >=0 is to try again

      // exceptionThrown = true;
      // try a second time to see if the one with errors was cached
      try {
        table = manager.get(defTblKey);
      } catch (CommandException fx) {
        handleCmdException(fx, 0);
        exceptionThrown = true;
      }
    }
    long defTblTime = System.nanoTime();
    long dtCons = 0, dtOther = 0, dtBinding = 0;
    StringBuilder output = new StringBuilder();
    output.append("\n\n");
    if (table != null) {
      DefinitionException consistency = table.checkOverallConsistency();
      dtCons = System.nanoTime();

      if (!exceptionThrown) {

        //        final String result = table.toString(false, true);
        //        System.out.println("\n------------------------------- DEFTABLE
        // -------------------------------");
        //        System.out.println(result);
        //        System.out.println();

        Set<Definition> defs = table.lookupDefinitions(sourceName);
        if (printSchRefs) {
          output.append(
              "\n------------------------------- SCHREFS --------------------------------");
          for (Definition d : defs) {
            if (d.getDefinitionKind().isSchemaReference()) {
              output.append(d.toString()).append("\n");
            }
          }
        }
        dtOther = System.nanoTime();
        dtBinding = dtOther;
        if (args.length > fileArgIndex) {
          ZName arg = ZUtils.FACTORY.createZName(args[fileArgIndex]);
          output
              .append("\n------------------------------- BINDINGS -------------------------------")
              .append("\n");
          Definition def = table.lookupName(arg);
          if (def == null) {
            output.append("Could not find bindings for ").append(arg).append("\n");
          } else {
            try {
              SortedSet<Definition> bindings = table.bindings(arg);
              dtBinding = System.nanoTime() - dtOther;
              final String result2 = bindings.toString().replaceAll(", ", ",\n");
              output
                  .append("Bindings for ")
                  .append(args[fileArgIndex])
                  .append(" = ")
                  .append(bindings.size())
                  .append("\n");
              output.append(result2).append("\n");
            } catch (DefinitionException ex) {
              System.err.println("Could not retrive bindings for " + args[fileArgIndex]);
              handleCmdException(ex, 0);
            }
            output.append("\n-------------- of Def -------------").append("\n");
            output.append(def.toString()).append("\n");
          }
          output
              .append("\n------------------------------------------------------------------------")
              .append("\n");
          output.append("\n");
        }
      } else {
        dtOther = System.nanoTime();
        dtBinding = dtOther;
      }
      output
          .append("CONSISTENCY-CHECK = ")
          .append(
              consistency == null
                  ? " okay! "
                  : " has " + (consistency.totalNumberOfErrors() - 1) + " errors");
      output.append(consistency == null ? "" : consistency.getMessage(true)).append("\n");
    }
    long finishTime = System.nanoTime();
    long nano2msec = 1000000;
    output
        .append("\n------------------------------------------------------------------------")
        .append("\n");
    output.append("START-TIME = ").append(startTime / nano2msec).append("\n");
    output
        .append("SETUP-TIME = ")
        .append(setupTime / nano2msec)
        .append("\t ")
        .append((setupTime - startTime) / nano2msec)
        .append("\n");
    output
        .append("PARSE-TIME = ")
        .append(parseTime / nano2msec)
        .append("\t ")
        .append((parseTime - setupTime) / nano2msec)
        .append("\n");
    output
        .append("TYPEC-TIME = ")
        .append(typeTime / nano2msec)
        .append("\t ")
        .append((typeTime - parseTime) / nano2msec)
        .append("\n");
    output
        .append("DEFTB-TIME = ")
        .append(defTblTime / nano2msec)
        .append("\t ")
        .append((defTblTime - typeTime) / nano2msec)
        .append("\n");
    output
        .append("DTCON-TIME = ")
        .append(dtCons / nano2msec)
        .append("\t ")
        .append((dtCons - defTblTime) / nano2msec)
        .append("\n");
    output
        .append("DTOTH-TIME = ")
        .append(dtOther / nano2msec)
        .append("\t ")
        .append((dtOther - dtCons) / nano2msec)
        .append("\n");
    output
        .append("DTBIN-TIME = ")
        .append(dtBinding / nano2msec)
        .append("\t ")
        .append((dtBinding - dtOther) / nano2msec)
        .append("\n");
    output
        .append("TOTAL-TIME = ")
        .append(finishTime / nano2msec)
        .append("\t ")
        .append((finishTime - startTime) / nano2msec)
        .append("\n");
    output.append("\n");

    System.out.println(output.toString());

    //    DefinitionException c =
    //      new DefinitionException("a",
    //        Arrays.asList(new DefinitionException("a.b",
    //            Arrays.asList(new DefinitionException("a.b.1"),
    //                          new DefinitionException("a.b.2",
    //                            Arrays.asList(new DefinitionException("a.b.2.1"))))),
    //                      new DefinitionException("a.c",
    //                        Arrays.asList(new DefinitionException("a.c.1"))),
    //                      new DefinitionException("a.d")));
    //    System.out.println("c = " + c.getMessage());
    //    System.out.println("c = " + c.totalNumberOfErrors());
    //    System.out.println("c = transitive list with " + c.getTransitiveExceptions().size());
    //    Iterator<DefinitionException> it = c.getTransitiveExceptions().iterator();
    //    while (it.hasNext())
    //      System.out.println("c = " + it.next().getMessage(false));

    /*
       URL url = table.getClass().getResource("/lib/");//dc_toolkit.tex");
       file = new File(url.toURI());
       System.out.println("url.file   = " + url.getFile());
       System.out.println("url.path   = " + url.getPath());
       System.out.println("url.extf   = " + url.toExternalForm());
       System.out.println("url.toStr  = " + url.toString());
       System.out.println("URI.toStr  = " + url.toURI());
       System.out.println("file.name  = " + file.getName());
       System.out.println("file.parent= " + file.getParent());
       System.out.println("file.path  = " + file.getPath());
       System.out.println("file.abspth= " + file.getAbsolutePath());
       System.out.println("file.tostr = " + file.toString());
    *
    */

  }