Exemplo n.º 1
1
 private Path holePathVonNeuemLaufwerk(ArrayList<Path> initial, ArrayList<Path> aktuell) {
   ArrayList<Path> test, test1;
   test = (ArrayList<Path>) aktuell.clone();
   test1 = (ArrayList<Path>) initial.clone();
   test.removeAll(test1);
   return test.get(test.size() - 1);
 }
Exemplo n.º 2
1
    @Override
    public void run() {
      while (true) {
        if (istWindows()) aktuell = holeLaufwerkeWindows();
        else aktuell = holeLaufwerkeUnix();

        if (initial.size() != aktuell.size()) {
          if (!initial.containsAll(aktuell)) {
            neuesLaufwerk = holePathVonNeuemLaufwerk(initial, aktuell);
            textArea.append("Neues Laufwerk endeckt:  " + neuesLaufwerk + System.lineSeparator());
            this.initial = (ArrayList<Path>) aktuell.clone();
            neuesLaufwerkDialog();

          } else {
            this.initial = (ArrayList<Path>) aktuell.clone();
            textArea.append("Laufwerk wurde entfernt" + System.lineSeparator());
          }
        }

        try {
          Thread.sleep(5000);
        } catch (InterruptedException e) {
          System.out.println("Laufwerksprüfung wird abgebrochen");
        }
      }
    }
  public String pickGoodStarterWord() {

    String word;
    ArrayList<String> wordsOfCurrentSize = (ArrayList) wordList.clone();
    wordsOfCurrentSize.retainAll(sizeToWord.get(wordlength));
    // ArrayList<String> wordsOfCurrentSize = sizeToWord.get(wordlength);
    Integer startingPoint = random.nextInt(wordsOfCurrentSize.size());
    // Log.d("numberOfWords: ", String.valueOf(wordsOfCurrentSize.size()));
    do {
      word = wordsOfCurrentSize.get(startingPoint);

      if (startingPoint == (wordsOfCurrentSize.size() - 1)) {
        startingPoint = 0;
      } else {
        startingPoint++;
      }

    } while (lettersToWord.get(sortLetters(word)).size() < MIN_NUM_ANAGRAMS);

    if (wordlength <= MAX_WORD_LENGTH) {
      wordlength++;
    }

    Log.d("pickGoodStarterWord", "Chosen Starter Word is: " + word);

    return word;
  }
Exemplo n.º 4
0
  public static void doIt() throws Exception {
    Scanner scanner = new Scanner(System.in);
    Integer currentBalance = scanner.nextInt();
    int removeLast, removePenultimate;
    StringBuffer buf = new StringBuffer();

    ArrayList<Character> chars = new ArrayList<Character>();
    for (Character c : currentBalance.toString().toCharArray()) chars.add(c);

    ArrayList<Character> c1 = (ArrayList<Character>) chars.clone();
    c1.remove(c1.size() - 1);

    for (Character cc : c1) buf.append(cc);

    removeLast = new Integer(buf.toString());
    buf = new StringBuffer();

    ArrayList<Character> c2 = (ArrayList<Character>) chars.clone();
    c2.remove(c2.size() - 2);

    for (Character cc : c2) buf.append(cc);
    removePenultimate = new Integer(buf.toString());

    System.out.println(Math.max(currentBalance, Math.max(removeLast, removePenultimate)));
  }
  private void construct(
      SourceObject scriptObject_,
      boolean isExecutable_,
      DebugObject debug_,
      TokenBase rootChunk_,
      ArrayList<TokenBase> remark_,
      ArrayList<ScriptInstruction> instructionRegistry_) {
    isExecutable = isExecutable_;
    if (rootChunk_ != null) {
      rootChunk = (TokenBase) rootChunk_.clone();
    }

    if (remark_ != null) {
      remark = (ArrayList<TokenBase>) remark_.clone();
    }

    retObjClassName = scriptObject_.returnClassName;

    if (instructionRegistry_ != null) {
      instructionRegistry = (ArrayList<JRInstruction>) instructionRegistry_.clone();
    }

    methodId = scriptObject_.methodId;

    if (debug_ != null) {
      debug = debug_.clone();
    }

    if (scriptObject_ != null) {
      source = scriptObject_.clone();
    }
  }
Exemplo n.º 6
0
  static int minOperationTime(long currentMoteSize, ArrayList<Long> motes) {
    if (motes.size() == 0) return 0;

    while (motes.size() > 0 && motes.get(0) < currentMoteSize) {
      currentMoteSize += motes.get(0);
      motes.remove(0);
    }

    if (currentMoteSize - 1 == 0) return motes.size();

    if (motes.size() == 0) return 0;

    ArrayList<Long> removeMotes = (ArrayList<Long>) (motes.clone());
    removeMotes.remove(0);
    int operationTimeRemove = minOperationTime(currentMoteSize, removeMotes);

    int operationTimeAdd = 0;
    while (currentMoteSize <= motes.get(0)) {
      currentMoteSize += currentMoteSize - 1;
      operationTimeAdd++;
    }
    ArrayList<Long> addMotes = (ArrayList<Long>) (motes.clone());
    // addMotes.add(0, currentMoteSize-1);
    // System.out.println("size:" + addMotes.size() + " mote:"+(2*currentMoteSize-1));
    operationTimeAdd += minOperationTime(currentMoteSize, addMotes);

    return operationTimeAdd < operationTimeRemove + 1 ? operationTimeAdd : operationTimeRemove + 1;
  }
 public List<DateFormat> getDateFormats(final Type type) {
   if (type.isFlagSet(Type.DATE_TYPE)) {
     return (List<DateFormat>) dateFormats.clone();
   } else if (type.isFlagSet(Type.DATETIME_TYPE)) {
     return (List<DateFormat>) datetimeFormats.clone();
   } else if (type.isFlagSet(Type.TIME_TYPE)) {
     return (List<DateFormat>) timeFormats.clone();
   }
   return Collections.emptyList();
 }
  public void addedStatement(com.hp.hpl.jena.rdf.model.Statement stmt) {

    if (stmt.getPredicate().equals(hasContextProperty)) {
      if (!stmt.getObject().canAs(com.hp.hpl.jena.rdf.model.Resource.class)) return;
      com.hp.hpl.jena.rdf.model.Resource resource =
          (com.hp.hpl.jena.rdf.model.Resource)
              stmt.getObject().as(com.hp.hpl.jena.rdf.model.Resource.class);
      hasContext = null;
      if (true) { // don't check resource type if the property range is Resource
        try {
          hasContext =
              ibspan.tss.um.ontology.UserModellingFactory.getUserBehaviourContext(resource, _model);
        } catch (JastorException e) {
          // e.printStackTrace();
        }
      }
      if (listeners != null) {
        java.util.ArrayList consumers;
        synchronized (listeners) {
          consumers = (java.util.ArrayList) listeners.clone();
        }
        for (java.util.Iterator iter = consumers.iterator(); iter.hasNext(); ) {
          ExtendedUserBehaviourListener listener = (ExtendedUserBehaviourListener) iter.next();
          listener.hasContextChanged(ibspan.tss.um.ontology.ExtendedUserBehaviourImpl.this);
        }
      }
      return;
    }
    if (stmt.getPredicate().equals(hasUserBehaviourProperty)) {
      if (!stmt.getObject().canAs(com.hp.hpl.jena.rdf.model.Resource.class)) return;
      com.hp.hpl.jena.rdf.model.Resource resource =
          (com.hp.hpl.jena.rdf.model.Resource)
              stmt.getObject().as(com.hp.hpl.jena.rdf.model.Resource.class);
      hasUserBehaviour = null;
      if (true) { // don't check resource type if the property range is Resource
        try {
          hasUserBehaviour =
              ibspan.tss.um.ontology.UserModellingFactory.getUserBehaviour(resource, _model);
        } catch (JastorException e) {
          // e.printStackTrace();
        }
      }
      if (listeners != null) {
        java.util.ArrayList consumers;
        synchronized (listeners) {
          consumers = (java.util.ArrayList) listeners.clone();
        }
        for (java.util.Iterator iter = consumers.iterator(); iter.hasNext(); ) {
          ExtendedUserBehaviourListener listener = (ExtendedUserBehaviourListener) iter.next();
          listener.hasUserBehaviourChanged(ibspan.tss.um.ontology.ExtendedUserBehaviourImpl.this);
        }
      }
      return;
    }
  }
 public Object clone() throws CloneNotSupportedException {
   final MailDefinition mailDefinition = (MailDefinition) super.clone();
   mailDefinition.bodyReport = (MasterReport) bodyReport.clone();
   mailDefinition.attachmentTypes = (ArrayList) attachmentTypes.clone();
   mailDefinition.attachmentReports = (ArrayList) attachmentReports.clone();
   mailDefinition.attachmentReports.clear();
   for (int i = 0; i < attachmentReports.size(); i++) {
     final MasterReport report = (MasterReport) attachmentReports.get(i);
     mailDefinition.attachmentReports.add(report.clone());
   }
   return mailDefinition;
 }
 // MJN: have to clone the vertices, otherwise the cloned triangle
 // points back to the same verts as the original triangle.
 // WARNING: this means that the triangle verts aren't references to the
 // verts in the vertex array.  The triangle verts are copies, so if
 // changes are made to the verts (ie. rebuild() assigns ids to them),
 // these copies won't be affected.
 public GL_Triangle makeClone() {
   GL_Triangle clone = new GL_Triangle(p1.makeClone(), p2.makeClone(), p3.makeClone());
   clone.norm1 = norm1.getClone();
   clone.norm2 = norm2.getClone();
   clone.norm3 = norm3.getClone();
   clone.uvw1 = uvw1.getClone();
   clone.uvw2 = uvw2.getClone();
   clone.uvw3 = uvw3.getClone();
   clone.neighborsP1 = (ArrayList) neighborsP1.clone();
   clone.neighborsP2 = (ArrayList) neighborsP2.clone();
   clone.neighborsP3 = (ArrayList) neighborsP3.clone();
   return clone;
 }
Exemplo n.º 11
0
  public ArrayList<Node> findBestPackageSet(Map map, int maxWeight) {
    long binaryCounter = 0b0;
    long bitMask = getBitMask(map.size());
    ArrayList<Node> best = new ArrayList<>();
    while ((binaryCounter & bitMask) != bitMask) {

      if (System.currentTimeMillis() - startTime > timeout) {
        stop = true;
        return null;
      }

      ArrayList<Node> current = new ArrayList<>();
      binaryCounter++;
      long temp = binaryCounter;
      for (int i = 0; i < map.size(); i++) {
        if ((temp & 0b1) == 0b1) {
          current.add(map.getNode(i));
        }
        temp = temp >>> 1;
      }
      if (map.getValue(current) > map.getValue(best) && map.getWeight(current) < maxWeight) {
        best = (ArrayList<Node>) current.clone();
      }
    }
    return best;
  }
Exemplo n.º 12
0
 public Generador(ArrayList<String> pila_2, String programName) {
   tope = 0;
   pila = null;
   pila = (ArrayList<String>) pila_2.clone();
   this.programName = programName;
   pilaEvaluacion = new Stack<Double>();
 }
Exemplo n.º 13
0
  public void calculo(int salto, int ValorI) {
    int ganancia = 0;
    int Valor = ValorI;
    ArrayList<Zona> temporal = new ArrayList<>();
    for (int i = Valor; i < TerreniSize; i += salto) {
      temporal.add(Terrenos.get(i));
      ganancia += Terrenos.get(i).getBeneficio();
    }

    if (ganancia > verificar) {
      firstOption = (ArrayList<Zona>) temporal.clone();
      verificar = ganancia;

      temporal.clear();
      ganancia = 0;
      if (salto < TerreniSize) {
        calculo(salto + 1, Valor);
      }
    } else {
      // Si no se cumple la condicion reinica la longitud del arreglo
      temporal.clear();
      ganancia = 0;
      if (salto < TerreniSize) {
        calculo(salto + 1, Valor);
      }
    }
  }
Exemplo n.º 14
0
 public void minimizar(){
          boolean cambio =true;
     int noCambio =0;
     pobini.clear();
     pobini = (ArrayList<ArrayList>) pobiniAux.clone();
     while(cambio){
         //seleccionar el nuevo renglon
         mayorFuturo=seleccionaMenor();
         System.out.println("El renglon seleccionado es :"+ renglonSeleccionado);
         //llenarlaNuevapoblacion
         nuevaPoblacion();
         //nuevos valores Decimales
         mostrarPesosNuevos();
         //comparar los cambios
         if(mayorActual>mayorFuturo){
             mayorActual=mayorFuturo;
             noCambio=0;
         }else{
             noCambio++;
         }
         if(noCambio>3){
             cambio=false;
         }
         System.out.println("El menor es: "+mayorActual);
     }
     mostrarPoblaFin();
     jMinimo.setText(Integer.toString(mayorActual));
 }
Exemplo n.º 15
0
  public static void printPaths(Node node, ArrayList<Integer> path) {
    if (node == null) {
      return;
    }

    ArrayList<Integer> newPath = (ArrayList<Integer>) path.clone();
    newPath.add(Integer.valueOf(node.data));

    if (node.isLeaf()) {
      printPath(newPath);
      return;
    }

    printPaths(node.left, newPath);
    printPaths(node.right, newPath);

    /* The following alternate approach won't work
       * because we'll append a node to the same list every time,
       * even when we move back up the tree and start on a new branch.
       *
       * path.add(Integer.valueOf(node.data));

       if (node.isLeaf()) {
       	printPath(path);
       	return;
       }

       printPaths(node.left , path);
    printPaths(node.right, path);
    */
  }
 public static void combinationSumRecursive(
     int[] candidates,
     int target,
     ArrayList<ArrayList<Integer>> ls,
     ArrayList<Integer> l,
     HashSet<String> outputs) {
   if (target == 0) {
     ArrayList<Integer> l2 = (ArrayList<Integer>) l.clone();
     Collections.sort(l2);
     StringBuffer output = new StringBuffer("");
     for (Integer f : l2) {
       output.append(f + " ");
     }
     if (!outputs.contains(output.toString())) {
       outputs.add(output.toString());
       ls.add(l2);
     }
     return;
   }
   for (int i = 0; i < candidates.length; i++) {
     if (target >= candidates[i]) {
       l.add(candidates[i]);
       combinationSumRecursive(candidates, target - candidates[i], ls, l, outputs);
       l.remove(l.size() - 1);
     }
   }
 }
Exemplo n.º 17
0
  @SuppressWarnings("unchecked")
  public Challenge next(int mLevel, int mScore) {

    if (challengeMap == null) {
      xmlScan();
    }

    // if level has increased beyond the defined challenges, pick the last challenge
    if (challengeMap.size() >= mLevel) mUsedChallengeMapIndex = mLevel - 1;
    else mUsedChallengeMapIndex = challengeMap.size() - 1;

    ArrayList<Challenge> challenges = challengeMap.get(mUsedChallengeMapIndex);

    if (challenges.size() == 0) {
      challengeMap.set(mUsedChallengeMapIndex, (ArrayList<Challenge>) mLastChallengeSet.clone());
      challenges = challengeMap.get(mUsedChallengeMapIndex);
    }

    mUsedChallengeIndex = random.nextInt(challenges.size());

    // clone challenge so we can modify the options freely
    Challenge ch = (Challenge) challenges.get(mUsedChallengeIndex).clone();

    ch.options = makeOptions(ch.nOptions, ch.answer, ch.options, ch.avoid);
    return ch;
  }
Exemplo n.º 18
0
 @Override
 @SuppressWarnings("unchecked")
 public ASTPtrdeclaratorList clone() {
   ASTPtrdeclaratorList ret = new ASTPtrdeclaratorList();
   ret.setList((ArrayList<ASTPtrdeclarator>) list.clone());
   return ret;
 }
Exemplo n.º 19
0
  /*
   * Combine two item sets of size k into an item set of size k+1
   * The maximum k is set to 5 at the moment
   */
  private void combineItemSet() {
    ArrayList<AttributeItemSet> tempItemSet = new ArrayList<AttributeItemSet>();

    for (int k = 1; k < this.ITEMSET_SIZE; k++) {
      for (int i = 0; i < this._itemSet.size() - 1; i++) {
        for (int j = i + 1; j < this._itemSet.size(); j++) {
          if (this._itemSet.get(i).differentInLastAttribute(this._itemSet.get(j))) {
            AttributeItemSet tempAttrItemSet1 = (AttributeItemSet) this._itemSet.get(i).clone();
            System.out.println(tempAttrItemSet1.toString());
            AttributeItemSet tempAttrItemSet2 = (AttributeItemSet) this._itemSet.get(j).clone();
            System.out.println(tempAttrItemSet2.toString());
            tempAttrItemSet1.addCandidateItemSet(
                tempAttrItemSet2
                    .getCandidateItemSet()
                    .get(tempAttrItemSet2.getCandidateItemSet().size() - 1));
            tempAttrItemSet1.resetCoverage();
            tempItemSet.add((AttributeItemSet) tempAttrItemSet1);
          } else {
            // do nothing when all the attributes are similar or when there
            // are more than one difference (not only the last) in the two sets
            ;
          }
        }
      }

      this.findFrequentItemSets(tempItemSet);
      this._itemSet = (ArrayList<AttributeItemSet>) tempItemSet.clone();
      tempItemSet.clear();
    }
  }
Exemplo n.º 20
0
 @SuppressWarnings("unchecked")
 @Override
 public void run() {
   try {
     ListeningSocket.setSoTimeout(ListeningTimeout);
     // .
     try {
       while (!Canceller.flCancel) {
         Socket ClientSocket;
         try {
           ClientSocket = ListeningSocket.accept();
           // . start new session
           new TClientSession(this, ClientSocket);
         } catch (SocketTimeoutException E) {
         }
       }
     } finally {
       ArrayList<TClientSession> _ClientSessions;
       synchronized (ClientSessions) {
         _ClientSessions = (ArrayList<TClientSession>) ClientSessions.clone();
       }
       for (int I = 0; I < _ClientSessions.size(); I++) _ClientSessions.get(I).Finalize();
     }
   } catch (Throwable T) {
     if (!Canceller.flCancel) {
       if (ExceptionHandler != null) ExceptionHandler.DoOnException(T);
     }
   }
 }
Exemplo n.º 21
0
 @SuppressWarnings("resource")
 static boolean toFile(ArrayList<UploadedCaption> list, long steamID, String packageName) {
   FileOutputStream stream;
   try {
     stream = new FileOutputStream(filePath(steamID, packageName));
   } catch (FileNotFoundException e) {
     return false;
   }
   @SuppressWarnings("unchecked")
   ArrayList<UploadedCaption> newList = (ArrayList<UploadedCaption>) (list.clone());
   Collections.sort(newList, new UploadedCaptionComparator());
   int size = newList.size();
   try {
     (new LittleEndianDataOutputStream(stream)).writeInt(size);
     Iterator<UploadedCaption> iterator = newList.iterator();
     while (size-- > 0) {
       iterator.next().writeToStream(stream);
     }
     stream.flush();
     Utility.closeCloseable(stream);
     return true;
   } catch (IOException e) {
     Utility.closeCloseable(stream);
     return false;
   }
 }
 /**
  * Method for retrieving the entities to render with the respective information.
  *
  * @return List containing all markers for now.
  */
 protected ArrayList<Trackable> getList() {
   synchronized (synLock) {
     updatedData = false;
     //noinspection unchecked
     return (ArrayList<Trackable>) detectedTrackables.clone();
   }
 }
Exemplo n.º 23
0
  public void setPoints(ArrayList<Double> xnvalues, ArrayList<Double> fxnvalues) {
    resultMatrix.clear();
    copiedXnValues.clear();
    coefficients.clear();
    individualPolynomials.clear();
    equations.clear();
    copiedXnValues = (ArrayList<Double>) xnvalues.clone();
    int sXEqs = (copiedXnValues.size() - 1) * 2;
    int dSXEqs = copiedXnValues.size() - 2;
    int d2SXEqs = copiedXnValues.size() - 2;
    int supEqs = 2;
    int totalEqs = 4 * (copiedXnValues.size() - 1);
    for (int i = 0; i < totalEqs; i++) {
      resultMatrix.add(new ArrayList<Double>()); // Se pone un nuevo ArrayList en cada posición.
    }

    // Ecuaciones con s(x).
    buildSXEqs(sXEqs, totalEqs, fxnvalues);
    // Ecuaciones con s'(x).
    buildDSXEqs(dSXEqs, totalEqs);
    // Ecuaciones con s''(x).
    buildD2SXEqs(d2SXEqs, totalEqs);
    // Ecuaciones con s''(x) + suposición.
    buildSupEqs(supEqs, totalEqs);

    convertResultToMatrix();
    marks = Matrix.fillMarks(interpolationMatrix.length);
    solveWithTotalPivoting();
    if (coefficients.size() > 0) {
      buildPiecewisePolynomial(totalEqs);
    } else { // Hubo algún error resolviendo el sistema de ecuaciones.
      polynomial = "Polinimio No Determinado";
    }
    // System.out.println(polynomial);
  }
 @Override
 @SuppressWarnings("unchecked")
 public ASTEnhancedForStatementNoShortIfList clone() {
   ASTEnhancedForStatementNoShortIfList ret = new ASTEnhancedForStatementNoShortIfList();
   ret.setList((ArrayList<ASTEnhancedForStatementNoShortIf>) list.clone());
   return ret;
 }
Exemplo n.º 25
0
 @Override
 @SuppressWarnings("unchecked")
 public ASTPostfixexpressionList clone() {
   ASTPostfixexpressionList ret = new ASTPostfixexpressionList();
   ret.setList((ArrayList<ASTPostfixexpression>) list.clone());
   return ret;
 }
Exemplo n.º 26
0
 @Override
 @SuppressWarnings("unchecked")
 public ASTTypenamePList clone() {
   ASTTypenamePList ret = new ASTTypenamePList();
   ret.setList((ArrayList<ASTTypenameP>) list.clone());
   return ret;
 }
Exemplo n.º 27
0
 @Override
 @SuppressWarnings("unchecked")
 public ASTUnannClassTypeList clone() {
   ASTUnannClassTypeList ret = new ASTUnannClassTypeList();
   ret.setList((ArrayList<ASTUnannClassType>) list.clone());
   return ret;
 }
Exemplo n.º 28
0
 private void calculateFiniteSupport(ArrayList<Integer> currentList, int depth, int remain) {
   if (depth == k) {
     finiteSupport[supportNum] = currentList.clone();
     supportNum++;
   } else if (depth == k - 1) {
     if (remain == 0) {
       currentList.add(0);
       calculateFiniteSupport(currentList, depth + 1, 0);
       currentList.remove(depth);
     } else if (!Util.closeToZero(p[depth])) {
       currentList.add(remain);
       calculateFiniteSupport(currentList, depth + 1, 0);
       currentList.remove(depth);
     }
   } else {
     currentList.add(0);
     calculateFiniteSupport(currentList, depth + 1, remain);
     currentList.remove(depth);
     if (!Util.closeToZero(p[depth])) {
       for (int i = 1; i <= remain; i++) {
         currentList.add(i);
         calculateFiniteSupport(currentList, depth + 1, remain - i);
         currentList.remove(depth);
       }
     }
   }
 }
Exemplo n.º 29
0
  public ArrayList getListOfAvailableItems(LibraryType type) {
    ArrayList listOfItems = new ArrayList();

    switch (type) {
      case BOOK:
        for (Item item : listOfAvailableItems) {
          if (item instanceof Book) {
            listOfItems.add((Book) item);
          }
        }
        break;

      case MOVIE:
        for (Item item : listOfAvailableItems) {
          if (item instanceof Movie) {
            listOfItems.add((Movie) item);
          }
        }
        break;

      default:
        listOfItems = (ArrayList) listOfAvailableItems.clone();
    }

    return listOfItems;
  }
Exemplo n.º 30
0
    private void addPaths(
        List<List<AbilityFacade>> abilityPaths,
        List<AbilityFacade> preAbilities,
        ArrayList<AbilityFacade> path) {
      if (path.size() > 20) {

        Logging.errorPrint(
            "Found probable ability prereq cycle ["
                + StringUtils.join(path, ",")
                + "] with prereqs ["
                + StringUtils.join(preAbilities, ",")
                + "]. Skipping.");
        return;
      }
      for (AbilityFacade preAbility : preAbilities) {
        @SuppressWarnings("unchecked")
        ArrayList<AbilityFacade> pathclone = (ArrayList<AbilityFacade>) path.clone();
        pathclone.add(preAbility);
        List<AbilityFacade> preAbilities2 = dataset.getPrereqAbilities(preAbility);
        // Don't include self references in the path
        preAbilities2.remove(preAbility);
        preAbilities2.removeAll(pathclone);
        if (preAbilities2.isEmpty()) {
          abilityPaths.add(pathclone);
        } else {
          addPaths(abilityPaths, preAbilities2, pathclone);
        }
      }
    }