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());
         }
       });
 }
Exemplo n.º 4
1
  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;
  }
Exemplo n.º 5
0
 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()]);
 }
Exemplo n.º 6
0
 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()]);
 }
Exemplo n.º 7
0
 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()]);
 }
Exemplo n.º 8
0
 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()]);
 }
Exemplo n.º 9
0
 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()]);
 }
Exemplo n.º 10
0
 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()]);
 }
Exemplo n.º 11
0
 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()]);
 }
Exemplo 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());
 }
Exemplo n.º 13
0
 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()]);
 }
Exemplo 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);
  }
Exemplo 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();
    }
  }
Exemplo 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);
  }
Exemplo 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));
       });
 }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo n.º 25
0
  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);
    }
  }