Beispiel #1
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)));
  }
Beispiel #2
0
 public void pairClusters(ArrayList<Record> pair1, ArrayList<Record> pair2, boolean left) {
   for (int i = 0; i < pair1.size(); i++) {
     for (int j = 0; j < pair2.size(); j++) {
       if (pair1.get(i).isInsertionPair(pair2.get(j), left)) {
         System.out.println(pair1.get(i) + "\n" + pair2.get(j) + "\n");
         pair1.remove(i);
         pair2.remove(j);
         i--;
         j--;
         break;
       }
     }
   }
   if ((pair1.size() + pair2.size()) > 0) {
     System.out.println("***** UNPAIRED *****");
     for (int i = 0; i < pair1.size(); i++) {
       System.out.println(pair1.get(i));
     }
     for (int j = 0; j < pair2.size(); j++) {
       System.out.println(pair2.get(j));
     }
     System.out.println("**** END OF UNPAIRED ****\n");
   }
   // System.out.println("\n");
 }
Beispiel #3
0
  /*
   *  to broadcast a private message to all Clients
   */
  private synchronized void broadcastOnlyOne(String message, ChatMessage cm) {

    // add HH:mm:ss and \n to the message
    String time = sdf.format(new Date());
    String messageLf = time + " " + message + "\r\n";
    System.out.print(messageLf);
    serverGUI.serverTextArea.append(messageLf);

    // we loop in reverse order in case we would have to remove a Client
    // because it has disconnected
    for (int i = al.size(); --i >= 0; ) {
      ClientThread ct = al.get(i);
      // try to write to the Client if it fails remove it from the list
      if (cm.getType() == ChatMessage.ESTABLISHCONNECTION
          || cm.getType() == ChatMessage.ESTABLISHCONNECTIONANDPLAY) {
        if (cm.getTO().equalsIgnoreCase(ct.username) && !ct.writeMsg(cm)) {
          al.remove(i);
          display("Disconnected Client " + ct.username + " removed from list.");
          break;
        }
      } else {
        if (cm.getTO().equalsIgnoreCase(ct.username) && !ct.writeMsg(message)) {
          al.remove(i);
          display("Disconnected Client " + ct.username + " removed from list.");
          break;
        }
      }
    }
  }
  public static void insert_element(int temp, int temp_size) {

    int numberToBeInserted = 0;
    iterator++;
    for (int i = 0; i < temp_size; i++) {
      numberToBeInserted = temp + i;
      // case 1 : (item is not in the cache)
      if (!cache.contains(numberToBeInserted)) {
        miss_count++;
        // if cache is full : delete the lru position and paste the item
        // at MRU
        if (cache.size() == cache_size) {
          cache.remove(cache_size - 1);
          cache.add(0, numberToBeInserted);
        }
        // if cache is not full : paste Item at MRU
        else {
          cache.add(0, numberToBeInserted);
        }
      }
      // case 2 : item is in the cache bring item to the beginning)
      else {
        hit_count++;
        cache.remove(cache.indexOf(numberToBeInserted));
        cache.add(1, numberToBeInserted);
      }
    }
  }
Beispiel #5
0
 @Override
 public void databaseChanged(DatabaseChangeEvent e) {
   synchronized (set) {
     int pos;
     switch (e.getType()) {
       case ADDED_ENTRY:
         pos = -Collections.binarySearch(set, e.getEntry(), comp) - 1;
         set.add(pos, e.getEntry());
         // addEntry(e.getEntry());
         // set.add(e.getEntry());
         // changed = true;
         // Collections.sort(set, comp);
         break;
       case REMOVED_ENTRY:
         set.remove(e.getEntry());
         changed = true;
         break;
       case CHANGED_ENTRY:
         // Entry changed. Resort list:
         // Collections.sort(set, comp);
         pos = Collections.binarySearch(set, e.getEntry(), comp);
         int posOld = set.indexOf(e.getEntry());
         if (pos < 0) {
           set.remove(posOld);
           set.add(-pos - 1, e.getEntry());
         }
         // changed = true;
         break;
     }
   }
 }
Beispiel #6
0
 public Mapa(String w, String h, String s, String j) {
   WIDTH = Integer.parseInt(w);
   HEIGHT = Integer.parseInt(h);
   SCALE = Integer.parseInt(s);
   numGamers = Integer.parseInt(j);
   hacerJugadores();
   if (Integer.parseInt(j) != 4) {
     switch (Integer.parseInt(j)) {
       case 1:
         jugadores.remove(1);
         jugadores.remove(1);
         jugadores.remove(1);
         break;
       case 2:
         jugadores.remove(1);
         jugadores.remove(1);
         break;
       case 3:
         jugadores.remove(1);
         break;
       default:
         break;
     }
   }
   restriccion = lectura(Integer.parseInt(w), Integer.parseInt(h), Integer.parseInt(s));
 }
Beispiel #7
0
  private static void getTopDocuments(int num, HashMap<String, Float> scoremap, String filename)
      throws FileNotFoundException {
    PrintWriter out = new PrintWriter(filename);
    Iterator<String> itr = scoremap.keySet().iterator();
    ArrayList<String> urls = new ArrayList<String>();
    ArrayList<Float> scores = new ArrayList<Float>();

    while (itr.hasNext()) {
      String key = itr.next();
      if (scores.size() < num) {
        scores.add(scoremap.get(key));
        urls.add(key);
      } else {
        int index = scores.indexOf(Collections.min(scores));
        if (scores.get(index) < scoremap.get(key)) {
          scores.set(index, scoremap.get(key));
          urls.set(index, key);
        }
      }
    }

    while (scores.size() > 0) {
      int index = scores.indexOf(Collections.max(scores));
      out.println(urls.get(index) + "\t" + scores.get(index));
      urls.remove(index);
      scores.remove(index);
    }
    out.close();
  }
Beispiel #8
0
  public static void main(String[] args) throws IOException {
    String line = "";
    ArrayList<String> list = new ArrayList<>();
    try (Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new FileReader(scanner.nextLine()))) {
      while ((line = reader.readLine()) != null) {
        list.addAll(Arrays.asList(line.split(" ")));
      }

      for (int i = 0; i < list.size(); i++) {
        String s = list.get(i);
        String reverse = new StringBuffer(s).reverse().toString();
        if (list.indexOf(reverse) != -1 & !s.equals("") & !s.equals(reverse)) {
          result.add(new Pair(s, reverse));
          list.remove(s);
          list.remove(reverse);
        }
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #9
0
  public void warcont() {
    int g = 0;
    if (mine.size() == 0) return;

    x = rand.nextInt(mine.size());
    card a = mine.get(x);
    mine.remove(x);

    if (mine.size() == 0) {
      comp.recieve(a, ID);
      return;
    }

    x = rand.nextInt(mine.size());
    card b = mine.get(x);
    mine.remove(x);
    if (mine.size() == 0) {
      comp.recieve(a, b, ID);
      return;
    }
    x = rand.nextInt(mine.size());
    card c = mine.get(x);
    mine.remove(x);
    if (mine.size() == 0) {
      comp.recieve(a, b, c, ID);
      return;
    }
    x = rand.nextInt(mine.size());
    card d = mine.get(x);
    mine.remove(x);
    comp.recieve(a, b, c, d, ID);
    while (temps.size() != 0) temps.remove(temps.size());
  }
Beispiel #10
0
 // DELETION FIXED
 public void getISDra2FixedDel() {
   for (int i = 0; i < records.size(); i++) {
     Record cur = records.get(i);
     if (cur.regular) {
       if (cur.doesFirstMatch(674400, 674850, true, "EDGE:145:213")
           && cur.doesSecondMatch(676750, 677000, false, "EDGE:216:277")) {
         System.out.println(cur);
         records.remove(i);
         i--;
       } else if (cur.doesFirstMatch(1387250, 1387550, true, "EDGE:149:325")
           && cur.doesSecondMatch(1389450, 1389700, false, "EDGE:168:281")) {
         System.out.println(cur);
         records.remove(i);
         i--;
       } else if (cur.doesFirstMatch(1611150, 1611550, true, "EDGE:192:280")
           && cur.doesSecondMatch(1613400, 1613750, false, "EDGE:147:324")) {
         System.out.println(cur);
         records.remove(i);
         i--;
       } else if (cur.doesFirstMatch(1952800, 1953125, true, "EDGE:271:283")
           && cur.doesSecondMatch(1955000, 1955300, false, "EDGE:146:313")) {
         System.out.println(cur);
         records.remove(i);
         i--;
       } else if (cur.doesFirstMatch(2321000, 2321350, true, "EDGE:190:282")
           && cur.doesSecondMatch(2323250, 2323600, false, "EDGE:150:242")) {
         System.out.println(cur);
         records.remove(i);
         i--;
       }
     }
   }
   System.out.println();
 }
Beispiel #11
0
 public String pairClusters2string(
     ArrayList<Record> pair1, ArrayList<Record> pair2, boolean left) {
   StringBuffer bf = new StringBuffer();
   for (int i = 0; i < pair1.size(); i++) {
     for (int j = 0; j < pair2.size(); j++) {
       if (pair1.get(i).isInsertionPair(pair2.get(j), left)) {
         bf.append(pair1.get(i) + "\n" + pair2.get(j) + "\n\n");
         pair1.remove(i);
         pair2.remove(j);
         i--;
         j--;
         break;
       }
     }
   }
   if ((pair1.size() + pair2.size()) > 0) {
     bf.append("***** UNPAIRED *****\n");
     for (int i = 0; i < pair1.size(); i++) {
       bf.append(pair1.get(i) + "\n");
     }
     for (int j = 0; j < pair2.size(); j++) {
       bf.append(pair2.get(j) + "\n");
     }
     bf.append("**** END OF UNPAIRED ****\n");
   }
   // bf.append("\n");
   return bf.toString();
 }
Beispiel #12
0
 public boolean removePower(String pow) {
   Iterator<Power> it = powers.iterator();
   Power power = null;
   while (it.hasNext()) {
     Power p = it.next();
     if (p.getName().equalsIgnoreCase(pow)) {
       it.remove();
       power = p;
       rebuild();
       break;
     }
   }
   if (power != null) {
     if (power instanceof PowerHit) {
       powerHit.remove((PowerHit) power);
     }
     if (power instanceof PowerLeftClick) {
       powerLeftClick.remove(power);
     }
     if (power instanceof PowerRightClick) {
       powerRightClick.remove(power);
     }
     if (power instanceof PowerProjectileHit) {
       powerProjectileHit.remove(power);
     }
     if (power instanceof PowerTick) {
       powerTick.remove(power);
     }
   }
   return power != null;
 }
  public static void golf(String file_name) {
    Random rand = new Random();
    ArrayList<Person> players = new ArrayList();
    try {
      Scanner in = new Scanner(new FileReader(file_name));
      while (in.hasNextLine()) {
        String name = in.nextLine();
        Person person = new Person(name);
        players.add(person);
      }
    } catch (Exception e) {
      System.out.println("Could not find file");
    }

    while (!players.isEmpty()) {
      int first, second;
      do {
        first = rand.nextInt(players.size());
        second = rand.nextInt(players.size());
      } while (first == second);
      System.out.println("Team:");
      System.out.println(players.get(first).name);
      System.out.println(players.get(second).name);
      System.out.print("\n");
      players.remove(second);
      if (second < first) {
        players.remove(first - 1);
      } else {
        players.remove(first);
      }
    }
  }
Beispiel #14
0
 public void removeMessageListener(MessageListener listener) {
   synchronized (listeners) {
     int idx = listeners.indexOf(listener);
     if (idx >= 0) {
       listenersDownload.remove(idx);
       listeners.remove(listener);
     }
   }
 }
Beispiel #15
0
  private void removeBuildPath(IResource resource, IProject project) {

    IScriptProject projrct = DLTKCore.create(project);
    IPath filePath = resource.getFullPath();

    oldBuildEntries = Arrays.asList(projrct.readRawBuildpath());

    newBuildEntries = new ArrayList<IBuildpathEntry>();

    newBuildEntries.addAll(oldBuildEntries);

    for (int i = 0; i < oldBuildEntries.size(); i++) {
      IBuildpathEntry fEntryToChange = oldBuildEntries.get(i);
      IPath entryPath = fEntryToChange.getPath();

      int mattchedPath = entryPath.matchingFirstSegments(filePath);

      if (mattchedPath == filePath.segmentCount()) {
        newBuildEntries.remove(fEntryToChange);
      } else {
        IBuildpathEntry newEntry =
            RefactoringUtility.createNewBuildpathEntry(
                fEntryToChange, fEntryToChange.getPath(), filePath, ""); // $NON-NLS-1$
        newBuildEntries.remove(fEntryToChange);
        newBuildEntries.add(newEntry);
      }
    }

    oldIncludePath = new ArrayList<IBuildpathEntry>();

    newIncludePathEntries = new ArrayList<IBuildpathEntry>();
    List<IncludePath> includePathEntries =
        Arrays.asList(IncludePathManager.getInstance().getIncludePaths(project));

    for (IncludePath entry : includePathEntries) {
      Object includePathEntry = entry.getEntry();
      IResource includeResource = null;
      if (!(includePathEntry instanceof IBuildpathEntry)) {
        includeResource = (IResource) includePathEntry;
        IPath entryPath = includeResource.getFullPath();

        IBuildpathEntry oldEntry =
            RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
        oldIncludePath.add((IBuildpathEntry) oldEntry);

        if (filePath.isPrefixOf(entryPath) || entryPath.equals(filePath)) {
        } else {
          IBuildpathEntry newEntry =
              RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
          newIncludePathEntries.add(newEntry);
        }
      } else {
        newIncludePathEntries.add((IBuildpathEntry) includePathEntry);
        oldIncludePath.add((IBuildpathEntry) includePathEntry);
      }
    }
  }
 public void remove(@NotNull Change change) {
   if (change.getType().isApplied()) {
     LOG.assertTrue(myAppliedChanges.remove(change), change);
   } else {
     LOG.assertTrue(myChanges.remove(change), change);
   }
   change.onRemovedFromList();
   fireOnChangeRemoved();
 }
 public static void remove(ArrayList<Integer> list, ArrayList<Integer> list2) {
   for (int i = 0; i < list.size() - 1; i++) {
     for (int k = i + 1; k < list.size(); k++) {
       if (list.get(i).equals(list.get(k)) && list2.get(i).equals(list2.get(k))) {
         list.remove(k);
         list2.remove(k);
         k--;
       }
     }
   }
 }
Beispiel #18
0
 public void undo() {
   if (undos.size() > 0) {
     Shape s = undos.get(undos.size() - 1);
     undos.remove(s);
     undos.add(s);
     shapes.remove(s);
     this.repaint();
     cpt--;
     notifyObservers();
   }
 }
Beispiel #19
0
  public static void main(String[] args) {

    ArrayList<Object> a = new ArrayList<Object>();
    ArrayList<Object> b = new ArrayList<Object>();

    long t = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
      a.add("x");
    }
    System.out.println(System.currentTimeMillis() - t);

    /*long s = System.currentTimeMillis();
    for (int i=0;i<100000;i++){
        b.add(0,"x");
    }
    System.out.println(System.currentTimeMillis() - t);
    */

    // Adding element in the front position takes more time
    // Running time-
    // At the end:15ms
    // Beginning:1046ms

    /*t = System.currentTimeMillis();
    for (int i=0;i<100000;i++){
        a.remove(0);
    }
    System.out.println(System.currentTimeMillis() - t);
    Takes 1078ms
    */
    t = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
      a.remove(a.size() - 1);
    }
    System.out.println(a);
    System.out.println(System.currentTimeMillis() - t);
    // Takes 8ms
    //
    // Removing From the end is much faster

    for (int i = 0; i < 15; i++) {
      b.add(i);
    }
    System.out.println(b);

    // Code to reverse the array values

    for (int i = 0; i < b.size(); i++) {
      b.add(i, b.get(b.size() - 1));
      b.remove(b.size() - 1);
    }
    System.out.println(b);
  }
  public PopsIOSpeciesTreeModel(
      PopsIOSpeciesBindings piosb, Parameter popPriorScale, PriorComponent[] priorComponents) {
    super(PopsIOSpeciesTreeModelParser.PIO_SPECIES_TREE);
    this.piosb = piosb;

    this.popPriorScale = popPriorScale;
    addVariable(popPriorScale);
    popPriorScale.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));

    this.priorComponents = priorComponents;

    PopsIOSpeciesBindings.SpInfo[] species = piosb.getSpecies();
    int nTaxa = species.length;
    int nNodes = 2 * nTaxa - 1;
    pionodes = new PopsIONode[nNodes];
    for (int n = 0; n < nNodes; n++) {
      pionodes[n] = new PopsIONode(n);
    }
    ArrayList<Integer> tojoin = new ArrayList<Integer>(nTaxa);
    for (int n = 0; n < nTaxa; n++) {
      pionodes[n].setTaxon(species[n].name);
      pionodes[n].setHeight(0.0);
      pionodes[n].setUnion(piosb.tipUnionFromTaxon(pionodes[n].getTaxon()));
      tojoin.add(n);
    }
    double rate = 1.0;
    double treeheight = 0.0;
    for (int i = 0; i < nTaxa - 1; i++) {
      int numtojoin = tojoin.size();
      int j = MathUtils.nextInt(numtojoin);
      Integer child0 = tojoin.get(j);
      tojoin.remove(j);
      int k = MathUtils.nextInt(numtojoin - 1);
      Integer child1 = tojoin.get(k);
      tojoin.remove(k);
      pionodes[nTaxa + i].addChildren(pionodes[child0], pionodes[child1]);
      pionodes[nTaxa + i].setHeight(treeheight + randomnodeheight(numtojoin * rate));
      treeheight = pionodes[nTaxa + i].getHeight();
      tojoin.add(nTaxa + i);
    }
    rootn = pionodes.length - 1;

    double scale = 0.99 * piosb.initialMinGeneNodeHeight() / pionodes[rootn].height;
    scaleAllHeights(scale);
    pionodes[rootn].fillinUnionsInSubtree(piosb.getSpecies().length);

    stree = makeSimpleTree();

    Logger.getLogger("dr.evomodel.speciation.popsio")
        .info(
            "\tConstructing a PopsIO Species Tree Model, please cite:\n"
                + Citable.Utils.getCitationString(this));
  }
Beispiel #21
0
  public ArrayList<Edge> search(int begNode) {
    // build list of edges for the result
    ArrayList<Edge> result = new ArrayList<Edge>();

    // you have a list of nodes that have been visited
    ArrayList<Integer> done = new ArrayList<Integer>();

    // populate the todo
    ArrayList<Integer> todo = new ArrayList<Integer>();
    for (int i = 0; i < 18; i++) {
      todo.add(i);
    }

    // stick the start node into done, remove from todo
    done.add(begNode);
    todo.remove(begNode);

    // this will be used for the getting of options
    PriorityQueue<Edge> edges = new PriorityQueue<Edge>();

    // until all the nodes are in done
    while (done.size() != 18) {
      // System.out.println("todo:			"+todo);
      // System.out.println("done:			"+done);
      // System.out.println("current result: \t"+result);
      // System.out.println("");
      // get the options currently available, starting at done nodes
      // and ending on "todo" nodes, and load them into a priority queue
      for (int i = 0; i < done.size(); i++) {
        int start = done.get(i);
        for (int j = 0; j < todo.size(); j++) {
          int end = todo.get(j);
          // System.out.println(" edge we are adding is " + start + " to " + end);
          edges.add(new Edge(c, start, end));
        }
      }

      // take the one off the top, add it to result
      Edge winner = edges.poll();
      // System.out.println("The winner is: " + winner);
      result.add(winner);

      // set it's new node as visited
      done.add((Integer) winner.end());
      todo.remove((Integer) winner.end());

      // clear the edges at the end
      edges.clear();
    }

    return result;
  }
Beispiel #22
0
 public void removeAdditionalPanels() {
   if (getCurrentPanelCount() > 3) {
     for (int i = 3; i < getCurrentPanelCount(); i++) {
       ConceptTreePanel panel = panelList.get(3);
       JLabel label = andOrLabelList.get(2);
       panel.setVisible(false);
       label.setVisible(false);
       panelList.remove(3);
       andOrLabelList.remove(2);
     }
     panelCount = 3;
   }
 }
Beispiel #23
0
  public String getIS2621FixedDel() {
    StringBuffer bf = new StringBuffer();
    Record pair1 = null;
    int pair1Index = -1;
    Record pair2 = null;
    int pair2Index = -1;

    for (int i = 0; i < records.size(); i++) {
      Record cur = records.get(i);
      if (cur.regular) {
        if (cur.doesFirstMatch(1637700, 1638000, true, "EDGE:147:324")
            && cur.doesSecondMatch(1639600, 1639900, false, "EDGE:107:349")) {
          bf.append(cur + "\n\n");
          records.remove(i);
          i--;
        } else if (cur.doesFirstMatch(1337450, 1337750, true, "EDGE:28:109")
            && cur.doesSecondMatch(1339350, 1339600, false, "EDGE:149:325")) {
          bf.append(cur + "\n\n");
          records.remove(i);
          i--;
        } else if (cur.doesFirstMatch(231925, 231975, false, "EDGE:194:330")
            && cur.doesSecondMatch(881050, 881300, true, "EDGE:111:239")) {
          pair1 = cur;
          records.remove(i);
          i--;
          pair1Index = i;
        } else if (cur.doesFirstMatch(881200, 881350, true, "EDGE:111:239")
            && cur.doesSecondMatch(883000, 883200, false, "EDGE:185:335")) {
          pair2 = cur;
          records.remove(i);
          i--;
          pair2Index = i;
        }
      }
    }
    if (pair1Index > -1 && pair2Index > -1) {
      bf.append(pair1 + "\n" + pair2 + "\n\n");
      // records.remove(pair1Index);
      // records.remove(pair2Index);
    } else if (pair1Index == -1 && pair2Index > -1) {
      bf.append("**MISSING**\n" + pair2 + "\n\n");
      // records.remove(pair2Index);
    } else if (pair1Index > -1 && pair2Index == -1) {
      bf.append(pair1 + "\n**MISSING**\n\n");
      // records.remove(pair1Index);
    } else {
      bf.append("**MISSING**\n**MISSING**\n\n");
    }

    return bf.toString();
  }
Beispiel #24
0
  public static void readFromFile(File inFile, Project project) {
    Scanner sc = null;
    try {
      sc = new Scanner(inFile);
    } catch (java.io.FileNotFoundException e) {
      System.out.println("File not found, quitting");
      System.exit(1);
    }
    if (sc.hasNext()) {
      num_tasks = Integer.parseInt(sc.next());
      System.out.println("Number of tasks: " + Integer.toString(num_tasks));
    }

    int counter = 1;

    while (sc.hasNextLine()) {
      ArrayList<String> tmp_string_arr = new ArrayList<>();
      for (String s : sc.nextLine().split("\\s")) tmp_string_arr.add(s);

      while (tmp_string_arr.remove("")) ;
      while (tmp_string_arr.remove(" ")) ;

      for (String s : tmp_string_arr) System.out.print(s + ",");
      System.out.println("");

      String[] tmp_string = {};
      tmp_string = tmp_string_arr.toArray(tmp_string);

      int id = -1;

      try {
        id = Integer.parseInt(tmp_string[0]);
      } catch (java.lang.NumberFormatException e) {
        id = -1; // Will not make new task
      } catch (java.lang.ArrayIndexOutOfBoundsException e) {
        id = -1;
      }

      if (id == counter) {
        String name = tmp_string[1];
        int time = Integer.parseInt(tmp_string[2]);
        int staff = Integer.parseInt(tmp_string[3]);
        int[] dependencies = new int[tmp_string.length - 5];
        for (int i = 4; i < tmp_string.length - 1; i++)
          dependencies[i - 4] = Integer.parseInt(tmp_string[i]);
        project.addTask(id, name, time, staff, dependencies);
        System.out.println("Created new task");
        counter++;
      }
    }
  }
Beispiel #25
0
 Point[] getConvex(Point[] points) {
   ArrayList<Point> hull = new ArrayList<Point>();
   for (Point p : points) {
     while (hull.size() >= 2
         && !isConvex(hull.get(hull.size() - 2), hull.get(hull.size() - 1), p)) {
       hull.remove(hull.size() - 1);
     }
     hull.add(p);
   }
   while (hull.size() >= 2 && hull.get(hull.size() - 1).x == hull.get(hull.size() - 2).x) {
     hull.remove(hull.size() - 1);
   }
   return hull.toArray(new Point[0]);
 }
  private ProgressIndicatorEx removeFromMaps(@NotNull InlineProgressIndicator progress) {
    final ProgressIndicatorEx original = myInline2Original.get(progress);

    myInline2Original.remove(progress);

    myOriginal2Inlines.remove(original, progress);
    if (myOriginal2Inlines.get(original) == null) {
      final int originalIndex = myOriginals.indexOf(original);
      myOriginals.remove(originalIndex);
      myInfos.remove(originalIndex);
    }

    return original;
  }
  @Test
  public void testBasic() {
    ArrayList<String> al = new ArrayList<>();
    al.add("x");
    al.add("y");
    al.add("z");

    assertThat(al.length(), is(3));
    assertThat(al.get(1), is("y"));
    assertThat(al.removeLast(), is("z"));
    assertThat(al.remove("y"), is(true));
    assertThat(al.length(), is(1));
    assertThat(al.remove("a"), is(false));
  }
 public void helper(
     ArrayList<ArrayList<Integer>> res, ArrayList<Integer> list, TreeNode root, int sum) {
   if (root == null) return;
   if (root.val == sum && root.left == null && root.right == null) {
     list.add(root.val);
     res.add(new ArrayList<Integer>(list));
     list.remove(list.size() - 1);
     return;
   }
   list.add(root.val);
   helper(res, list, root.left, sum - root.val);
   helper(res, list, root.right, sum - root.val);
   list.remove(list.size() - 1);
 }
Beispiel #29
0
 /**
  * removes a user from the user list
  *
  * @param un the name of the user to be removed
  */
 public void userDel(String un) {
   users.remove(users.indexOf(un));
   if (ignores.contains(un)) {
     ignores.remove(ignores.indexOf(un));
   }
   if (afks.contains(un)) {
     afks.remove(afks.indexOf(un));
   }
   if (admins.contains(un)) {
     admins.remove(admins.indexOf(un));
   }
   updateList();
   serverMessage(un + " has left " + server.channel);
   privates.serverMessage(un, un + " has left");
 }
 private void removeOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) {
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     idmapAL.remove(mapping.getKey());
     if (idmapAL.size() <= 0) fOrderedElements.remove(idmap.getName());
     ArrayList ordered = idmap.getOrdered();
     ordered.remove(mapping);
     if (ordered.size() <= 0) idmap.setOrdered(null);
     itemsOrdered[0].dispose(); // Table is single selection
   }
 }