public void update() {
   for (int i = 0; i < entities.size(); i++) {
     Entity entity = entities.get(i);
     entity.update();
   }
   entities.sort(renderSort);
 }
  /**
   * Return the list of found directories
   *
   * @param u
   * @param regex
   * @param container
   * @return
   */
  public static List<Directory> searchDirectories(
      User u, String regex, Directory container, boolean recursive, SortType sort) {
    MongoCollection<Document> collection = DataBase.getInstance().getCollection("directories");
    ArrayList<Directory> directories = new ArrayList<Directory>();

    BasicDBObject query = new BasicDBObject();
    query.put("owner", new ObjectId(u.UID));
    query.put("name", new BasicDBObject("$regex", regex));
    if (recursive) query.put("path", new BasicDBObject("$regex", "^" + container.getInnerPath()));
    else query.put("path", new BasicDBObject("$regex", "^" + container.getInnerPath() + "$"));

    FindIterable<Document> results = collection.find(query);

    // Sort
    // No sort from mongodb

    for (Document d : results) {
      directories.add(new Directory(d));
    }

    // Sort (not handled by mongodb)
    switch (sort) {
      case NAME_ASC:
        directories.sort(
            new Comparator<Directory>() {
              @Override
              public int compare(Directory d1, Directory d2) {
                return String.CASE_INSENSITIVE_ORDER.compare(d1.name, d2.name);
              }
            });
        break;
      case NAME_DSC:
        directories.sort(
            new Comparator<Directory>() {
              @Override
              public int compare(Directory d1, Directory d2) {
                return String.CASE_INSENSITIVE_ORDER.compare(d2.name, d1.name);
              }
            });
        break;
      default:
        break;
    }
    return directories;
  }
 private void setArrayList() {
   arrayList = new ArrayList<RawMaterial>(list.keySet());
   arrayList.sort(
       new Comparator<RawMaterial>() {
         @Override
         public int compare(RawMaterial o1, RawMaterial o2) {
           return o1.getName().compareTo(o2.getName());
         }
       });
 }
  private String sort(MemoriCommand command, GoogleSync googleSync) {
    Boolean[] f_values = command.getMemoriField();

    for (int i = 0; i < f_values.length; i++) {
      if (f_values[i] == Boolean.TRUE) {
        if (i == 0) {
          memoriCalendar.sort(MemoriEvent.nameComparator);
        } else if (i == 1) {
          memoriCalendar.sort(MemoriEvent.startDateComparator);
        } else if (i == 2) {
          memoriCalendar.sort(MemoriEvent.endDateComparator);
        } else if (i == 3) {
          memoriCalendar.sort(MemoriEvent.descriptionComparator);
        } else {
          memoriCalendar.sort(MemoriEvent.locationComparator);
        }
      }
    }
    return MESSAGE_SORT;
  }
 public static Achievement[] getAchievements() {
   ArrayList<Achievement> a = new ArrayList<Achievement>();
   a.addAll(achievements.values());
   a.sort(
       new Comparator<Achievement>() {
         @Override
         public int compare(Achievement o1, Achievement o2) {
           return o1.id.compareTo(o2.id);
         }
       });
   return a.toArray(new Achievement[a.size()]);
 }
 public static Attribute[] getAttributes() {
   ArrayList<Attribute> a = new ArrayList<Attribute>();
   a.addAll(attributes.values());
   a.sort(
       new Comparator<Attribute>() {
         @Override
         public int compare(Attribute o1, Attribute o2) {
           return o1.id.compareTo(o2.id);
         }
       });
   return a.toArray(new Attribute[a.size()]);
 }
 public static Block[] getBlocks() {
   ArrayList<Block> a = new ArrayList<Block>();
   a.addAll(blocks.values());
   a.sort(
       new Comparator<Block>() {
         @Override
         public int compare(Block o1, Block o2) {
           return o1.idString.compareTo(o2.idString);
         }
       });
   return a.toArray(new Block[a.size()]);
 }
 public static EnchantmentType[] getEnchantmentTypes() {
   ArrayList<EnchantmentType> a = new ArrayList<EnchantmentType>();
   a.addAll(enchantments.values());
   a.sort(
       new Comparator<EnchantmentType>() {
         @Override
         public int compare(EnchantmentType o1, EnchantmentType o2) {
           return o1.idString.compareTo(o2.idString);
         }
       });
   return a.toArray(new EnchantmentType[a.size()]);
 }
 public static Entity[] getEntities() {
   ArrayList<Entity> a = new ArrayList<Entity>();
   a.addAll(entities.values());
   a.sort(
       new Comparator<Entity>() {
         @Override
         public int compare(Entity o1, Entity o2) {
           return o1.id.compareTo(o2.id);
         }
       });
   return a.toArray(new Entity[a.size()]);
 }
 public static Item[] getItems() {
   ArrayList<Item> a = new ArrayList<Item>();
   a.addAll(items.values());
   a.sort(
       new Comparator<Item>() {
         @Override
         public int compare(Item o1, Item o2) {
           return o1.idString.compareTo(o2.idString);
         }
       });
   return a.toArray(new Item[a.size()]);
 }
 public static Particle[] getParticles() {
   ArrayList<Particle> a = new ArrayList<Particle>();
   a.addAll(particles.values());
   a.sort(
       new Comparator<Particle>() {
         @Override
         public int compare(Particle o1, Particle o2) {
           return o1.id.compareTo(o2.id);
         }
       });
   return a.toArray(new Particle[a.size()]);
 }
Esempio n. 12
0
 @Test
 public void testPopAll() throws Exception {
   for (String inputArrayItem : inputArray) {
     stack.push(inputArrayItem);
   }
   stack.popAll(inputList);
   assertEquals(inputArray.length, inputList.size());
   assertTrue(stack.isEmpty());
   Arrays.sort(inputArray, new LengthComparator());
   inputList.sort(new LengthComparator());
   assertEquals(Arrays.deepToString(inputArray), inputList.toString());
 }
 public static Sound[] getSounds() {
   ArrayList<Sound> a = new ArrayList<Sound>();
   a.addAll(sounds.values());
   a.sort(
       new Comparator<Sound>() {
         @Override
         public int compare(Sound o1, Sound o2) {
           return o1.id.compareTo(o2.id);
         }
       });
   return a.toArray(new Sound[a.size()]);
 }
Esempio n. 14
0
  public List<User> getSetOfHosts() {
    final ArrayList<User> hosts = Lists.newArrayList(activeGames.keySet());

    hosts.sort(
        new Ordering<User>() {
          @Override
          public int compare(@Nullable User left, @Nullable User right) {
            return left.getUserName().compareTo(right.getUserName());
          }
        });

    return ImmutableList.copyOf(hosts);
  }
Esempio n. 15
0
  public static void main(String[] args) {
    String strnum = null;
    int[][] nums = new int[3][3];
    ArrayList<block> openlist = new ArrayList<block>();
    ArrayList<block> closedlist = new ArrayList<block>();

    Comparator<block> sortmethod =
        new Comparator<block>() {
          @Override
          public int compare(block b1, block b2) {

            return b1.compareTo(b2);
          }
        };

    strnum = JOptionPane.showInputDialog("ยฐร‹รŽยปร„ร‘รŠรฝ", "ร‡รซรŠรครˆรซยฐร‹รŽยปรŠรฝร—ร–ร—ร–ยทรป");

    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++)
        nums[i][j] = Integer.valueOf(String.valueOf(strnum.charAt(i * 3 + j)));
    block b = new block(-1, null, null, nums);
    openlist.add(b);

    while (openlist != null) {

      closedlist.add(openlist.get(0));

      closedlist.get(0).PrintIndex();
      // System.out.println(' '+closedlist.get(0).judge());

      System.out.println();

      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      if (closedlist.get(0).wrongNum() == 0) break;

      closedlist = getChildList(closedlist);

      for (int i = 0; i < closedlist.size(); i++) openlist.add(closedlist.get(i));

      openlist.remove(0);
      openlist.sort(sortmethod);

      closedlist.clear();
    }
  }
Esempio n. 16
0
  public static void main(String[] args) {
    // main() ๋ฉ”์„œ๋“œ์—์„œ๋งŒ ์‚ฌ์šฉํ•  ํด๋ž˜์Šค๋ผ๋ฉด, ๋กœ์ปฌ ์ค‘์ฒฉ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด๋ผ!
    class MyComparator implements Comparator<String> {
      @Override
      public int compare(String s1, String s2) {
        return s1.toLowerCase().compareTo(s2.toLowerCase());
      }
    }

    ArrayList<String> list = new ArrayList<>();
    list.add("111");
    list.add("aaa");
    list.add("444");
    list.add("BBB");
    list.add("222");
    list.add("333");
    list.add("aab");
    list.add("Aac");

    // ์ •๋ ฌ ์ „
    printList(list);

    // ์ •๋ ฌ
    MyComparator comp = new MyComparator();
    list.sort(comp);
    // ๋ฌธ์ œ์ 1)
    // ์ด ์ฝ”๋“œ๋ฅผ ์œ ์ง€๋ณด์ˆ˜ ํ•˜๋Š” ํ›„์ž„์ž๋Š” ๋„๋Œ€์ฒด MyComparator๊ฐ€ ์–ด๋–ค ์ผ์„ ํ•˜๋Š”
    // ํด๋ž˜์Šค์ธ์ง€ ๊ถ๊ธˆํ•˜๋‹ค.
    // ๊ทธ๋ž˜์„œ ์ด ํ›„์ž„์ž๋Š” ์œ„๋กœ ์Šคํฌ๋กคํ•˜์—ฌ ํด๋ž˜์Šค๋ฅผ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•  ๊ฒƒ์ด๋‹ค.
    // ํ™•์ธํ•œ ๋‹ค์Œ์— ๋‹ค์‹œ ์ด ์œ„์น˜๋กœ ๋‚ด๋ ค์™€์„œ ์ด ์ฝ”๋“œ์˜ ์˜๋ฏธ๋ฅผ ์ดํ•ดํ•˜๋ ค๊ณ 
    // ๋…ธ๋ ฅํ•  ๊ฒƒ์ด๋‹ค.
    // ๊ทธ๋‚˜๋งˆ ์ด ์˜ˆ์ œ๋Š” ์Šคํฌ๋กค์„ ์‚ด์ง๋งŒ ํ•ด๋„ MyComparator ํด๋ž˜์Šค์˜ ์ฝ”๋“œ๋ฅผ
    // ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์„œ ๋‹คํ–‰์ด๋‹ค.
    // ๋งŒ์•ฝ ๋ฉ”์„œ๋“œ์˜ ์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์„œ ์—ฌ๋Ÿฌ ํŽ˜์ด์ง€๋ฅผ ์Šคํฌ๋กคํ•ด์•ผ๋งŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค๋ฉด,
    // ์•„~~~~~ ์–ผ๋งˆ๋‚˜ ํ”ผ๊ณคํ•  ๊ฒƒ์ธ๊ฐ€?
    // ์ข‹์€ ํ•ด๊ฒฐ์ฑ…?
    // => ๊ฐ€๋Šฅํ•œ ๊ทธ์™€ ๊ด€๋ จ๋œ ์ฝ”๋“œ๋Š” ๊ทผ์ฒ˜์— ์žˆ๋Š” ๊ฒƒ์ด ์ฝ”๋“œ๋ฅผ ์ดํ•ดํ•˜๋Š”๋ฐ
    // ๋„์›€์ด ๋œ๋‹ค.
    // => ๊ฐ€๋Šฅํ•œ ๊ด€๋ จ๋œ ์ฝ”๋“œ๋Š” ๊ฐ€๊นŒ์ด์— ๋‘์–ด๋ผ!

    // ๋ฌธ์ œ์ 2)
    // MyComparator ๊ฐ์ฒด๋ฅผ ์˜ค์ง ํ•œ ๊ฐœ๋งŒ ๋งŒ๋“ ๋‹ค.
    //
    // ์œ„์˜ ๋‘ ๊ฐœ์˜ ๋ฌธ์ œ๋ฅผ ํ•œ๊บผ๋ฒˆ์— ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•? ์ต๋ช… ์ค‘์ฒฉ ํด๋ž˜์Šค!

    // ์ •๋ ฌ ํ›„
    printList(list);
  }
Esempio n. 17
0
 /**
  * Homework 2: Implement the median filter. The java function java.util.Arrays.sort(array) can be
  * used to sort an array.
  *
  * @param img the graylevel image (row major representation)
  * @param w width of the image
  * @param h height of the image
  * @param filterSize the size of the filter, which is supplied by the user
  */
 public void medianFilter(byte[] img, int w, int h, int filterSize) {
   applyFilter(
       img,
       w,
       h,
       filterSize,
       (newPoints) -> {
         ArrayList<Integer> values = new ArrayList<Integer>();
         for (int z = 0; z < newPoints.length; z = z + 2) {
           int newX = newPoints[z];
           int newY = newPoints[z + 1];
           if (newX >= 0 && newX < h && newY >= 0 && newY < w) {
             values.add((0xFF & img[newX * w + newY]));
           }
         }
         values.sort(Integer::compare);
         return (byte) ((int) values.get(values.size() / 2));
       });
 }
Esempio n. 18
0
  /**
   * Computes the layout of the data section and closes this object to further updates.
   *
   * <p>This must be called exactly once.
   */
  public void close() {
    checkOpen();
    closed = true;

    // simple heuristic: put items with larger alignment requirement first
    dataItems.sort((a, b) -> a.alignment - b.alignment);

    int position = 0;
    int alignment = 1;
    for (Data d : dataItems) {
      alignment = lcm(alignment, d.alignment);
      position = align(position, d.alignment);

      d.ref.setOffset(position);
      position += d.size;
    }

    sectionAlignment = alignment;
    sectionSize = position;
  }
 private String fixVariablesOrOperator(String var) {
   ArrayList<String> term = formatTerms(var);
   term.sort(
       new Comparator<String>() {
         @Override
         public int compare(String arg0, String arg1) {
           if (arg0.charAt(0) == arg1.charAt(0)) return 0;
           else if (arg0.charAt(0) > arg1.charAt(0)) return 1;
           else return -1;
         }
       });
   String temp = "";
   for (int x = 0; x < term.size(); x++) {
     if (term.get(x).length() == 3 && term.get(x).charAt(term.get(x).length() - 1) == '1') {
       temp += term.get(x).charAt(0) + "";
     } else {
       temp += term.get(x);
     }
   }
   return temp;
 }
 /** Creates new form StartupActionsPreferencesPanel */
 public StartupActionsPreferencesPanel() {
   initComponents();
   this.actionsTbl
       .getSelectionModel()
       .addListSelectionListener(
           (ListSelectionEvent e) -> {
             int row = this.actionsTbl.getSelectedRow();
             this.upBtn.setEnabled(row != 0 && row != -1);
             this.downBtn.setEnabled(row != this.actionsTbl.getRowCount() - 1 && row != -1);
             this.removeBtn.setEnabled(row != -1);
           });
   ArrayList<JMenuItem> items = new ArrayList<>();
   InstanceManager.getDefault(StartupActionsManager.class)
       .getFactories()
       .values()
       .stream()
       .forEach(
           (factory) -> {
             JMenuItem item = new JMenuItem(factory.getActionText());
             item.addActionListener(
                 (ActionEvent e) -> {
                   StartupModel model = factory.newModel();
                   factory.editModel(model, this.getTopLevelAncestor());
                   if (model.getName() != null && !model.getName().isEmpty()) {
                     InstanceManager.getDefault(StartupActionsManager.class).addAction(model);
                   }
                 });
             items.add(item);
           });
   items.sort((JMenuItem o1, JMenuItem o2) -> o1.getText().compareTo(o2.getText()));
   items
       .stream()
       .forEach(
           (item) -> {
             this.actionsMenu.add(item);
           });
 }
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    // read products file
    Scanner scanner = null;
    String[] productInfo = null;

    try {
      scanner = new Scanner(new File(args[0]));

      Product pEntry = null;
      // product ID, price, length, width, height, weight
      int mId = -1;
      int mPrice = -1;
      int mLength = -1;
      int mWidth = -1;
      int mHeight = -1;
      int mWeight = -1;
      int mDimension = -1;
      double mWeightedRank = -1;

      while (scanner.hasNextLine()) {

        productInfo = scanner.nextLine().split(",");

        mId = Integer.valueOf(productInfo[0]);
        mPrice = Integer.valueOf(productInfo[1]);
        mLength = Integer.valueOf(productInfo[2]);
        mWidth = Integer.valueOf(productInfo[3]);
        mHeight = Integer.valueOf(productInfo[4]);
        mWeight = Integer.valueOf(productInfo[5]);

        // if item cannot fit the tote, skip it
        if ((mLength > Tote.HEIGHT) && (mLength > Tote.WIDTH) && (mLength > Tote.LENGTH)) continue;
        else if ((mWidth > Tote.HEIGHT) && (mWidth > Tote.WIDTH) && (mWidth > Tote.LENGTH))
          continue;
        else if ((mHeight > Tote.HEIGHT) && (mHeight > Tote.WIDTH) && (mHeight > Tote.LENGTH))
          continue;

        // keep track of smallest side
        if ((minSide == 0) || (minSide > mLength) || (minSide > mWidth) || (minSide > mHeight))
          minSide = Math.min(mLength, Math.min(mWidth, mHeight));

        // get dimension of product
        mDimension = mLength * mWidth * mHeight;

        // mWeightedRank =
        // ((1-((double)mDimension/Tote.dimension))*((double)mPrice/mDimension))*Tote.dimension;
        mWeightedRank = (double) mPrice / mDimension;

        pEntry =
            new Product(mId, mPrice, mWeight, mDimension, mWeightedRank, mLength, mWidth, mHeight);

        warehouseItems.add(pEntry);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (scanner != null) scanner.close();
    }

    // order by most efficient price to size ratio
    warehouseItems.sort(
        new Comparator<Product>() {
          @Override
          public int compare(Product o1, Product o2) {
            // TODO Auto-generated method stub
            if (o1.getWeightedRank() - o2.getWeightedRank() > 0) return -1;
            // if price to size ratio is same, order by lightest weight
            else if (o1.getWeightedRank() - o2.getWeightedRank() == 0) {
              return (o1.getWeight() - o2.getWeight());
            } else return 1;
          }
        });

    // TODO: change it to recursion
    // keep adding to tote history
    // will have to implement if minimum size reached then break iteration
    Tote tote = null;
    for (Product ip : warehouseItems) {
      tote = new Tote();
      tote.add(ip);
      for (Product p : warehouseItems) {
        tote.add(p);
        if (!tote.canFit(minSide)) {
          break;
        }
        for (Product pp : warehouseItems) {
          tote.add(pp);
          if (!tote.canFit(minSide)) {
            break;
          }
        }
      }
      // add to history list
      toteHistory.add(tote);
      tote = null;
    }

    toteHistory.sort(
        new Comparator<Tote>() {
          @Override
          public int compare(Tote o1, Tote o2) {
            // TODO Auto-generated method stub
            return o2.getValue() - o1.getValue();
          }
        });

    tote = toteHistory.get(0);
    for (Product p : tote.getProducts()) {
      System.out.println(p.toString());
    }

    System.out.println("email to : " + tote.getProductIdSum() + "@redmart.com");
  }
 private static <T extends AbstractBlockBase<T>> Deque<T> createQueue(List<T> blocks) {
   ArrayList<T> queue = new ArrayList<>(blocks);
   queue.sort(BiDirectionalTraceBuilder::compare);
   return new ArrayDeque<>(queue);
 }
Esempio n. 23
0
 public static void sort(ArrayList<ArrayList<Integer>> aList) {
   for (Iterator<ArrayList<Integer>> i = aList.iterator(); i.hasNext(); ) {
     ArrayList<Integer> aSet = i.next();
     aSet.sort(null);
   }
 }
 public void sort() {
   processQueue.sort(null);
 }
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);

    int m = Integer.parseInt(scn.nextLine());

    String s = scn.nextLine();

    String sArr[] = s.split(" ");
    int arr[] = strToIntArr(sArr);

    int n = arr[0];
    int f = arr[1];
    int t = arr[2];
    int l = arr[3];

    Station st[] = new Station[n];

    for (int i = 0; i < n; i++) {
      String ss = scn.nextLine();
      String ssArr[] = ss.split(" ");
      int arr2[] = strToIntArr(ssArr);
      int distance = arr2[0];
      int cost = arr2[1];
      st[i] = new Station(i + 1, cost, distance);
    }

    int cl = 0;
    int sum = 0;

    if (t >= l) {
      System.out.println(sum);
    } else {
      ArrayList<Station> sInit = new ArrayList<Station>();
      int i = 0;
      while (i < n && st[i].getDistance() <= t) {
        sInit.add(st[i]);
        i++;
      }

      sInit.sort(
          new Comparator<Station>() {
            @Override
            public int compare(Station o1, Station o2) {

              return o1.getCost() - o2.getCost();
            }
          });

      if (!sInit.isEmpty()) {
        Station currentSt = (Station) sInit.get(0);

        // System.out.println(currentSt);

        cl = currentSt.getDistance();
        t -= currentSt.getDistance();
        while (cl < l) {
          System.out.println(currentSt);

          int j = currentSt.getIndex();
          ArrayList<Station> sts = new ArrayList<Station>();
          while (j < n && st[j].getDistance() - cl <= f) {
            sts.add(st[j]);
            j++;
          }

          sts.sort(
              new Comparator<Station>() {
                @Override
                public int compare(Station o1, Station o2) {

                  return o1.getCost() - o2.getCost();
                }
              });

          if (isEnd(cl, l, f)) {
            if (isCurrentStCheapest(sts, currentSt)) {
              sum += (l - currentSt.getDistance() - t) * currentSt.getCost();
            } else {
              if (!sts.isEmpty()) {
                int dis = sts.get(0).getDistance() - currentSt.getDistance();
                sum = sum + (dis - t) * currentSt.getCost();
              } else {
                sum += (l - currentSt.getDistance() - t) * currentSt.getCost();
              }
            }
          } else {
            if (isCurrentStCheapest(sts, currentSt)) {
              sum = sum + ((f - t) * currentSt.getCost());
              t = f;
            } else {
              int dis = sts.get(0).getDistance() - currentSt.getDistance();
              sum = sum + (dis - t) * currentSt.getCost();
              t = 0;
            }
          }

          if (!sts.isEmpty()) {
            if (t > 0) {
              t = sts.get(0).getDistance() - currentSt.getDistance();
            }
            currentSt = sts.get(0);
            cl = currentSt.getDistance();

          } else {
            cl = l;
          }
        }
      }

      System.out.println("Final Sum: " + sum);
    }
  }