Ejemplo n.º 1
0
 @Override
 public void update() {
   LinkedList<TubeItem> removeQueue = new LinkedList<TubeItem>();
   for (TubeItem t : itemFlow) {
     t.update();
     if (t.hasCrossedCenter) {
       if (!t.pathFoundByParent) {
         // TODO Pathfind from here and set item.direction under these conditions:
         // 1) If this pipe is a node (contains a turn point)
         // 2) If item cannot continue straight.
       }
       t.pathFoundByParent = true;
     }
     if (t.progress > 100) {
       BlockCoord bc = new BlockCoord(x(), y(), z()).offset(t.direction);
       TileMultipart tile = BasicUtils.getMultipartTile(world(), bc);
       if (tile != null) {
         TMultiPart tp = tile.partMap(6);
         if (tp instanceof ITubeInterface && ((ITubeInterface) tp).addItem(t, t.direction)) {
           removeQueue.add(t);
         }
       }
     }
   }
   itemFlow.removeAll(removeQueue);
 }
Ejemplo n.º 2
0
 /** @param properties */
 private void checkProperties(Map<String, String> properties) {
   Set<String> keys = properties.keySet();
   if (!keys.containsAll(expectedProperties)) {
     LinkedList<String> missingProperties = new LinkedList<String>(expectedProperties);
     missingProperties.removeAll(keys);
     throw new InvitationException(
         "The following mandatory properties are missing:\n" + missingProperties);
   }
 }
  // Overload method to perfom the actual file writing
  public static void writeToFile() {
    // Write the data to the file
    if (DataCollection.size() > 0) {
      System.out.println("Wrote to file" + DataCollection.get(0));
      FileManager.flushFile();

      // Delete the contents of the collection
      DataCollection.removeAll(DataCollection);
    }
  }
Ejemplo n.º 4
0
  private void paintAnimations(Graphics2D g2d) {

    LinkedList<Animation> toRemove = new LinkedList<Animation>();
    // get all the animations you can, forget about the ones that are about to be added
    animationLock.lock();
    List<Animation> toPaint = (List<Animation>) animations.clone();
    animationLock.unlock();
    for (Animation x : toPaint) {
      if (x.isOver()) toRemove.add(x);
      else x.step(g2d);
    }

    animations.removeAll(toRemove);
  }
    public boolean onTouchEvent(MotionEvent me) {
      super.onTouchEvent(me);

      if (me.getPointerCount() > 1) {
        f_lines = null;
        lines.removeAll(lines);
        invalidate();
      }
      int action = me.getAction();
      switch (action) {
        case MotionEvent.ACTION_DOWN:
          i_x = me.getX();
          i_y = me.getY();

          i_x_ruler = i_x;
          i_y_ruler = i_y;

          draw_ruler = true;
          break;

        case MotionEvent.ACTION_MOVE:
          f_x = me.getX();
          f_y = me.getY();

          if (distance(i_x, i_y, f_x, f_y) > 10) {
            lines.add(i_x);
            lines.add(i_y);
            lines.add(f_x);
            lines.add(f_y);
            f_lines = convert_linked_list();

            i_x = f_x;
            i_y = f_y;
            invalidate();
          }

          f_x_ruler = f_x;
          f_y_ruler = f_y;

          ruler_length = distance(i_x_ruler, i_y_ruler, f_x_ruler, f_y_ruler);
          break;

        case MotionEvent.ACTION_UP:
          draw_ruler = false;
          invalidate();
          break;
      }
      return true;
    }
  public void removeAllInfos(UrlInfo.Type type) {
    List<T> list = null;
    for (T info : myInfos) {
      if (info.InfoType == type) {
        if (list == null) {
          list = new LinkedList<T>();
        }
        list.add(info);
      }
    }

    if (list != null) {
      myInfos.removeAll(list);
    }
  }
 public static String getWinner(final List<String> listOfBallots) {
   // Your code
   LinkedList<String> ballot = new LinkedList<String>();
   ballot.addAll(listOfBallots);
   Set<String> candidates = new HashSet<String>();
   int max = listOfBallots.size() / 2 + 1;
   int total = listOfBallots.size();
   int tolerance = 0;
   int count = 0;
   while (!ballot.isEmpty()) {
     String b = ballot.getFirst();
     candidates.add(b);
     ballot.removeAll(candidates);
     if (total - ballot.size() >= max) {
       return b;
     }
     total -= total - ballot.size();
   }
   return null;
 }
Ejemplo n.º 8
0
  protected void initialiseStateMap() {
    Stg stg = getUnderlyingStg();
    HashMap<String, SignalData> newStateMap = new HashMap<>();
    LinkedList<String> allSignals = new LinkedList<>();
    for (Type type : Type.values()) {
      Set<String> typedSignals = stg.getSignalReferences(type);
      allSignals.addAll(typedSignals);
      for (String signal : typedSignals) {
        SignalData signalData = new SignalData(signal, type);
        signalData.copy(signalDataMap.get(signal));
        signalData.visible = type != Type.INTERNAL;
        newStateMap.put(signal, signalData);
      }
    }
    signalDataMap = newStateMap;

    signals.retainAll(allSignals);
    allSignals.removeAll(signals);
    signals.addAll(allSignals);
    updateSignalState();
  }
Ejemplo n.º 9
0
  public void updateRewards() {
    if (bot.scoreCounter.getBotScore() > bot.lastBotScore) {
      bot.lastBotScore = bot.scoreCounter.getBotScore();
      // TODO: moze dac to do innego shootingu? Np. tego ktory ma hitpoint na teraz
      actionReward += 1;
    }
    //            Dbg.prn("");
    LinkedList<Shooting> toDelete = new LinkedList<Shooting>();
    for (Shooting s : shootings) {

      int damage = HitsReporter.wasHitInGivenPeriod(s.shotTime + 1, s.hitTime + 2, s.enemyName);
      if (damage > 0) {
        actionReward += (damage / 100d) * 0.2;
        toDelete.add(s);
        //                System.out.println(bot.getBotName()+" got shooting rwd - "+actionReward);
      } else if (s.hitTime + 4 < bot.getFrameNumber()) {
        toDelete.add(s);
        //                System.out.println(bot.getBotName()+" missed! - "+actionReward);
        //                actionReward -= 0.001;
      }
    }
    shootings.removeAll(toDelete);
    return;
  }
Ejemplo n.º 10
0
  public static LinkedList<PParking> getParkingsForScenario(String parkingDataBase) {

    LinkedList<PParking> parkingCollection = getParkingCollectionZHCity(parkingDataBase);
    String parkingsFile = parkingDataBase + "publicParkingsOutsideZHCity.xml";

    readParkings(parkingsOutsideZHCityScaling, parkingsFile, parkingCollection);

    LinkedList<PParking> parkingWithNonPositveCapacity = new LinkedList<PParking>();
    for (PParking parking : parkingCollection) {
      if (parking.getIntCapacity() <= 0) {
        parkingWithNonPositveCapacity.add(parking);
      }
    }
    parkingCollection.removeAll(parkingWithNonPositveCapacity);

    int numberOfStreetParking = 0;
    int numberOfGarageParking = 0;
    int numberOfPrivateParking = 0;

    for (PParking parking : parkingCollection) {
      if (parking.getId().toString().contains("stp")) {
        numberOfStreetParking += parking.getIntCapacity();
      } else if (parking.getId().toString().contains("gp")) {
        numberOfGarageParking += parking.getIntCapacity();
      } else if (parking.getId().toString().contains("private")) {
        numberOfPrivateParking += parking.getIntCapacity();
      }
    }

    double totalNumberOfParkingZH =
        numberOfStreetParking + numberOfGarageParking + numberOfPrivateParking;

    System.out.println(
        "streetParking to garageParking (%): "
            + numberOfStreetParking / 1.0 / numberOfGarageParking
            + " - ref: 3.03");
    System.out.println(
        "numberOfStreetParking (%): "
            + numberOfStreetParking / totalNumberOfParkingZH * 100
            + " - ref: 18.5 - ["
            + numberOfStreetParking
            + "]");
    System.out.println(
        "numberOfGarageParking (%):"
            + numberOfGarageParking / totalNumberOfParkingZH * 100
            + " - ref: 6.1 - ["
            + numberOfGarageParking
            + "]");
    System.out.println(
        "numberOfPrivateParking (%):"
            + numberOfPrivateParking / totalNumberOfParkingZH * 100
            + " - ref: 75.4 - ["
            + numberOfPrivateParking
            + "]");

    System.out.println(
        "totalNumberOfParkingZH: "
            + (totalNumberOfParkingZH / 1000)
            + "k - ref: "
            + 267000 * populationScalingFactor / 1000
            + "k");

    return parkingCollection;
  }
  public void roughcores() {

    int vset[] = new int[nodenum];
    for (int i = 0; i < nodenum; i++) vset[i] = i;

    boolean free[] = new boolean[nodenum];
    for (int i = 0; i < nodenum; i++) free[i] = true;

    for (int i = 0; i < nodenum; i++)
      for (int j = i + 1; j < nodenum; j++)
        if (degree[vset[i]] < degree[vset[j]]) {
          int temp = vset[i];
          vset[i] = vset[j];
          vset[j] = temp;
        }

    for (Integer i : vset) {
      HashMap<Integer, Double> core = new HashMap<Integer, Double>();
      if (degree[i] >= 3 && free[i] == true) {
        int max = -1;
        int index = -1;
        for (int k = 0; k < neighborlist[i].size(); k++) {
          int j = (Integer) neighborlist[i].get(k);
          if (degree[j] > max) {
            max = degree[j];
            index = j;
          }
        }

        if (free[index] == true) {

          core.put(i, 1.0);
          core.put(index, 1.0);

          //		free[i] = false;
          //		free[index] = false;

          LinkedList<Integer> commneiber = new LinkedList<Integer>();

          for (int k = nodenum - 1; k >= 0; k--) {
            int node = vset[k];
            if (neighborlist[i].contains(node) && neighborlist[index].contains(node)) {
              commneiber.add(node);
            }
          }

          while (commneiber.size() != 0) {
            int h = commneiber.getFirst();

            core.put(h, 1.0);
            //		free[h] = false;

            LinkedList<Integer> toremove = new LinkedList<Integer>();
            for (int m = 0; m < commneiber.size(); m++) {
              int cc = commneiber.get(m);
              if (!neighborlist[h].contains(cc)) {
                toremove.add(cc);
              }
            }
            commneiber.removeAll(toremove);

            commneiber.remove(new Integer(h));
          }

          normalize(core);
          //		System.out.println("core : "+ core);

        }
      }

      if (core.size() >= 3) {
        oldmap[i] = core;
        //		System.out.println("core2 : "+ core);
        //		for(Integer ik : core.keySet())
        //		free[ik] = false;

      }
    }
  }
Ejemplo n.º 12
0
 public void upgrade(UrlInfoCollection<? extends T> other) {
   myInfos.removeAll(other.myInfos);
   myInfos.addAll(other.myInfos);
 }
 public boolean removeAll(java.util.Collection c)
     throws UnsupportedOperationException, NullPointerException {
   // Specified by: removeAll in interface java.util.List
   return (linkedlist.removeAll(c));
 }
Ejemplo n.º 14
0
 /** Removes the content of a set of rules */
 public void deleteAll() {
   reglas.removeAll(reglas);
 }
Ejemplo n.º 15
0
 public void removeProcessed(Collection<OsmPrimitive> processed) {
   if (processed == null) return;
   toAdd.removeAll(processed);
   toUpdate.removeAll(processed);
   toDelete.removeAll(processed);
 }