public void addHijos(DefaultMutableTreeNode nodo) {
    if (nodo.getChildCount() != 0) {
      nodo.removeAllChildren();
    }
    Vector<String> ListaDir = new Vector<String>();
    Vector<String> ListaArch = new Vector<String>();
    DefaultMutableTreeNode upNode =
        (nodo.isRoot()) ? nodo : (DefaultMutableTreeNode) nodo.getParent();
    String Ruta = nodo.getUserObject().toString();
    while (!upNode.isRoot()) {
      Ruta = upNode.getUserObject().toString() + "\\" + Ruta;
      upNode = (DefaultMutableTreeNode) upNode.getParent();
    }

    try {
      Process sysCall;
      BufferedReader br;
      String s = "";
      String strCmd = "cmd /c cd " + localDir + "\\" + Ruta + " & dir";
      System.out.println(strCmd);
      sysCall = Runtime.getRuntime().exec(strCmd);
      br = new BufferedReader(new InputStreamReader(sysCall.getInputStream()));
      while ((s = br.readLine()) != null) {
        System.out.println(s);
        int indexArch = "                                         ".length();
        if (s.contains("<DIR>")) {
          int indexDir = s.indexOf("<DIR>") + "<DIR>".length() + 1;
          String nomDir = s.substring(indexDir);
          ListaDir.add(nomDir.trim());
        } else {
          String nomArch = (s.length() > indexArch) ? s.substring(indexArch) : s;
          ListaArch.add(nomArch);
        }
      }
      ListaDir = new Vector<String>(ListaDir.subList(2, ListaDir.size()));
      ListaArch = new Vector<String>(ListaArch.subList(5, ListaArch.size() - 2));
      int i;
      for (i = 0; i < ListaDir.size(); i++) {
        DefaultMutableTreeNode hijo = new DefaultMutableTreeNode(ListaDir.get(i).toString());
        nodo.add(hijo);
      }
      for (i = 0; i < ListaArch.size(); i++) {
        DefaultMutableTreeNode hijo = new DefaultMutableTreeNode(ListaArch.get(i).toString());
        nodo.add(hijo);
      }
      ListaArchSup.addAll(ListaArch);
      ListaDirSup.addAll(ListaDir);
    } catch (Exception e) {
    }
  }
示例#2
1
 private int move(int index, int direction, boolean allTheWay) {
   Vector<Mod> visibleMods = getVisible();
   int newIndex;
   if (!allTheWay) {
     newIndex = index + direction;
   } else if (direction < 0) {
     newIndex = 0;
   } else {
     newIndex = visibleMods.size() - 1;
   }
   if (index >= 0
       && index < visibleMods.size()
       && newIndex >= 0
       && newIndex < visibleMods.size()
       && newIndex != index) {
     List<Mod> mods =
         visibleMods.subList(Math.min(index, newIndex), Math.max(index, newIndex) + 1);
     for (int i = 0; i < modsByIndex.size(); i++) {
       for (int j = 0; j < mods.size(); j++) {
         if (modsByIndex.get(i) == mods.get(j)) {
           modsByIndex.set(i, mods.get((j + direction + mods.size()) % mods.size()));
           break;
         }
       }
     }
     index = newIndex;
   }
   return index;
 }
  protected void checkAndAppendSyllables(
      BufferedWriter w, String line, Vector<ClusterProperties> syllables) throws IOException {
    while (syllables.size() > 0) {
      int candidateLength = Math.min(syllables.size(), mMaxSyllables);

      for (; candidateLength > 0; --candidateLength) {
        ClusterProperties endSyllable = syllables.elementAt(candidateLength - 1);

        String candidate =
            line.substring(syllables.firstElement().getStart(), endSyllable.getEnd());
        if (mWordList.contains(candidate)) {
          w.append(candidate);
          appendSpacer(w, line, endSyllable);
          List<ClusterProperties> wordCP =
              new ArrayList<ClusterProperties>(syllables.subList(0, candidateLength));
          syllables.removeAll(wordCP);
          break;
        }
      }
      if (candidateLength == 0) {
        // no match found, so append first syllable as is
        w.append(
            line.substring(syllables.firstElement().getStart(), syllables.firstElement().getEnd()));
        appendSpacer(w, line, syllables.firstElement());
        syllables.remove(0);
      }
    }
  }
 @Override
 public Name getSuffix(int index) {
   if (index == elems.size()) {
     return new CompoundName(new Vector<String>().elements(), mySyntax);
   }
   validateIndex(index, false);
   return new CompoundName(
       new Vector<String>(elems.subList(index, elems.size())).elements(), mySyntax);
 }
 @Override
 public void addToAllHosts(final String host) {
   final String hostToAdd = getHostUrlPrefix(host);
   m_allHosts.remove(hostToAdd);
   if (m_allHosts.size() > 10) {
     m_allHosts.subList(10, m_allHosts.size()).clear();
   }
   m_allHosts.add(0, hostToAdd);
 }
示例#6
1
 public static void main(String[] args) {
   Vector<String> vectr = new Vector<String>();
   vectr.add("One");
   vectr.add("Two");
   vectr.add("Three");
   vectr.add("Four");
   vectr.add("Five");
   vectr.add("Six");
   System.out.println("Elements in Vectror are : " + vectr);
   System.out.println("SubList of Elements in Vectror are : " + vectr.subList(2, 4));
 }
示例#7
0
  public void onError(RpcAsyncContext ctx) {
    if (_errorlist.size() == 0) {
      onFinally(ctx);
      return;
    }
    KeyValuePair<RpcPromise, Behavior> kv = _errorlist.remove(0);
    int index = _successlist.indexOf(kv.getValue());
    _successlist.subList(0, index + 1).clear();

    ctx.promise = kv.getKey();
    ctx.promise.onNext(ctx); // drive into next
  }
示例#8
0
 public void onNext(RpcAsyncContext ctx, RpcPromise from) {
   if (from != null && from._lastPoint != null) {
     int index = _successlist.indexOf(from._lastPoint);
     _successlist.subList(0, index + 1).clear();
   }
   if (_successlist.size() == 0) {
     onFinally(ctx);
     return;
   }
   Behavior next = null;
   next = _successlist.remove(0);
   if (next != null) {
     next.onNext(ctx);
   }
 }
  public synchronized void maintainConnections() {
    int connectionsToAdd = connectionsToMaintain - connections.size();
    if (connectionsToAdd <= 0) {
      return;
    }
    List<Address> toConnect;
    Vector<Address> possible = addressBook.getAddressConnectList();

    removeConnectionsFromAddressList(connections, possible);

    if (possible.size() < connectionsToAdd && ircBootStrap) {

      try {
        System.out.println("addresses: " + possible.size());

        bootstrap();
        possible = addressBook.getAddressConnectList();
        possible.removeAll(connections);
        System.out.println("addresses2: " + possible.size());
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    toConnect =
        possible.subList(
            0, (connectionsToMaintain < possible.size() ? connectionsToMaintain : possible.size()));
    for (Address a : toConnect) {
      try {
        connectTo(a);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
 public boolean isConverged(Population pop) {
   Vector<Double> bests = (Vector<Double>) pop.getEAIndividual(0).getData(NichePSO.fitArchiveKey);
   if (bests.size() < haltingWindow) {
     return false;
   } else {
     List<Double> lst = bests.subList(bests.size() - haltingWindow, bests.size());
     bests = new Vector<>(haltingWindow);
     bests.addAll(lst);
     for (int i = 1; i < pop.size(); i++) {
       for (int k = 0; k < haltingWindow; k++) {
         Vector<Double> fitArch =
             (Vector<Double>) pop.getEAIndividual(i).getData(NichePSO.fitArchiveKey);
         int archIndex =
             fitArch.size()
                 - haltingWindow
                 + k; // index within the fitness archive of the current particle, which may be
                      // larger than the bests list - the tail is important
         if (archIndex >= 0 && (fitArch.get(archIndex) < bests.get(k))) {
           bests.set(k, fitArch.get(archIndex));
         }
       }
     }
   }
   // bests contains now the sequence of best fitness values across the last generations
   Double historicHWAgo = bests.get(0);
   boolean res = true;
   for (int i = 1; i < haltingWindow; i++) {
     // if historic[-hW] is worse than historic[-hW+i] return false
     Double historicIter = bests.get(i);
     // if the iterated value (the later one in history) has improved, there is no convergence.
     boolean improvementHappened =
         (historicIter < historicHWAgo); // testSecondForImprovement(historicHWAgo, historicIter));
     if (improvementHappened) {
       res = false;
       break;
     }
   }
   return res;
 }
示例#11
0
 public List<String> realElements(Vector elements) {
   return elements.subList(Token.MIN_USER_TOKEN_TYPE, elements.size());
 }
示例#12
0
  public ExpressionPart parseTokens(Vector<Token> input) throws Exception { // TODO INNY PARSER
    System.out.println("parsing tokens");

    if (input.size() == 0) {
      System.out.println("no tokens to parse!");
      return null;
    }

    for (int k = 0; k < input.size(); k++) {
      System.out.println(
          "next token: " + input.get(k).getToken() + " type: " + input.get(k).getType());
    }

    if (input.size() == 1 && input.get(0).getType() == 0) {
      System.out.println("only one number to parse");
      return new Number(Double.parseDouble(input.get(0).getToken()));
    }
    if (input.size() == 1 && input.get(0).getType() == 3) {
      System.out.println("only one variable to parse");
      return new Variable(input.get(0).getToken());
    }

    ExpressionPart returnVal = null;
    System.out.println(
        "amount of tokens: "
            + input.size()); // I'm working on new parser, i don't like the way current one is
    // functioning

    /*
    //int bracketLevel = 0;
    int tmpBracketLevel = 0;
    int i = input.size() - 1;
    boolean bracketFlag = false;
    if(input.get(0).getToken().equals("(") && input.get(i).getToken().equals(")")){
    	bracketFlag = true;
    	for(int j = 0; j < i; j++){
    		Token currToken = input.get(j);
    		if(currToken.getToken().equals("(")){
    			tmpBracketLevel ++;
    		}
    		if(currToken.getToken().equals(")")){
    			tmpBracketLevel --;
    			if(tmpBracketLevel == 0 && j < i-1){
    				bracketFlag = false;
    				break;
    			}
    		}
    	}
    }
    if(bracketFlag){
    	i = input.size() - 2;
    }
    String currentOp = input.get(0).getToken();

    int k;
    if(bracketFlag){
    	k = 2;
    }else{
    	k = 1;
    }
    Vector<Token> rightSideOfLast = new Vector<Token>();
    for(; k < i; k++){
    	Token currToken = input.get(k);
    	if(getPriority(currentOp) >= getPriority(currToken.getToken())){
    		System.out.println("token with higer priority!");
    		if(returnVal instanceof Addition){
    			Addition tmp = (Addition)returnVal;
    			tmp.addAddend(parseTokens(rightSideOfLast));
    			returnVal = tmp;
    		}else if(returnVal instanceof Substraction){
    			Substraction tmp = (Substraction)returnVal;
    			tmp.setSubtrahend(parseTokens(rightSideOfLast));
    			returnVal = tmp;
    		}else{
    			returnVal = parseTokens(rightSideOfLast);
    		}

    		currentOp = currToken.getToken();

    		if(currentOp.equals("+")){
    			System.out.println("addition");
    			if(returnVal == null){
    				Addition tmp = new Addition();
    				tmp.addAddend(returnVal);
    				returnVal = tmp;
    				System.out.println("returnVal == null");
    				System.out.println(returnVal);
    			}else if(returnVal instanceof Addition){
    				Addition tmp = (Addition)returnVal;
    				tmp.addAddend(returnVal);
    				returnVal = tmp;
    			}
    		}
    		if(currentOp.equals("-")){
    			Substraction tmp = new Substraction();
    			tmp.setMinuend(returnVal);
    			returnVal = tmp;
    		}
    		if(currentOp.equals("*")){

    		}
    		if(currentOp.equals("/")){

    		}
    		if(currentOp.equals("=")){

    		}

    		rightSideOfLast.clear();
    	}else{
    		rightSideOfLast.add(currToken);
    	}
    }
    System.out.println("end of parsing!");
    return returnVal;*/

    String currentOp = "";
    int lastOperatorPos = 0;
    for (int k = 0;
        k <= 5;
        k++) { // look only at operators at lowest priority, then ones higher priority
      Vector<Token> tokensToAdd = new Vector<Token>();
      System.out.println("searching for operators with priority: " + k);
      if (!currentOp.equals("")) {
        break;
      }
      int bracketLevel = 0;
      int tmpBracketLevel = 0;
      int i = input.size() - 1;
      boolean bracketFlag = false; // TODO system struktur, ewentualnie bez tokenow
      if (input.get(0).getToken().equals("(") && input.get(i).getToken().equals(")")) {
        bracketFlag = true;
        for (int j = 0; j < i; j++) {
          Token currToken = input.get(j);
          if (currToken
              .getToken()
              .equals("(")) { // if thera are brackets surronding expression, ignore them
            tmpBracketLevel++;
          }
          if (currToken.getToken().equals(")")) {
            tmpBracketLevel--;
            if (tmpBracketLevel == 0 && j < i - 1) {
              bracketFlag = false;
              break;
            }
          }
        }
      }
      if (bracketFlag) {
        i = input.size() - 2;
      }

      for (; i >= 0; i--) { // TODO daje odwrotna kolejnosc niz wpisane(nie mozna )
        Token currToken = input.get(i);
        tokensToAdd.add(currToken); // tokens that are between last operator and next one(useful in
        // addition/multiplications)
        if (currToken.getToken().equals(")")) {
          bracketLevel++;
        }
        if (currToken.getToken().equals("(")) {
          bracketLevel--;
        }
        if (bracketLevel > 0) {
          System.out.println("skipping token, searching for end of bracket");
          continue;
        }
        System.out.println("next token: " + currToken.getToken() + " type: " + currToken.getType());
        if (currToken.getType() == 1) {
          if (getPriority(currToken.getToken()) == k) {
            lastOperatorPos = i;
            if (currentOp.equals("")) { // to jest, zeby nie ustawial nowego operatora
              currentOp =
                  currToken
                      .getToken(); // TODO obsluga pierwiastkowania(a tym samym operacje z innym
              // zapisem niz arg op arg)
            }

            if (currentOp.equals(currToken.getToken())) {
              Vector<Token> firstPart = new Vector<Token>();
              Vector<Token> secondPart = new Vector<Token>();

              if (!bracketFlag) {
                firstPart.addAll(input.subList(0, i));
                secondPart.addAll(input.subList(i + 1, input.size()));
              } else {
                firstPart.addAll(input.subList(1, i));
                secondPart.addAll(input.subList(i + 1, input.size() - 1));
              }
              if (returnVal == null) { // parse diffrent operators
                System.out.println("first operator");
                if (currentOp.equals("\\")) {
                  Fraction returnValTmp = new Fraction();

                  System.out.println("[\\]part 1");
                  returnValTmp.setNumerator(parseTokens(firstPart));
                  System.out.println("[\\]part 2");
                  returnValTmp.setDenominator(parseTokens(secondPart));
                  returnVal = returnValTmp;
                }
                if (currentOp.equals("+")) {
                  Addition returnValTmp = new Addition();

                  System.out.println("[+]part 1");
                  returnValTmp.addAddend(parseTokens(secondPart));
                  // System.out.println("[+]part 2");
                  // returnValTmp.addAddend(parseTokens(secondPart));
                  returnVal = returnValTmp;
                  System.out.println("end of part 2");
                  tokensToAdd.clear();
                }
                if (currentOp.equals("-")) {
                  Substraction returnValTmp = new Substraction();

                  System.out.println("[-]part 1");
                  returnValTmp.setMinuend(parseTokens(firstPart));
                  System.out.println("[-]part 2");
                  returnValTmp.setSubtrahend(parseTokens(secondPart));
                  returnVal = returnValTmp;
                }
                if (currentOp.equals("*")) {
                  Multiplication returnValTmp = new Multiplication();

                  System.out.println("[*]part 1");
                  returnValTmp.addFactor(parseTokens(secondPart));
                  // System.out.println("[+]part 2");
                  // returnValTmp.addAddend(parseTokens(secondPart));
                  returnVal = returnValTmp;
                  System.out.println("end of part 2");
                  tokensToAdd.clear();
                }
                if (currentOp.equals("/")) {
                  Division returnValTmp = new Division();

                  System.out.println("[/]part 1");
                  returnValTmp.setDividend(parseTokens(firstPart));
                  System.out.println("[/]part 2");
                  returnValTmp.setDivisor(parseTokens(secondPart));
                  returnVal = returnValTmp;
                }
                if (currentOp.equals("^")) {
                  Exponentiation returnValTmp = new Exponentiation();

                  System.out.println("[^]part 1");
                  returnValTmp.setBase(parseTokens(firstPart));
                  System.out.println("[^]part 2");
                  returnValTmp.setExponent(parseTokens(secondPart));
                  returnVal = returnValTmp;
                }
                if (currentOp.equals("=")) {
                  Equation returnValTmp = new Equation();

                  System.out.println("[=]part 1");
                  returnValTmp.setSide1(parseTokens(firstPart));
                  System.out.println("[=]part 2");
                  returnValTmp.setSide2(parseTokens(secondPart));
                  returnVal = returnValTmp;
                }
              } else {
                System.out.println("next operator");

                if (currentOp.equals("+") && returnVal instanceof Addition) {
                  Addition returnValConverted = (Addition) returnVal;

                  // System.out.println("[+]part 1");
                  // returnValConverted.addAddend(parseTokens(firstPart));
                  Vector<Token> tokensInArg = new Vector<Token>();
                  tokensInArg.addAll(tokensToAdd.subList(0, tokensToAdd.size() - 1));

                  System.out.println("[+]part 2(adding only second part)");
                  returnValConverted.addAddend(parseTokens(tokensInArg));
                  tokensToAdd.clear();
                }
                if (currentOp.equals("*") && returnVal instanceof Multiplication) {
                  Multiplication returnValConverted = (Multiplication) returnVal;

                  // System.out.println("[+]part 1");
                  // returnValConverted.addAddend(parseTokens(firstPart));
                  Vector<Token> tokensInArg = new Vector<Token>();
                  tokensInArg.addAll(tokensToAdd.subList(0, tokensToAdd.size() - 1));

                  System.out.println("[+]part 2(adding only second part)");
                  returnValConverted.addFactor(parseTokens(tokensInArg));
                  tokensToAdd.clear();
                }
              }
            }
          }
        }
        if (bracketFlag && i <= 1) {
          break;
        }
      }

      Vector<Token> firstPart = new Vector<Token>();
      Vector<Token> secondPart = new Vector<Token>();

      if (!bracketFlag) {
        firstPart.addAll(input.subList(0, lastOperatorPos));
        secondPart.addAll(input.subList(lastOperatorPos + 1, input.size()));
      } else if (lastOperatorPos >= 1) {
        firstPart.addAll(input.subList(1, lastOperatorPos));
        secondPart.addAll(input.subList(lastOperatorPos + 1, input.size() - 1));
      }

      System.out.println("Adding last part");
      if (currentOp.equals("+") && returnVal instanceof Addition) {
        Addition returnValConverted = (Addition) returnVal;

        System.out.println("[+]part 1(adding only first part)");
        returnValConverted.addAddend(parseTokens(firstPart));
        tokensToAdd.clear();
      }
      if (currentOp.equals("*") && returnVal instanceof Multiplication) {
        Multiplication returnValConverted = (Multiplication) returnVal;

        System.out.println("[*]part 1(adding only first part)");
        returnValConverted.addFactor(parseTokens(firstPart));
        tokensToAdd.clear();
      }
      if (returnVal != null) {
        break;
      }
    }
    return returnVal;
  }
 @Override
 public Name getPrefix(int index) {
   validateIndex(index, true);
   return new CompoundName(new Vector<String>(elems.subList(0, index)).elements(), mySyntax);
 }