예제 #1
0
  public String getLegend(String[] cityMap, int[] POIs) {
    char[] ans = new char[POIs.length];

    Hashtable hash = new Hashtable();

    for (int i = 0; i < cityMap.length; i++) {
      for (int j = 0; j < cityMap[i].length(); j++) {
        char cur = cityMap[i].charAt(j);
        int k = 1;
        if (!hash.containsKey(cur)) {
          hash.put(cur, k);
        } else {
          int prev = (int) hash.get(cur);
          hash.remove(cur);
          hash.put(cur, prev + 1);
        }
      }
    }

    Enumeration vals = hash.keys();
    while (vals.hasMoreElements()) {
      char c = (char) vals.nextElement();

      for (int i = 0; i < POIs.length; i++) {
        if (hash.get(c) == POIs[i]) {
          ans[i] = c;
        }
      }
    }

    String str = new String(ans);

    return str;
  }
예제 #2
0
 /** Description of the Method */
 public void removeAllElements() {
   for (Enumeration<BPM_Element> e = listModel.elements(); e.hasMoreElements(); ) {
     BPM_Element elm = e.nextElement();
     elm.stopMonitor();
   }
   listModel.removeAllElements();
 }
예제 #3
0
  // -------------------------------------------
  public static String[] mergeArrays(String[] sa1, String[] sa2) {
    if (sa1 == null) {
      sa1 = new String[0];
    }
    if (sa2 == null) {
      sa2 = new String[0];
    }
    int sa1Len = sa1.length;
    int sa2Len = sa2.length;
    Hashtable tab = new Hashtable(sa1Len + sa2Len);
    for (int i = 0; i < sa1Len; i++) {
      tab.put(sa1[i], sa1[i]);
    }
    for (int i = 0; i < sa2Len; i++) {
      tab.put(sa2[i], sa2[i]);
    }

    int len = tab.size();
    String[] res = new String[len];
    int i = 0;
    for (Enumeration e = tab.keys(); e.hasMoreElements(); ) {
      String s = (String) e.nextElement();
      res[i++] = s;
    }
    return res;
  }
예제 #4
0
 /** ** Prints all LocalString keys for this I18N instance */
 public void printKeyValues() {
   Enumeration e = this.getKeys();
   if (e != null) {
     for (; e.hasMoreElements(); ) {
       String k = (String) e.nextElement();
       String v = this.getString(k, "?");
       Print.logInfo("Key:" + k + " Value:" + v);
     }
   }
 }
 /*
  * Applet is no longer displayed
  */
 public void stop() {
   // Tell all pages to stop talking to the server
   Enumeration e = pages.elements();
   while (e.hasMoreElements()) {
     SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement();
     if (pg != null) {
       pg.stop();
     }
   }
 }
예제 #6
0
 /**
  * Returns the bPM attribute of the BPMsTable object
  *
  * @param name The Parameter
  * @return The bPM value
  */
 public BPM_Element getBPM(String name) {
   BPM_Element bpmElm = null;
   Enumeration<BPM_Element> bpm_enum = listModel.elements();
   while (bpm_enum.hasMoreElements()) {
     BPM_Element bpmElm1 = bpm_enum.nextElement();
     if (bpmElm1.getName().equals(name)) {
       bpmElm = bpmElm1;
     }
   }
   return bpmElm;
 }
 /** Check if soap data matches filter */
 public boolean filterMatch(SOAPMonitorData soap) {
   boolean match = true;
   if (filter_include != null) {
     // Check for service match
     Enumeration e = filter_include.elements();
     match = false;
     while (e.hasMoreElements() && !match) {
       String service = (String) e.nextElement();
       if (service.equals(soap.getTargetService())) {
         match = true;
       }
     }
   }
   if (filter_exclude != null) {
     // Check for service match
     Enumeration e = filter_exclude.elements();
     while (e.hasMoreElements() && match) {
       String service = (String) e.nextElement();
       if (service.equals(soap.getTargetService())) {
         match = false;
       }
     }
   }
   if (filter_active) {
     // Check for active status match
     if (soap.getSOAPResponse() != null) {
       match = false;
     }
   }
   if (filter_complete) {
     // Check for complete status match
     if (soap.getSOAPResponse() == null) {
       match = false;
     }
   }
   // The "most recent" is always a match
   if (soap.getId() == null) {
     match = true;
   }
   return match;
 }
예제 #8
0
 /**
  * Helper method to convert properties to string.
  *
  * @param prop a <code>Properties</code> value
  * @return a <code>String</code> value
  */
 public static String convertPropsToString(Properties prop) {
   if (prop == null) {
     return "{null}";
   }
   StringBuffer strBuf = new StringBuffer("{ ");
   for (Enumeration enum1 = prop.propertyNames(); enum1.hasMoreElements(); ) {
     Object obj = enum1.nextElement();
     strBuf.append("[ ").append(obj).append("->");
     Object val = prop.getProperty((String) obj);
     if (val == null) strBuf.append("null");
     else strBuf.append((String) val);
     strBuf.append(" ] ");
   }
   strBuf.append("}");
   return strBuf.toString();
 }
예제 #9
0
파일: Macro.java 프로젝트: bramk/bnd
 /**
  * Take all the properties and translate them to actual values. This method takes the set
  * properties and traverse them over all entries, including the default properties for that
  * properties. The values no longer contain macros.
  *
  * @return A new Properties with the flattened values
  */
 public Properties getFlattenedProperties() {
   // Some macros only work in a lower processor, so we
   // do not report unknown macros while flattening
   flattening = true;
   try {
     Properties flattened = new Properties();
     Properties source = domain.getProperties();
     for (Enumeration<?> e = source.propertyNames(); e.hasMoreElements(); ) {
       String key = (String) e.nextElement();
       if (!key.startsWith("_"))
         if (key.startsWith("-")) flattened.put(key, source.getProperty(key));
         else flattened.put(key, process(source.getProperty(key)));
     }
     return flattened;
   } finally {
     flattening = false;
   }
 }
 /** Refilter the list of messages */
 public void applyFilter() {
   // Re-filter using new criteria
   filter_data = null;
   if ((filter_include != null)
       || (filter_exclude != null)
       || filter_active
       || filter_complete) {
     filter_data = new Vector();
     Enumeration e = data.elements();
     SOAPMonitorData soap;
     while (e.hasMoreElements()) {
       soap = (SOAPMonitorData) e.nextElement();
       if (filterMatch(soap)) {
         filter_data.addElement(soap);
       }
     }
   }
   fireTableDataChanged();
 }
예제 #11
0
  public String verify(JarFile jar, String... algorithms) throws IOException {
    if (algorithms == null || algorithms.length == 0) algorithms = new String[] {"MD5", "SHA"};
    else if (algorithms.length == 1 && algorithms[0].equals("-")) return null;

    try {
      Manifest m = jar.getManifest();
      if (m.getEntries().isEmpty()) return "No name sections";

      for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ) {
        JarEntry je = e.nextElement();
        if (MANIFEST_ENTRY.matcher(je.getName()).matches()) continue;

        Attributes nameSection = m.getAttributes(je.getName());
        if (nameSection == null) return "No name section for " + je.getName();

        for (String algorithm : algorithms) {
          try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            String expected = nameSection.getValue(algorithm + "-Digest");
            if (expected != null) {
              byte digest[] = Base64.decodeBase64(expected);
              copy(jar.getInputStream(je), md);
              if (!Arrays.equals(digest, md.digest()))
                return "Invalid digest for "
                    + je.getName()
                    + ", "
                    + expected
                    + " != "
                    + Base64.encodeBase64(md.digest());
            } else reporter.error("could not find digest for " + algorithm + "-Digest");
          } catch (NoSuchAlgorithmException nsae) {
            return "Missing digest algorithm " + algorithm;
          }
        }
      }
    } catch (Exception e) {
      return "Failed to verify due to exception: " + e.getMessage();
    }
    return null;
  }
  static void writeUsersToFile() {
    userWriter = createCSVFile("Users.dat");
    // write the list of users to file
    System.out.println("Users that are both seller and buyer BUT different ratings: ");
    Enumeration<String> keys = userList.keys();
    while (keys.hasMoreElements()) {
      String curUserID = keys.nextElement();
      String curUser[] = userList.get(curUserID);
      String userRow =
          wrapQuotations(curUser[0])
              + ","
              + curUser[1]
              + ","
              + curUser[2]
              + ","
              + wrapQuotations(curUser[3])
              + ","
              + wrapQuotations(curUser[4]);
      writeLine(userWriter, userRow);
      // if(curUser[1] != null && curUser[2] != null && !curUser[1].equals(curUser[2]))
      //    System.out.println(curUser[0]);
    }
    System.out.println("----end different ratings----");

    // System.out.println("The users that are both seller and buyer: ");
    // Enumeration<String> both = bothSellerAndBuyer.elements();
    // while(both.hasMoreElements()) {
    //    System.out.println(both.nextElement());
    // }
    // System.out.println("----end both----");

    try {
      userWriter.flush();
      userWriter.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public Response serve(String uri, String method, Properties header, Properties parms) {
    if (!uri.equals("/mediaserver")) {
      return super.serve(uri, method, header, parms); // this way we can
      // also serve up
      // normal files and
      // content
    }

    logger.fine(method + " '" + uri + "' ");

    Enumeration<?> e = header.propertyNames();
    while (e.hasMoreElements()) {
      String value = (String) e.nextElement();
      logger.fine("  HDR: '" + value + "' = '" + header.getProperty(value) + "'");
    }
    e = parms.propertyNames();
    while (e.hasMoreElements()) {
      String value = (String) e.nextElement();
      logger.fine("  PRM: '" + value + "' = '" + parms.getProperty(value) + "'");
    }

    // TODO: check the actual path...

    final String mediaPath = parms.getProperty("media");
    final String outputFormatStr = parms.getProperty("format");
    final String mimeType = parms.getProperty("mime");
    logger.info("requested media: " + mediaPath);
    logger.info("requested mime type: " + mimeType);
    if (mediaPath == null)
      return new Response(HTTP_FORBIDDEN, "text/plain", "mediaPath parameter not specified");
    if (mimeType == null)
      return new Response(HTTP_FORBIDDEN, "text/plain", "mimeType parameter not specified");

    // TODO: if we aren't performing any transcoding, just serve the file up
    // directly.
    // TODO: capture sources need to be treated as singletons, with some
    // kind of broadcasting/cloning to ensure
    // that multiple connections can be made.

    final String serverSideUrlStr = mediaPath; // URLUtils.createUrlStr(new
    // File(mediaPath)); // TODO:
    // enforce that we can't just
    // serve up anything anywhere
    final ContentDescriptor outputContentDescriptor =
        new FileTypeDescriptor(ContentDescriptor.mimeTypeToPackageName(mimeType));

    final Format outputFormat;
    if (outputFormatStr == null) {
      outputFormat = null;
    } else {
      try {
        outputFormat = FormatArgUtils.parse(outputFormatStr);
      } catch (ParseException e1) {
        logger.log(Level.WARNING, "" + e1, e1);
        return new Response(HTTP_FORBIDDEN, "text/plain", "" + e1);
      }
    }

    logger.info("serverSideUrlStr: " + serverSideUrlStr);
    logger.info("outputContentDescriptor: " + outputContentDescriptor);
    logger.info("outputFormat: " + outputFormat);

    final InputStream is;
    try {
      is = getInputStream(serverSideUrlStr, outputFormat, outputContentDescriptor);
    } catch (Exception e1) {
      return new Response(HTTP_FORBIDDEN, "text/plain", "" + e1);
    }

    final String responseMimeType;
    // workaround for the problem that the multipart/x-mixed-replace
    // boundary is not stored anywhere.
    // this assumes that if we are serving multipart/x-mixed-replace data,
    // that MultipartMixedReplaceMux is being used.
    if (mimeType.equals("multipart/x-mixed-replace"))
      responseMimeType = mimeType + ";boundary=" + MultipartMixedReplaceMux.BOUNDARY;
    else responseMimeType = mimeType;
    logger.info("Response mime type: " + responseMimeType);
    return new Response(HTTP_OK, responseMimeType, is);
  }
예제 #14
0
 /** Description of the Method */
 public void startMonitor() {
   for (Enumeration<BPM_Element> e = listModel.elements(); e.hasMoreElements(); ) {
     BPM_Element elm = e.nextElement();
     elm.startMonitor();
   }
 }