Example #1
1
  /**
   * Returns the value of the component
   *
   * @param nLineInd index of the line in the file.
   */
  protected String getValue(int nLineInd) {
    JComponent comp = null;
    String strValue = null;

    // Get the component corresponding to the line of the file from the list.
    if (nLineInd < m_aListComp.size()) {
      comp = (JComponent) m_aListComp.get(nLineInd);
    }

    if (comp == null) return strValue;

    // Get the value of the component
    if (comp instanceof JTextField) strValue = ((JTextField) comp).getText();
    else if (comp instanceof JCheckBox) strValue = ((JCheckBox) comp).isSelected() ? "yes" : "no";
    else if (comp instanceof JComboBox) strValue = (String) ((JComboBox) comp).getSelectedItem();

    // if the value is of the form: $home, then parse the value
    /*if (strValue.indexOf('$') >= 0)
    {
        String strNewValue = WFileUtil.parseValue(strValue, new HashMap());
        if (strNewValue != null && strNewValue.trim().length() > 0)
            strValue = strNewValue;
    }*/

    return strValue;
  }
Example #2
0
  /**
   * Parse a method declaration. The declaration should be in the following format:
   *
   * <p>fully-qualified-method-name (args)
   *
   * <p>where the arguments are comma separated and all arguments other than primitives should have
   * fully qualified names. Arrays are indicating by trailing brackets. For example:
   *
   * <p>int int[] int[][] java.lang.String java.util.Date[]
   *
   * <p>The arguments are translated into BCEL types and a MethodDef is returned.
   */
  private MethodDef parse_method(StrTok st) {

    // Get the method name
    String method_name = st.need_word();

    // Get the opening paren
    st.need("(");

    // Read the arguments
    ArrayList<String> args = new ArrayList<String>();
    String tok = st.nextToken();
    if (tok != ")") {
      st.pushBack();
      do {
        tok = st.need_word();
        args.add(tok);
      } while (st.nextToken() == ",");
      st.pushBack();
      st.need(")");
    }

    // Convert the arguments to Type
    Type[] targs = new Type[args.size()];
    for (int ii = 0; ii < args.size(); ii++) {
      targs[ii] = BCELUtil.classname_to_type(args.get(ii));
    }

    return new MethodDef(method_name, targs);
  }
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
 protected void compile(
     SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
   if (compilingFirstGroup && additionalUnits != null) {
     // add any source file from additionalUnits to units if it defines secondary types
     // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type
     // can cause an infinite loop as it alternates between not found and defined, see bug 146324
     ArrayList extras = null;
     for (int i = 0, l = additionalUnits.length; i < l; i++) {
       SourceFile unit = additionalUnits[i];
       if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) {
         if (JavaBuilder.DEBUG)
           System.out.println(
               "About to compile file with secondary types " + unit.typeLocator()); // $NON-NLS-1$
         if (extras == null) extras = new ArrayList(3);
         extras.add(unit);
       }
     }
     if (extras != null) {
       int oldLength = units.length;
       int toAdd = extras.size();
       System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength);
       for (int i = 0; i < toAdd; i++) units[oldLength++] = (SourceFile) extras.get(i);
     }
   }
   super.compile(units, additionalUnits, compilingFirstGroup);
 }
Example #5
0
  public MoquiStart(ClassLoader parent, boolean loadWebInf) {
    super(parent);
    this.loadWebInf = loadWebInf;

    URL wrapperWarUrl = null;
    try {
      // get outer file (the war file)
      pd = getClass().getProtectionDomain();
      CodeSource cs = pd.getCodeSource();
      wrapperWarUrl = cs.getLocation();
      outerFile = new JarFile(new File(wrapperWarUrl.toURI()));

      // allow for classes in the outerFile as well
      jarFileList.add(outerFile);

      Enumeration<JarEntry> jarEntries = outerFile.entries();
      while (jarEntries.hasMoreElements()) {
        JarEntry je = jarEntries.nextElement();
        if (je.isDirectory()) continue;
        // if we aren't loading the WEB-INF files and it is one, skip it
        if (!loadWebInf && je.getName().startsWith("WEB-INF")) continue;
        // get jars, can be anywhere in the file
        String jeName = je.getName().toLowerCase();
        if (jeName.lastIndexOf(".jar") == jeName.length() - 4) {
          File file = createTempFile(je);
          jarFileList.add(new JarFile(file));
        }
      }
    } catch (Exception e) {
      System.out.println("Error loading jars in war file [" + wrapperWarUrl + "]: " + e.toString());
    }
  }
 public List<DirectoryScanner> partition(int count) {
   ArrayList<DirectoryScanner> partitions = Lists.newArrayListWithExpectedSize(count);
   for (int i = 0; i < count; i++) {
     partitions.add(this.createPartition(i, count));
   }
   return partitions;
 }
Example #7
0
  private WyilFile.MethodDeclaration readMethodBlock() throws IOException {
    int nameIdx = input.read_uv();
    // System.out.println("=== METHOD " + stringPool.get(nameIdx));
    int modifiers = input.read_uv();
    int typeIdx = input.read_uv();
    int numCases = input.read_uv();

    input.pad_u8();

    Type.Method type = (Type.Method) typePool[typeIdx];
    ArrayList<WyilFile.Case> cases = new ArrayList<WyilFile.Case>();
    for (int i = 0; i != numCases; ++i) {
      int kind = input.read_uv(); // unsued
      int size = input.read_uv();
      input.pad_u8();

      switch (kind) {
        case WyilFileWriter.BLOCK_Case:
          cases.add(readFunctionOrMethodCase(type));
          break;
        default:
          throw new RuntimeException("Unknown method block encountered");
      }
    }
    return new WyilFile.MethodDeclaration(
        generateModifiers(modifiers), stringPool[nameIdx], type, cases);
  }
Example #8
0
 private static ArrayList<Item> getArrayList(int n) {
   ArrayList<Item> result = new ArrayList<Item>();
   for (Item it : dicts) {
     if (it.str.length() == n) result.add(it);
   }
   return result;
 }
Example #9
0
  /*
   * Get the active protocol versions.
   *
   * In TLS 1.1, many weak or vulnerable cipher suites were obsoleted,
   * such as TLS_RSA_EXPORT_WITH_RC4_40_MD5. The implementation MUST NOT
   * negotiate these cipher suites in TLS 1.1 or later mode.
   *
   * For example, if "TLS_RSA_EXPORT_WITH_RC4_40_MD5" is the
   * only enabled cipher suite, the client cannot request TLS 1.1 or
   * later, even though TLS 1.1 or later is enabled.  We need to create a
   * subset of the enabled protocols, called the active protocols, which
   * contains protocols appropriate to the list of enabled Ciphersuites.
   *
   * Return empty list instead of null if no active protocol versions.
   */
  ProtocolList getActiveProtocols() {
    if (activeProtocols == null) {
      ArrayList<ProtocolVersion> protocols = new ArrayList<>(4);
      for (ProtocolVersion protocol : enabledProtocols.collection()) {
        boolean found = false;
        for (CipherSuite suite : enabledCipherSuites.collection()) {
          if (suite.isAvailable()
              && suite.obsoleted > protocol.v
              && suite.supported <= protocol.v) {
            if (algorithmConstraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), suite.name, null)) {
              protocols.add(protocol);
              found = true;
              break;
            } else if (debug != null && Debug.isOn("verbose")) {
              System.out.println("Ignoring disabled cipher suite: " + suite + " for " + protocol);
            }
          } else if (debug != null && Debug.isOn("verbose")) {
            System.out.println("Ignoring unsupported cipher suite: " + suite + " for " + protocol);
          }
        }
        if (!found && (debug != null) && Debug.isOn("handshake")) {
          System.out.println("No available cipher suite for " + protocol);
        }
      }
      activeProtocols = new ProtocolList(protocols);
    }

    return activeProtocols;
  }
Example #10
0
  /**
   * Get the active cipher suites.
   *
   * <p>In TLS 1.1, many weak or vulnerable cipher suites were obsoleted, such as
   * TLS_RSA_EXPORT_WITH_RC4_40_MD5. The implementation MUST NOT negotiate these cipher suites in
   * TLS 1.1 or later mode.
   *
   * <p>Therefore, when the active protocols only include TLS 1.1 or later, the client cannot
   * request to negotiate those obsoleted cipher suites. That is, the obsoleted suites should not be
   * included in the client hello. So we need to create a subset of the enabled cipher suites, the
   * active cipher suites, which does not contain obsoleted cipher suites of the minimum active
   * protocol.
   *
   * <p>Return empty list instead of null if no active cipher suites.
   */
  CipherSuiteList getActiveCipherSuites() {
    if (activeCipherSuites == null) {
      if (activeProtocols == null) {
        activeProtocols = getActiveProtocols();
      }

      ArrayList<CipherSuite> suites = new ArrayList<>();
      if (!(activeProtocols.collection().isEmpty())
          && activeProtocols.min.v != ProtocolVersion.NONE.v) {
        for (CipherSuite suite : enabledCipherSuites.collection()) {
          if (suite.obsoleted > activeProtocols.min.v && suite.supported <= activeProtocols.max.v) {
            if (algorithmConstraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), suite.name, null)) {
              suites.add(suite);
            }
          } else if (debug != null && Debug.isOn("verbose")) {
            if (suite.obsoleted <= activeProtocols.min.v) {
              System.out.println("Ignoring obsoleted cipher suite: " + suite);
            } else {
              System.out.println("Ignoring unsupported cipher suite: " + suite);
            }
          }
        }
      }
      activeCipherSuites = new CipherSuiteList(suites);
    }

    return activeCipherSuites;
  }
Example #11
0
    // specify input and out keys
    public void map(
        LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
      String line = value.toString(); // define new variable to be string

      ArrayList<Integer> range = new ArrayList<Integer>();
      for (int i = 2000; i <= 2010; i++) {
        range.add(i);
      }

      // String[] inputs = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
      String[] inputs = line.split(",");

      try {

        int year = Integer.parseInt(inputs[165]);

        if (range.contains(year)) {
          String dur = inputs[3];
          String artist_name = inputs[2];
          String song_title = inputs[1];
          String final_input = artist_name + ',' + dur + ',' + song_title;
          Final_Value.set(final_input);
          output.collect(Final_Value, dummy);
        }
      } catch (NumberFormatException e) {
        // do nothing
      }
    }
Example #12
0
 /**
  * read AIMLIF categories from a file into bot brain
  *
  * @param filename name of AIMLIF file
  * @return array list of categories read
  */
 public ArrayList<Category> readIFCategories(String filename) {
   ArrayList<Category> categories = new ArrayList<Category>();
   try {
     // Open the file that is the first
     // command line parameter
     FileInputStream fstream = new FileInputStream(filename);
     // Get the object
     BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
     String strLine;
     // Read File Line By Line
     while ((strLine = br.readLine()) != null) {
       try {
         Category c = Category.IFToCategory(strLine);
         categories.add(c);
       } catch (Exception ex) {
         System.out.println("Invalid AIMLIF in " + filename + " line " + strLine);
       }
     }
     // Close the input stream
     br.close();
   } catch (Exception e) { // Catch exception if any
     System.err.println("Error: " + e.getMessage());
   }
   return categories;
 }
Example #13
0
  public WDBObject[] search(SimpleNode expression, Adapter scda) throws Exception {
    boolean hasWhereClause = (expression != null);
    WDBObject[] matchesArray = new WDBObject[0];
    ArrayList<WDBObject> matchesList = new ArrayList<WDBObject>();
    WDBObject[] indexFilteredArray;
    if (hasWhereClause) {
      indexFilteredArray =
          expression
              .filterObjectsWithIndexes(scda, this.indexes)
              .getFilteredResults(scda, this.indexes);
    } else {
      indexFilteredArray = null;
    }
    if (indexFilteredArray == null) {
      // Simple for loop for search
      WDBObject object;
      for (int i = 0; i < this.instances.size(); i++) {
        object = this.getInstance(i, scda);
        if (!hasWhereClause || (hasWhereClause && expression.eval(scda, object))) {
          matchesList.add(object);
        }
      }
    } else {
      // Simple for loop for search
      for (int i = 0; i < indexFilteredArray.length; i++) {
        if (!hasWhereClause || (hasWhereClause && expression.eval(scda, indexFilteredArray[i]))) {
          matchesList.add(indexFilteredArray[i]);
        }
      }
    }

    return (WDBObject[]) matchesList.toArray(matchesArray);
  }
Example #14
0
 /** Return a list of all tests of the given type, according to the current filters */
 public List<Resource> findTestsOfType(Resource testType) {
   ArrayList<Resource> result = new ArrayList<>();
   StmtIterator si = testDefinitions.listStatements(null, RDF.type, testType);
   while (si.hasNext()) {
     Resource test = si.nextStatement().getSubject();
     boolean accept = true;
     // Check test status
     Literal status = (Literal) test.getProperty(RDFTest.status).getObject();
     if (approvedOnly) {
       accept = status.getString().equals(STATUS_FLAGS[0]);
     } else {
       accept = false;
       for (String STATUS_FLAG : STATUS_FLAGS) {
         if (status.getString().equals(STATUS_FLAG)) {
           accept = true;
           break;
         }
       }
     }
     // Check for blocked tests
     for (String BLOCKED_TEST : BLOCKED_TESTS) {
       if (BLOCKED_TEST.equals(test.toString())) {
         accept = false;
       }
     }
     // End of filter tests
     if (accept) {
       result.add(test);
     }
   }
   return result;
 }
 public boolean comparePrefix(String prefixCode, String prefixCodeWithProc) {
   try {
     boolean flag = false;
     String prefixBreak[] = prefixCode.split("#");
     String prefixProcBreak[] = prefixCodeWithProc.split("#");
     for (String str : prefixBreak) {
       flag = false;
       for (int i = 0; i < prefixProcBreak.length; i++) {
         if (prefixProcBreak[i].equals(str)) {
           flag = true;
           prefixProcBreak[i] = "-1";
           break;
         }
       }
       if (!flag) return false;
     }
     if (prefixCode.length() == prefixCodeWithProc.length()) {
       procList.clear();
       procList.add(prefixCodeWithProc);
       return true;
     } else procList.add(prefixCodeWithProc);
   } catch (Exception ed) {
   }
   return false;
 }
  /**
   * Removes an attribute from the servlet context.
   *
   * @param name the name of the attribute to remove.
   */
  public void removeAttribute(String name) {
    Object oldValue;

    synchronized (_attributes) {
      oldValue = _attributes.remove(name);
    }

    // Call any listeners
    if (_applicationAttributeListeners != null) {
      ServletContextAttributeEvent event;

      event = new ServletContextAttributeEvent(this, name, oldValue);

      for (int i = 0; i < _applicationAttributeListeners.size(); i++) {
        ServletContextAttributeListener listener;

        Object objListener = _applicationAttributeListeners.get(i);
        listener = (ServletContextAttributeListener) objListener;

        try {
          listener.attributeRemoved(event);
        } catch (Throwable e) {
          log.log(Level.FINE, e.toString(), e);
        }
      }
    }
  }
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
  /**
   * ************************************************************************* loadHashFromFile -
   * loads a hastable from a file the format of the file is inflected_word base_form with a space
   * between both words ************************************************************************
   */
  private HashMap<String, ArrayList<String>> loadHashFromFile(String filename) {
    HashMap<String, ArrayList<String>> hashtable = new HashMap<String, ArrayList<String>>();

    try {
      BufferedReader br = new BufferedReader(new FileReader(filename));
      StringTokenizer st;

      for (; ; ) {

        String line = br.readLine();

        if (line == null) {
          br.close();
          break;
        } else {
          st = new StringTokenizer(line, " ");
          ArrayList<String> baseList = new ArrayList<String>();
          String inflected = st.nextToken();
          while (st.hasMoreTokens()) {
            baseList.add(st.nextToken());
          }
          hashtable.put(inflected, baseList);
        }
      }
    } catch (Exception e) {
      // System.out.println(line);
      System.out.println("Error:" + e);
    }

    return hashtable;
  }
Example #19
0
 /**
  * Gets the object whose index is the integer argument.
  *
  * @param i the integer index to be queried for the corresponding argument
  * @return the object whose index is the integer argument.
  */
 @Override
 public E get(int i) {
   if (i < 0 || i >= objects.size())
     throw new ArrayIndexOutOfBoundsException(
         "Index " + i + " outside the bounds [0," + size() + ")");
   return objects.get(i);
 }
Example #20
0
  /**
   * @param args
   * @throws FileNotFoundException
   */
  public static void main(String[] args) throws FileNotFoundException {
    // TODO Auto-generated method stub
    System.out.println("Swim Meet Planner");

    // scanner to read file
    Scanner fileReader = new Scanner(new File("src/Finalprojectinput"));

    // create results Map
    HashMap<String, ArrayList<Integer>> results = new HashMap<String, ArrayList<Integer>>();

    // adding names and times to results Map
    while (fileReader.hasNext()) {
      String name = fileReader.next();
      int time = fileReader.nextInt();
      // does swimmer exist in map?
      if (results.containsKey(name)) {
        results.get(name).add(time);

      } else {
        ArrayList<Integer> times = new ArrayList<Integer>();
        times.add(time);
        results.put(name, times);
      }
    }
    fileReader.close();
    Average a = new Average();
    a.average(results);
  }
 public static void main(String[] args) throws IOException {
   BufferedReader f = new BufferedReader(new FileReader("barn1.in"));
   out = new PrintWriter(new BufferedWriter(new FileWriter("barn1.out")));
   StringTokenizer nstr = new StringTokenizer(f.readLine());
   int m = Integer.parseInt(nstr.nextToken());
   int s = Integer.parseInt(nstr.nextToken());
   occupied = new ArrayList<ArrayList<Integer>>();
   occupied.add(new ArrayList<Integer>());
   for (int i = 0; i < s; i++) {
     try {
       nstr = new StringTokenizer(f.readLine());
       occupied.get(0).add(Integer.parseInt(nstr.nextToken()));
     } catch (NullPointerException e) {
       break;
     }
   }
   Collections.sort(occupied.get(0));
   int bound = m - 1;
   if (occupied.get(0).size() - 1 < bound) {
     bound = occupied.get(0).size() - 1;
   }
   for (int i = 0; i < bound; i++) {
     findMaxCut();
   }
   int total = 0;
   int len = occupied.size();
   for (int i = 0; i < len; i++) {
     ArrayList<Integer> arr = occupied.get(i);
     int len2 = arr.size();
     total += arr.get(len2 - 1) - arr.get(0) + 1;
   }
   out.println(total);
   out.close();
   System.exit(0);
 }
  static void eliminarLugarFicheroLOC(Lugar lugar) {
    String fichero = lugar.getFicheroLOC();

    try {
      FileReader fr = new FileReader(fichero);
      BufferedReader br = new BufferedReader(fr);

      String linea;
      ArrayList lineas = new ArrayList();

      do {
        linea = br.readLine();
        if (linea != null) {
          if (!linea.substring(0, lugar.nombre.length()).equals(lugar.nombre)) lineas.add(linea);
        } else break;
      } while (true);
      br.close();
      fr.close();

      FileOutputStream fos = new FileOutputStream(fichero);
      PrintWriter pw = new PrintWriter(fos);

      for (int i = 0; i < lineas.size(); i++) pw.println((String) lineas.get(i));
      pw.flush();
      pw.close();
      fos.close();

    } catch (FileNotFoundException e) {
      System.err.println("error: eliminando " + e);

    } catch (IOException e) {
      System.err.println("error: eliminando 2 : " + e);
    }
  }
 public static IpnbCellRaw fromCell(@NotNull final IpnbCell cell, int nbformat) {
   final IpnbCellRaw raw = new IpnbCellRaw();
   if (cell instanceof IpnbEditableCell) {
     raw.metadata = ((IpnbEditableCell) cell).getMetadata();
   }
   if (cell instanceof IpnbMarkdownCell) {
     raw.cell_type = "markdown";
     raw.source = ((IpnbMarkdownCell) cell).getSource();
   } else if (cell instanceof IpnbCodeCell) {
     raw.cell_type = "code";
     final ArrayList<CellOutputRaw> outputRaws = new ArrayList<CellOutputRaw>();
     for (IpnbOutputCell outputCell : ((IpnbCodeCell) cell).getCellOutputs()) {
       outputRaws.add(CellOutputRaw.fromOutput(outputCell, nbformat));
     }
     raw.outputs = outputRaws;
     final Integer promptNumber = ((IpnbCodeCell) cell).getPromptNumber();
     if (nbformat == 4) {
       raw.execution_count = promptNumber != null && promptNumber >= 0 ? promptNumber : null;
       raw.source = ((IpnbCodeCell) cell).getSource();
     } else {
       raw.prompt_number = promptNumber != null && promptNumber >= 0 ? promptNumber : null;
       raw.language = ((IpnbCodeCell) cell).getLanguage();
       raw.input = ((IpnbCodeCell) cell).getSource();
     }
   } else if (cell instanceof IpnbRawCell) {
     raw.cell_type = "raw";
     raw.source = ((IpnbRawCell) cell).getSource();
   } else if (cell instanceof IpnbHeadingCell) {
     raw.cell_type = "heading";
     raw.source = ((IpnbHeadingCell) cell).getSource();
     raw.level = ((IpnbHeadingCell) cell).getLevel();
   }
   return raw;
 }
Example #24
0
 public void dfs(int v) {
   if (hasCycle) {
     return;
   }
   if (color[v] != 2) {
     color[v] = 1;
     if (graph[v] == null) {
       color[v] = 2;
       answer.add(v);
       return;
     }
     for (int i = 0; i < graph[v].size(); i++) {
       int to = graph[v].get(i);
       if (color[to] == 0) {
         dfs(to);
       }
       if (color[to] == 1) {
         hasCycle = true;
         return;
       }
     }
     color[v] = 2;
     answer.add(v);
   }
 }
Example #25
0
 /** @see java.lang.ClassLoader#findResources(java.lang.String) */
 @Override
 public Enumeration<URL> findResources(String resourceName) throws IOException {
   String webInfResourceName = "WEB-INF/classes/" + resourceName;
   List<URL> urlList = new ArrayList<URL>();
   int jarFileListSize = jarFileList.size();
   for (int i = 0; i < jarFileListSize; i++) {
     JarFile jarFile = jarFileList.get(i);
     JarEntry jarEntry = jarFile.getJarEntry(resourceName);
     // to better support war format, look for the resourceName in the WEB-INF/classes directory
     if (loadWebInf && jarEntry == null) jarEntry = jarFile.getJarEntry(webInfResourceName);
     if (jarEntry != null) {
       try {
         String jarFileName = jarFile.getName();
         if (jarFileName.contains("\\")) jarFileName = jarFileName.replace('\\', '/');
         urlList.add(new URL("jar:file:" + jarFileName + "!/" + jarEntry));
       } catch (MalformedURLException e) {
         System.out.println(
             "Error making URL for ["
                 + resourceName
                 + "] in jar ["
                 + jarFile
                 + "] in war file ["
                 + outerFile
                 + "]: "
                 + e.toString());
       }
     }
   }
   // add all resources found in parent loader too
   Enumeration<URL> superResources = super.findResources(resourceName);
   while (superResources.hasMoreElements()) urlList.add(superResources.nextElement());
   return Collections.enumeration(urlList);
 }
Example #26
0
 /**
  * Returns all editors.
  *
  * @return editors
  */
 EditorArea[] editors() {
   final ArrayList<EditorArea> edits = new ArrayList<EditorArea>();
   for (final Component c : tabs.getComponents()) {
     if (c instanceof EditorArea) edits.add((EditorArea) c);
   }
   return edits.toArray(new EditorArea[edits.size()]);
 }
  protected void finishedWith(
      String sourceLocator,
      CompilationResult result,
      char[] mainTypeName,
      ArrayList definedTypeNames,
      ArrayList duplicateTypeNames) {
    char[][] previousTypeNames = this.newState.getDefinedTypeNamesFor(sourceLocator);
    if (previousTypeNames == null) previousTypeNames = new char[][] {mainTypeName};
    IPath packagePath = null;
    next:
    for (int i = 0, l = previousTypeNames.length; i < l; i++) {
      char[] previous = previousTypeNames[i];
      for (int j = 0, m = definedTypeNames.size(); j < m; j++)
        if (CharOperation.equals(previous, (char[]) definedTypeNames.get(j))) continue next;

      SourceFile sourceFile = (SourceFile) result.getCompilationUnit();
      if (packagePath == null) {
        int count = sourceFile.sourceLocation.sourceFolder.getFullPath().segmentCount();
        packagePath =
            sourceFile.resource.getFullPath().removeFirstSegments(count).removeLastSegments(1);
      }
      if (this.secondaryTypesToRemove == null)
        this.secondaryTypesToRemove = new SimpleLookupTable();
      ArrayList types =
          (ArrayList) this.secondaryTypesToRemove.get(sourceFile.sourceLocation.binaryFolder);
      if (types == null) types = new ArrayList(definedTypeNames.size());
      types.add(packagePath.append(new String(previous)));
      this.secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types);
    }
    super.finishedWith(sourceLocator, result, mainTypeName, definedTypeNames, duplicateTypeNames);
  }
  /**
   * Sets an application attribute.
   *
   * @param name the name of the attribute
   * @param value the value of the attribute
   */
  public void setAttribute(String name, Object value) {
    Object oldValue;

    synchronized (_attributes) {
      if (value != null) oldValue = _attributes.put(name, value);
      else oldValue = _attributes.remove(name);
    }

    // Call any listeners
    if (_applicationAttributeListeners != null) {
      ServletContextAttributeEvent event;

      if (oldValue != null) event = new ServletContextAttributeEvent(this, name, oldValue);
      else event = new ServletContextAttributeEvent(this, name, value);

      for (int i = 0; i < _applicationAttributeListeners.size(); i++) {
        ServletContextAttributeListener listener;

        Object objListener = _applicationAttributeListeners.get(i);
        listener = (ServletContextAttributeListener) objListener;

        try {
          if (oldValue != null) listener.attributeReplaced(event);
          else listener.attributeAdded(event);
        } catch (Exception e) {
          log.log(Level.FINE, e.toString(), e);
        }
      }
    }
  }
  public void createBuildings() {
    bList = new ArrayList<Building>();

    // resource
    bList.add(new Building("Gold Mine", 3, 3, 960, 7));
    bList.add(new Building("Elixir Collector", 3, 3, 960, 7));
    // bList.add(new Building("Dark Elixir Drill", 3, 3, 1160, 3));
    bList.add(new Building("Gold Storage", 3, 3, 2100, 4));
    bList.add(new Building("Elixir Storage", 3, 3, 2100, 4));
    // bList.add(new Building("Dark Elixir Storage", 3, 3, 3200, 1));
    // bList.add(new Building("Builder Hut", 2, 2, 250, 5));

    // army
    bList.add(new Building("Army Camp", 5, 5, 500, 4));
    bList.add(new Building("Barracks", 3, 3, 860, 4));
    // bList.add(new Building("Dark Barracks", 3, 3, 900, 2));
    // bList.add(new Building("Laboratory", 4, 4, 950, 1));
    // bList.add(new Building("Spell Factory", 3, 3, 615, 1));
    // bList.add(new Building("Barbarian King Altar", 3, 3, 250, 1));
    // bList.add(new Building("Dark Spell Factory", 3, 3, 750, 1));
    // bList.add(new Building("Archer Queen Altar", 3, 3, 250, 1));

    // other
    bList.add(new Building("Town Hall", 4, 4, 5500, 1));
    bList.add(new Building("Clan Castle", 3, 3, 3400, 1));

    // defense
    bList.add(new Building("Archer Tower", 3, 3, 1050, 7));
    bList.add(new Building("Cannon", 3, 3, 1260, 6));
    bList.add(new Building("Wall", 1, 1, 7000, 275));
    // bList.add(new Building("Air Sweeper", 2, 2, 1000, 2));
    // bList.add(new Building("Cannon", 3, 3, 1260, 6));
    // bList.add(new Building("Cannon", 3, 3, 1260, 6));
  }
  public static void main(final String[] args) throws FileNotFoundException {
    if (args.length == 0) {
      System.out.println(usage);
      return;
    }

    Scanner sc = new Scanner(new File(dictFile));
    ArrayList<String> dict = new ArrayList<String>();
    while (sc.hasNext()) {
      dict.add(sc.next());
    }

    if (args[0].equals("list") && args.length == 2) {
      String word = args[1];
      System.out.println(fmtList(wordLadder(word, dict)));
    } else if (args[0].equals("top") && args.length == 2) {
      int num = Integer.parseInt(args[1]);
      System.out.println(fmtPairs(mostLadderable(num, dict)));
    } else if (args[0].equals("chain") && args.length == 3) {
      int steps = Integer.parseInt(args[1]);
      List<String> start = new ArrayList<String>();
      start.add(args[2]);
      Set<String> chain = wordChain(steps, start, dict);
      System.out.println(chain.size());
    } else {
      System.out.println(usage);
      return;
    }
  }