コード例 #1
0
 /**
  * Add an card to the deck
  *
  * @param card the card to add
  */
 public void addCard(Card card) {
   first = cards.indexOf(card);
   last = cards.lastIndexOf(card);
   if (first == last) {
     cards.add(card);
   }
 }
コード例 #2
0
ファイル: StyleGroupSet.java プロジェクト: rossjudson/gs-core
  /**
   * Remove a style change listener.
   *
   * @param listener The listener to remove.
   */
  public void removeListener(StyleGroupListener listener) {
    int index = listeners.lastIndexOf(listener);

    if (index >= 0) {
      listeners.remove(index);
    }
  }
コード例 #3
0
ファイル: StyleGroupSet.java プロジェクト: rossjudson/gs-core
    /**
     * Remove an event from the set.
     *
     * @param event The event to remove.
     */
    public void popEvent(String event) {
      int index = eventSet.lastIndexOf(event);

      if (index >= 0) eventSet.remove(index);

      events = eventSet.toArray(events);
    }
コード例 #4
0
ファイル: BinaryObjectCache.java プロジェクト: tomw2/visad
  /**
   * Add an object to the end of the list. If the index is less than zero, the object will be added
   * to the end of the list.
   *
   * @param obj Object to be added.
   * @return <tt>-1</tt> if the object is <tt>null</tt>, or the index at which the object was added.
   */
  public int add(int index, Object obj) {
    // don't bother adding null objects
    if (obj == null) {
      return -1;
    }

    // build a new list if necessary
    if (cache == null) {
      cache = new ArrayList();
    }

    final int cacheLen = cache.size();
    if (index < 0 || index == cacheLen) {
      // add to end of list, then find out where it was added
      cache.add(obj);
      index = cache.lastIndexOf(obj);
    } else if (index < cacheLen) {
      // overwrite the current entry
      cache.set(index, obj);
    } else {
      // pad with nulls
      for (int i = cacheLen; i < index; i++) {
        cache.add(null);
      }

      // add to end of list
      cache.add(obj);
    }

    return index;
  }
コード例 #5
0
 @Override
 public int lastIndexOf(Object arg0) {
   if (serviceSet != null) {
     ArrayList<ServiceReference> list = new ArrayList<ServiceReference>(serviceSet);
     return list.lastIndexOf(arg0);
   }
   return -1;
 }
コード例 #6
0
 public String nameOfBestCustomer() {
   double top = 0.0;
   for (double i : payment) {
     if (i > top) {
       top = i;
     }
   }
   return customer.get(payment.lastIndexOf(top));
 }
コード例 #7
0
ファイル: AI.java プロジェクト: Epono/TheParkKeeper
  /**
   * Patrol mode of a <b>Guardian</b> : </br> - If the provided <b>Gardian</b> doesn't have a patrol
   * route, he moves randomly.</br> - If the provided <b>Gardian</b> has a patrol route and is
   * currently patrolling, he continues his patrol.</br> - If the provided <b>Gardian</b> has a
   * patrol route, but isn't doing it, he moves toward the nearest patrol <b>Coordinate</b>.</br>
   *
   * @param guard : the patrolling <b>Gardian</b>.
   * @return the corresponding <b>Displacement</b>.
   */
  public Displacement patrolMode(Guardian guard) {
    if (guard.getPatrolPosition() == -2) {
      // pas de coord de patrouille, deplacement aleatoire
      return randomDisplacement();
    } else if (guard.getPatrolPosition() != -1
        && guard.getPatrol().get(guard.getPatrolPosition()).equals(guard.getPosition())) {
      // aller au point suivant
      guard.incrPatrolPosition();
      return displacementCalculation(
          guard.getPosition(), guard.getPatrol().get(guard.getPatrolPosition()));
    } else {
      // aller vers le point unique le plus proche
      ArrayList<Coordinate> patrolCoordinates =
          new ArrayList<Coordinate>(guard.getPatrol().values());
      ArrayList<Coordinate> routeTemp = new ArrayList<Coordinate>();
      ArrayList<Coordinate> routeFinal = new ArrayList<Coordinate>();
      Coordinate coordDestination = null;
      // tirage de la coord la plus proche
      for (Coordinate coord : patrolCoordinates) {
        if (patrolCoordinates.lastIndexOf(coord)
            == patrolCoordinates.indexOf(coord)) { // si passage unique
          routeTemp = routeCalculation(guard.getPosition(), coord, true);
          if (routeFinal.size() == 0
              || (routeTemp.size() != 0 && routeTemp.size() < routeFinal.size())) {
            routeFinal = new ArrayList<Coordinate>(routeTemp);
            coordDestination = coord.copy();
          }
        }
      }

      if (coordDestination
          == null) { // passage 2 fois partout, pas de bol, go au debut de la patrouille
        if (areAdjacent(guard.getPosition(), guard.getPatrol().get(0))) guard.setPatrolPosition(0);
        return displacementCalculation(guard.getPosition(), routeFinal.get(1));
      } else { // aller a itineraire final (proche et unique) et si on y arrive, mettre la bonne
               // valeur de positionPatrouille
        if (areAdjacent(
            guard.getPosition(),
            guard.getPatrol().get(patrolCoordinates.indexOf(coordDestination))))
          guard.setPatrolPosition(patrolCoordinates.indexOf(coordDestination));
        return displacementCalculation(guard.getPosition(), routeFinal.get(1));
      }
    }
  }
コード例 #8
0
  /** Supprime les doublons */
  private ArrayList<String> getDistinctInstanceIds(String[] givenInstancesIds) {
    ArrayList<String> instancesIds = new ArrayList<String>();
    String instanceId = null;
    ArrayList<String> intermed = new ArrayList<String>();

    for (int i = 0; i < givenInstancesIds.length; i++) {
      instanceId = givenInstancesIds[i];
      intermed.add(instanceId);
    }

    for (int i = 0; i < givenInstancesIds.length; i++) {
      instanceId = givenInstancesIds[i];
      if (intermed.lastIndexOf(instanceId) == i) {
        instancesIds.add(instanceId);
      }
    }

    return instancesIds;
  }
コード例 #9
0
 public int lastIndexOf(ASTTypeArguments o) {
   return list.lastIndexOf(o);
 }
コード例 #10
0
 public int lastIndexOf(ASTRelationalexpression o) {
   return list.lastIndexOf(o);
 }
コード例 #11
0
ファイル: SlideModel.java プロジェクト: Ronelg/MMS-Plus
 public int lastIndexOf(Object object) {
   return mMedia.lastIndexOf(object);
 }
コード例 #12
0
 public int lastIndexOf(Object o) {
   return list.lastIndexOf(o);
 }
コード例 #13
0
 public int lastIndexOf(ASTUnannClassType o) {
   return list.lastIndexOf(o);
 }
コード例 #14
0
ファイル: ApplianceEditPanel.java プロジェクト: oeoeaio/emma
  private void editAppliance(Source source) {
    try {
      Statement MySQL_Statement = dbConn.createStatement();
      ArrayList<String> circuitIDList = new ArrayList<String>();
      ArrayList<String> roomIDList = new ArrayList<String>();
      if (siteIDInput.getText().equals("")
          || sourceIDInput.getText().equals("")
          || circuitInput.getItemCount() == 0
          || roomInput.getItemCount() == 0) {

        // get room types
        ResultSet roomIDsSQL =
            MySQL_Statement.executeQuery(
                "SELECT room_id,room_number,room_type FROM rooms WHERE site_id ="
                    + source.site.siteID); // gets relevant rooms
        if (roomIDsSQL.next()) {
          roomIDsSQL.beforeFirst();
          while (roomIDsSQL.next()) { // if got some rooms
            roomInput.addItem(
                roomIDsSQL.getString("room_number") + ": " + roomIDsSQL.getString("room_type"));
            roomIDList.add(roomIDsSQL.getString("room_id"));
          }
        } else {
          roomInput.addItem("No Rooms");
          roomInput.addItem("Add New Room");
        }

        // get circuits
        ResultSet circuitIDsSQL =
            MySQL_Statement.executeQuery(
                "SELECT circuit_id,source_name FROM circuits LEFT JOIN sources ON circuits.source_id = sources.source_id WHERE circuits.site_id ="
                    + source.site.siteID); // gets relevant circuits
        if (circuitIDsSQL.next()) {
          circuitIDsSQL.beforeFirst();
          while (circuitIDsSQL.next()) { // if got some circuits
            circuitInput.addItem(circuitIDsSQL.getString("source_name"));
            circuitIDList.add(circuitIDsSQL.getString("circuit_id"));
          }
        } else {
          circuitInput.addItem("No Circuits");
          circuitInput.addItem("Add New Circuit");
        }

        siteIDInput.setText(source.site.siteID + ": " + source.site.siteName);
        sourceIDInput.setText(source.sourceID);
        ResultSet applianceData =
            MySQL_Statement.executeQuery(
                "SELECT sources.source_name,sources.source_type,sources.measurement_type,rooms.room_number,rooms.room_type,appliances.* FROM appliances LEFT JOIN sources ON sources.source_id = appliances.source_id LEFT JOIN rooms ON appliances.room_id = rooms.room_id WHERE appliances.site_id ="
                    + source.site.siteID
                    + " AND appliances.source_id = "
                    + source.sourceID); // retrieves data pertaining to selected site
        if (applianceData.next()) { // if retrieved a new id
          sourceNameInput.setText(applianceData.getString("source_name"));
          circuitInput.setSelectedIndex(
              circuitIDList.lastIndexOf(applianceData.getString("circuit_id")));
          roomInput.setSelectedItem(
              applianceData.getString("room_number") + ": " + applianceData.getString("room_type"));
          sourceTypeInput.setSelectedItem(applianceData.getString("source_type"));
          measurementTypeInput.setSelectedItem(applianceData.getString("measurement_type"));
          applianceGroupInput.setSelectedItem(applianceData.getString("appliance_group"));
          applianceTypeInput.setSelectedItem(applianceData.getString("appliance_type"));
          brandInput.setText(applianceData.getString("brand"));
          modelInput.setText(applianceData.getString("model"));
          serialInput.setText(applianceData.getString("serial_no"));
          connectionInput.setSelectedItem(applianceData.getString("connection_type"));
          controlInput.setSelectedItem(applianceData.getString("control"));
          switchTypeInput.setSelectedItem(applianceData.getString("switch_type"));
          displayInput.setSelectedItem(applianceData.getString("display"));
          epsInput.setSelectedItem(applianceData.getString("eps"));
          delayStartInput.setSelectedItem(applianceData.getString("delay_start"));
          onWInput.setText(applianceData.getString("on_w"));
          asWInput.setText(applianceData.getString("as_w"));
          psWInput.setText(applianceData.getString("ps_w"));
          offWInput.setText(applianceData.getString("off_w"));
          dsWInput.setText(applianceData.getString("ds_w"));
          yearOfPurchaseInput.setText(applianceData.getString("year_of_purchase"));
          usageInput.setText(applianceData.getString("usage_amount"));
          usageUnitsInput.setSelectedItem(applianceData.getString("usage_units"));
          feature1Input.setText(applianceData.getString("feature1"));
          feature2Input.setText(applianceData.getString("feature2"));
          feature3Input.setText(applianceData.getString("feature3"));
          feature4Input.setText(applianceData.getString("feature4"));
          feature5Input.setText(applianceData.getString("feature5"));
          notesInput.setText(applianceData.getString("notes"));
        }
      }

      if (!siteIDInput.getText().equals("")
          && !sourceIDInput.getText().equals("")
          && circuitInput.getItemCount() > 0
          && roomInput.getItemCount() > 0) {

        int response =
            JOptionPane.showConfirmDialog(
                null,
                this,
                "Editing appliance (Source ID: " + source.sourceID + ")",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        if (response == JOptionPane.OK_OPTION) {
          Source newSource =
              new Source(
                  source.site,
                  source.sourceID,
                  sourceNameInput.getText(),
                  sourceTypeInput.getSelectedItem().toString(),
                  measurementTypeInput.getSelectedItem().toString());
          if (newSource.isValid()) {
            Appliance newAppliance =
                new Appliance(
                    source.site,
                    source.sourceID,
                    sourceNameInput.getText(),
                    circuitIDList.get(circuitInput.getSelectedIndex()),
                    roomIDList.get(roomInput.getSelectedIndex()),
                    applianceGroupInput.getSelectedItem().toString(),
                    applianceTypeInput.getSelectedItem().toString(),
                    brandInput.getText(),
                    modelInput.getText(),
                    serialInput.getText(),
                    connectionInput.getSelectedItem().toString(),
                    controlInput.getSelectedItem().toString(),
                    switchTypeInput.getSelectedItem().toString(),
                    displayInput.getSelectedItem().toString(),
                    epsInput.getSelectedItem().toString(),
                    delayStartInput.getSelectedItem().toString(),
                    onWInput.getText(),
                    asWInput.getText(),
                    psWInput.getText(),
                    offWInput.getText(),
                    dsWInput.getText(),
                    yearOfPurchaseInput.getText(),
                    usageInput.getText(),
                    usageUnitsInput.getSelectedItem().toString(),
                    feature1Input.getText(),
                    feature2Input.getText(),
                    feature3Input.getText(),
                    feature4Input.getText(),
                    feature5Input.getText(),
                    notesInput.getText());
            if (newAppliance.isValid()) {
              try {
                String updSourceSQL =
                    "UPDATE sources SET source_name='"
                        + sourceNameInput.getText()
                        + "',source_type='"
                        + sourceTypeInput.getSelectedItem().toString()
                        + "',measurement_type='"
                        + measurementTypeInput.getSelectedItem().toString()
                        + "' WHERE site_id = "
                        + source.site.siteID
                        + " AND source_id = "
                        + source.sourceID; // adds specified information into the database
                MySQL_Statement.executeUpdate(updSourceSQL);
                try {
                  String updApplianceSQL =
                      "UPDATE appliances SET circuit_id="
                          + circuitIDList.get(circuitInput.getSelectedIndex())
                          + ",room_id="
                          + roomIDList.get(roomInput.getSelectedIndex())
                          + ",appliance_group='"
                          + applianceGroupInput.getSelectedItem().toString()
                          + "',appliance_type='"
                          + applianceTypeInput.getSelectedItem().toString()
                          + "',brand="
                          + (brandInput.getText().equals("")
                              ? "NULL"
                              : "'" + brandInput.getText() + "'")
                          + ",model="
                          + (modelInput.getText().equals("")
                              ? "NULL"
                              : "'" + modelInput.getText() + "'")
                          + ",serial_no="
                          + (serialInput.getText().equals("")
                              ? "NULL"
                              : "'" + serialInput.getText() + "'")
                          + ",connection_type='"
                          + connectionInput.getSelectedItem().toString()
                          + "',control='"
                          + controlInput.getSelectedItem().toString()
                          + "',switch_type='"
                          + switchTypeInput.getSelectedItem().toString()
                          + "',display='"
                          + displayInput.getSelectedItem().toString()
                          + "',eps='"
                          + epsInput.getSelectedItem().toString()
                          + "',delay_start='"
                          + delayStartInput.getSelectedItem().toString()
                          + "',on_w="
                          + (onWInput.getText().equals("") ? "NULL" : onWInput.getText())
                          + ",as_w="
                          + (asWInput.getText().equals("") ? "NULL" : asWInput.getText())
                          + ",ps_w="
                          + (psWInput.getText().equals("") ? "NULL" : psWInput.getText())
                          + ",off_w="
                          + (offWInput.getText().equals("") ? "NULL" : offWInput.getText())
                          + ",ds_w="
                          + (dsWInput.getText().equals("") ? "NULL" : dsWInput.getText())
                          + ",year_of_purchase="
                          + (yearOfPurchaseInput.getText().equals("")
                              ? "NULL"
                              : yearOfPurchaseInput.getText())
                          + ",usage_amount="
                          + (usageInput.getText().equals("") ? "NULL" : usageInput.getText())
                          + ",usage_units='"
                          + usageUnitsInput.getSelectedItem().toString()
                          + "',feature1="
                          + (feature1Input.getText().equals("")
                              ? "NULL"
                              : "'" + feature1Input.getText() + "'")
                          + ",feature2="
                          + (feature2Input.getText().equals("")
                              ? "NULL"
                              : "'" + feature2Input.getText() + "'")
                          + ",feature3="
                          + (feature3Input.getText().equals("")
                              ? "NULL"
                              : "'" + feature3Input.getText() + "'")
                          + ",feature4="
                          + (feature4Input.getText().equals("")
                              ? "NULL"
                              : "'" + feature4Input.getText() + "'")
                          + ",feature5="
                          + (feature5Input.getText().equals("")
                              ? "NULL"
                              : "'" + feature5Input.getText() + "'")
                          + ",notes="
                          + (notesInput.getText().equals("")
                              ? "NULL"
                              : "'" + notesInput.getText() + "'")
                          + " WHERE site_id = "
                          + source.site.siteID
                          + " AND source_id = "
                          + source.sourceID; // adds specified information into the database
                  MySQL_Statement.executeUpdate(updApplianceSQL);
                } catch (SQLException sE) {
                  JOptionPane.showMessageDialog(
                      null,
                      "Error occured when writing appliance information.",
                      "Error",
                      JOptionPane.ERROR_MESSAGE);
                  editAppliance(source);
                }
              } catch (SQLException sE) {
                if (sE.getErrorCode() == 1062) {
                  JOptionPane.showMessageDialog(
                      null,
                      "Information entered conflicts with an existing source for this site.",
                      "Error",
                      JOptionPane.ERROR_MESSAGE);
                } else {
                  sE.printStackTrace();
                  JOptionPane.showMessageDialog(
                      null,
                      "Error occured when writing source information.",
                      "Error",
                      JOptionPane.ERROR_MESSAGE);
                }
                editAppliance(source);
              }
            } else {
              editAppliance(source);
            }
          } else {
            editAppliance(source);
          }
        }
        resetApplianceEditForm();
      } else {
        JOptionPane.showMessageDialog(
            this,
            "An error occured when writing data for appliance (Source ID: " + source.sourceID + ".",
            "Fatal Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } catch (SQLException sE) {
      sE.printStackTrace();
    }
  }
コード例 #15
0
 public int lastIndexOf(ASTPtrdeclarator o) {
   return list.lastIndexOf(o);
 }
コード例 #16
0
 public int lastIndexOf(final Object o) {
   final int index = myHashSet.index((T) o);
   return index >= 0 ? myElements.lastIndexOf(myHashSet.get(index)) : -1;
 }
 public int lastIndexOf(Object object) {
   return mSlides.lastIndexOf(object);
 }
コード例 #18
0
ファイル: Solution.java プロジェクト: Ivansamara/javarush
 @Override
 public int lastIndexOf(Object o) {
   return original.lastIndexOf(o);
 }
コード例 #19
0
 public int lastIndexOf(ASTTypenameP o) {
   return list.lastIndexOf(o);
 }
コード例 #20
0
 public int lastIndexOf(ASTEnhancedForStatementNoShortIf o) {
   return list.lastIndexOf(o);
 }
コード例 #21
0
 public int lastIndexOf(ASTNumericType o) {
   return list.lastIndexOf(o);
 }
コード例 #22
0
 @Override
 public int lastIndexOf(Object o) {
   return children.lastIndexOf(o);
 }
コード例 #23
0
 public int lastIndexOf(ASTPostfixexpression o) {
   return list.lastIndexOf(o);
 }
コード例 #24
0
 public int lastIndexOf(ASTNoptrabstractpackdeclarator o) {
   return list.lastIndexOf(o);
 }