コード例 #1
0
 /** @return create dialog result object basing on the dialog state */
 private Result createResult() {
   Result rc = new Result();
   String name = myNameTextField.getText().trim();
   if (myTarget == null) {
     rc.target = myConfig.createConfiguration(name);
   } else {
     rc.target = myTarget;
     rc.target.setName(name);
   }
   rc.changes = new ArrayList<Change>(myChangesTree.getIncludedChanges());
   for (BranchDescriptor d : myBranches) {
     if (d.root != null) {
       if (!StringUtil.isEmpty(d.newBranchName)) {
         final String ref = d.referenceToCheckout.trim();
         rc.referencesToUse.put(d.root, Pair.create(ref, d.referencesToSelect.contains(ref)));
         rc.target.setReference(d.root.getPath(), d.newBranchName.trim());
         rc.checkoutNeeded.add(d.root);
       } else {
         String ref = d.referenceToCheckout.trim();
         if (!d.referencesToSelect.contains(ref)) {
           ref = myConfig.detectTag(d.root, ref);
         }
         rc.target.setReference(d.root.getPath(), ref);
         if (!d.referenceToCheckout.equals(d.currentReference)) {
           rc.checkoutNeeded.add(d.root);
         }
       }
     }
   }
   return rc;
 }
コード例 #2
0
ファイル: ZxingQrcode.java プロジェクト: zhiyongl/jcommon
 private static String decodeQrcode(String filePath) {
   String content = "";
   try {
     BufferedImage image = ImageIO.read(new File(filePath));
     MultiFormatReader reader = new MultiFormatReader();
     LuminanceSource source = new BufferedImageLuminanceSource(image);
     BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
     Result result = reader.decode(bitmap, getDecodeHints());
     content = result.getText();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return content;
 }
コード例 #3
0
ファイル: TextView.java プロジェクト: dirkk/basex
  /**
   * Caches the output.
   *
   * @param out cached output
   * @param c command
   * @param r result
   * @throws QueryException query exception
   */
  public void cacheText(final ArrayOutput out, final Command c, final Result r)
      throws QueryException {

    // cache command or node set
    cmd = null;
    ns = null;

    final int mh = gui.context.options.get(MainOptions.MAXHITS);
    boolean parse = false;
    if (mh >= 0 && r != null && r.size() >= mh) {
      parse = true;
    } else if (out.finished()) {
      if (r instanceof DBNodes) ns = (DBNodes) r;
      else parse = true;
    }
    // create new command instance
    if (parse) cmd = new CommandParser(c.toString(), gui.context).parseSingle();
  }
コード例 #4
0
ファイル: Lab1.java プロジェクト: smmcmanus/academic_work
  // ================================ main ===============================
  //
  // You can use command line arguments to have the output and/or input
  // come from a file versus the command line.
  //
  // If there are two arguments then the first one is the file from where
  // the input is read and the second is the file where a transcript is
  // saved.
  //
  // If there is just one argument then it is the file where a transcript
  // is saved.
  public static void main(String args[]) {
    XYPoint points[];

    if (args.length >= 1) {
      Terminal.startTranscript(args[0]);
    }
    if (args.length >= 2) {
      // Read points from file
      points = PointReader.readXYPoints(args[1]);
    } else {
      // You can change "" to something else when testing,
      // but it MUST  be "3861" for your submitted output!

      java.util.Random randseq = new java.util.Random(3861);

      // Use this line if you want a different random set of
      // points for each run.  This code uses the system
      // clock as the seed to the random number generator.
      //
      // java.util.Random randseq = new java.util.Random();

      Terminal.println("How many points? ");

      int nPoints = Terminal.readInt();

      points = genPointsAtRandom(nPoints, randseq);
    }

    XComparator lessThanX = new XComparator();
    YComparator lessThanY = new YComparator();

    Date startTime = new Date();

    //////////////////////////////////////////////////////////////////////
    // CLOSEST-PAIR ALGORITHM STARTS HERE

    // The algorithm expects two arrays containing the same points.
    XYPoint pointsByX[] = new XYPoint[points.length];
    XYPoint pointsByY[] = new XYPoint[points.length];
    for (int j = 0; j < points.length; j++) {
      pointsByX[j] = points[j];
      pointsByY[j] = points[j];
    }
    // Ensure sorting precondition for divide-and-conquer CP algorithm.
    // You should *not* have to call msort() in your own code!
    Sort.msort(pointsByX, lessThanX); // sort by x-coord
    Sort.msort(pointsByY, lessThanY); // sort by y-coord

    Result rMin = ClosestPair.findClosestPair(pointsByX, pointsByY);
    rMin.print();

    // CLOSEST-PAIR ALGORITHM ENDS HERE
    //////////////////////////////////////////////////////////////////////

    Date endTime = new Date();
    long elapsedTime = endTime.getTime() - startTime.getTime();
    Terminal.println(
        "For n = " + points.length + ", the elapsed time is " + elapsedTime + " milliseconds.\n");

    // *** NOTE: for your submitted output for Part Two, you MUST print
    // *** the closest pair of points and the distance between them!

    //////////////////////////////////////////////////////////////////////
    // THE FOLLOWING LINES DEMONSTRATE HOW TO USE THE PROVIDED
    // PLOTTER ROUTINE.  Uncomment them as you wish for debugging
    // purposes, or use them in your closest pair code to inspect
    // the point arrays at any time.  For example, you could color
    // all points in the left half red and all points in the right
    // half blue and then visually check that you divided them
    // properly by calling the plotter before you recurse.  Note
    // that if you make several calls, all the plots will
    // initially be on top of each other -- just move them so you
    // can see everything.
    //

    // Here the points are plotted and labelled by X-coordinate

    // new Plotter(pointsByY, true, "Sorted by X-coordinate");

    // Here the points are plotted and labelled by Y-coordinate

    // new Plotter(pointsByY, true, "Sorted by Y-coordinate");

    // Here's a call to the plot routine in which the points
    // aren't labeled. A nice thing to do at this point (if you
    // computed the two closest points) would be to color the two
    // closest points a different color For a XYPoint p, you could
    // color p (say red) with the line:
    //
    // p.color = Color.red;

    // new Plotter(pointsByX, true, "Output");
  }
コード例 #5
0
ファイル: SummaryTab.java プロジェクト: summerpulse/openjdk7
  synchronized Result formatSummary() {
    Result result = new Result();
    ProxyClient proxyClient = vmPanel.getProxyClient();
    if (proxyClient.isDead()) {
      return null;
    }

    buf = new StringBuilder();
    append("<table cellpadding=1>");

    try {
      RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
      CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
      ThreadMXBean tmBean = proxyClient.getThreadMXBean();
      MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
      ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
      OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
      com.sun.management.OperatingSystemMXBean sunOSMBean =
          proxyClient.getSunOperatingSystemMXBean();

      append("<tr><td colspan=4>");
      append("<center><b>" + Messages.SUMMARY_TAB_TAB_NAME + "</b></center>");
      String dateTime = headerDateTimeFormat.format(System.currentTimeMillis());
      append("<center>" + dateTime + "</center>");

      append(newDivider);

      { // VM info
        append(newLeftTable);
        append(Messages.CONNECTION_NAME, vmPanel.getDisplayName());
        append(
            Messages.VIRTUAL_MACHINE,
            Resources.format(
                Messages.SUMMARY_TAB_VM_VERSION, rmBean.getVmName(), rmBean.getVmVersion()));
        append(Messages.VENDOR, rmBean.getVmVendor());
        append(Messages.NAME, rmBean.getName());
        append(endTable);

        append(newRightTable);
        result.upTime = rmBean.getUptime();
        append(Messages.UPTIME, formatTime(result.upTime));
        if (sunOSMBean != null) {
          result.processCpuTime = sunOSMBean.getProcessCpuTime();
          append(Messages.PROCESS_CPU_TIME, formatNanoTime(result.processCpuTime));
        }

        if (cmpMBean != null) {
          append(Messages.JIT_COMPILER, cmpMBean.getName());
          append(
              Messages.TOTAL_COMPILE_TIME,
              cmpMBean.isCompilationTimeMonitoringSupported()
                  ? formatTime(cmpMBean.getTotalCompilationTime())
                  : Messages.UNAVAILABLE);
        } else {
          append(Messages.JIT_COMPILER, Messages.UNAVAILABLE);
        }
        append(endTable);
      }

      append(newDivider);

      { // Threads and Classes
        append(newLeftTable);
        int tlCount = tmBean.getThreadCount();
        int tdCount = tmBean.getDaemonThreadCount();
        int tpCount = tmBean.getPeakThreadCount();
        long ttCount = tmBean.getTotalStartedThreadCount();
        String[] strings1 =
            formatLongs(
                tlCount, tpCount,
                tdCount, ttCount);
        append(Messages.LIVE_THREADS, strings1[0]);
        append(Messages.PEAK, strings1[1]);
        append(Messages.DAEMON_THREADS, strings1[2]);
        append(Messages.TOTAL_THREADS_STARTED, strings1[3]);
        append(endTable);

        append(newRightTable);
        long clCount = clMBean.getLoadedClassCount();
        long cuCount = clMBean.getUnloadedClassCount();
        long ctCount = clMBean.getTotalLoadedClassCount();
        String[] strings2 = formatLongs(clCount, cuCount, ctCount);
        append(Messages.CURRENT_CLASSES_LOADED, strings2[0]);
        append(Messages.TOTAL_CLASSES_LOADED, strings2[2]);
        append(Messages.TOTAL_CLASSES_UNLOADED, strings2[1]);
        append(null, "");
        append(endTable);
      }

      append(newDivider);

      { // Memory
        MemoryUsage u = memoryBean.getHeapMemoryUsage();

        append(newLeftTable);
        String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
        append(Messages.CURRENT_HEAP_SIZE, strings1[0]);
        append(Messages.MAXIMUM_HEAP_SIZE, strings1[1]);
        append(endTable);

        append(newRightTable);
        String[] strings2 = formatKByteStrings(u.getCommitted());
        append(Messages.COMMITTED_MEMORY, strings2[0]);
        append(
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_LABEL,
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_VALUE,
            memoryBean.getObjectPendingFinalizationCount());
        append(endTable);

        append(newTable);
        Collection<GarbageCollectorMXBean> garbageCollectors =
            proxyClient.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
          String gcName = garbageCollectorMBean.getName();
          long gcCount = garbageCollectorMBean.getCollectionCount();
          long gcTime = garbageCollectorMBean.getCollectionTime();

          append(
              Messages.GARBAGE_COLLECTOR,
              Resources.format(
                  Messages.GC_INFO,
                  gcName,
                  gcCount,
                  (gcTime >= 0) ? formatTime(gcTime) : Messages.UNAVAILABLE),
              4);
        }
        append(endTable);
      }

      append(newDivider);

      { // Operating System info
        append(newLeftTable);
        String osName = osMBean.getName();
        String osVersion = osMBean.getVersion();
        String osArch = osMBean.getArch();
        result.nCPUs = osMBean.getAvailableProcessors();
        append(Messages.OPERATING_SYSTEM, osName + " " + osVersion);
        append(Messages.ARCHITECTURE, osArch);
        append(Messages.NUMBER_OF_PROCESSORS, result.nCPUs + "");

        if (pathSeparator == null) {
          // Must use separator of remote OS, not File.pathSeparator
          // from this local VM. In the future, consider using
          // RuntimeMXBean to get the remote system property.
          pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
        }

        if (sunOSMBean != null) {
          String[] kbStrings1 = formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());

          String[] kbStrings2 =
              formatKByteStrings(
                  sunOSMBean.getTotalPhysicalMemorySize(),
                  sunOSMBean.getFreePhysicalMemorySize(),
                  sunOSMBean.getTotalSwapSpaceSize(),
                  sunOSMBean.getFreeSwapSpaceSize());

          append(Messages.COMMITTED_VIRTUAL_MEMORY, kbStrings1[0]);
          append(endTable);

          append(newRightTable);
          append(Messages.TOTAL_PHYSICAL_MEMORY, kbStrings2[0]);
          append(Messages.FREE_PHYSICAL_MEMORY, kbStrings2[1]);
          append(Messages.TOTAL_SWAP_SPACE, kbStrings2[2]);
          append(Messages.FREE_SWAP_SPACE, kbStrings2[3]);
        }

        append(endTable);
      }

      append(newDivider);

      { // VM arguments and paths
        append(newTable);
        String args = "";
        java.util.List<String> inputArguments = rmBean.getInputArguments();
        for (String arg : inputArguments) {
          args += arg + " ";
        }
        append(Messages.VM_ARGUMENTS, args, 4);
        append(Messages.CLASS_PATH, rmBean.getClassPath(), 4);
        append(Messages.LIBRARY_PATH, rmBean.getLibraryPath(), 4);
        append(
            Messages.BOOT_CLASS_PATH,
            rmBean.isBootClassPathSupported() ? rmBean.getBootClassPath() : Messages.UNAVAILABLE,
            4);
        append(endTable);
      }
    } catch (IOException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    } catch (UndeclaredThrowableException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    }

    append("</table>");

    result.timeStamp = System.currentTimeMillis();
    result.summary = buf.toString();

    return result;
  }