Java Iterator Examples

Java Iterator - 30 examples found. These are the top rated real world Java examples of java.util.Iterator extracted from open source projects. You can rate examples to help us improve the quality of examples.
  /**
   * Returns submap of x and y values according to the given start and end
   *
   * @param start start x value
   * @param stop stop x value
   * @return a submap of x and y values
   */
  public synchronized SortedMap<Double, Double> getRange(
      double start, double stop, int beforeAfterPoints) {
    // we need to add one point before the start and one point after the end (if
    // there are any)
    // to ensure that line doesn't end before the end of the screen

    // this would be simply: start = mXY.lowerKey(start) but NavigableMap is
    // available since API 9
    SortedMap<Double, Double> headMap = mXY.headMap(start);
    if (!headMap.isEmpty()) {
      start = headMap.lastKey();
    }

    // this would be simply: end = mXY.higherKey(end) but NavigableMap is
    // available since API 9
    // so we have to do this hack in order to support older versions
    SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
    if (!tailMap.isEmpty()) {
      Iterator<Double> tailIterator = tailMap.keySet().iterator();
      Double next = tailIterator.next();
      if (tailIterator.hasNext()) {
        stop = tailIterator.next();
      } else {
        stop += next;
      }
    }
    return new TreeMap<Double, Double>(mXY.subMap(start, stop));
  }
  private void listAll() {
    ViewGroup root = mList;
    root.removeAllViews();

    // 列出所有已经安装的插件
    Collection<PluginDescriptor> plugins = PluginLoader.getPlugins();
    Iterator<PluginDescriptor> itr = plugins.iterator();
    while (itr.hasNext()) {
      final PluginDescriptor pluginDescriptor = itr.next();
      Button button = new Button(this);
      button.setPadding(10, 10, 10, 10);
      button.setText("插件id:" + pluginDescriptor.getPackageName() + ",点击查看");
      button.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(PluginListActivity.this, PluginDetailActivity.class);
              intent.putExtra("plugin_id", pluginDescriptor.getPackageName());
              startActivity(intent);
            }
          });

      LayoutParams layoutParam =
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      layoutParam.topMargin = 10;
      layoutParam.bottomMargin = 10;
      layoutParam.gravity = Gravity.LEFT;
      root.addView(button, layoutParam);
    }
  }
 /** Initialize the (java.bean) PropertyDescriptors for the properties */
 private void initPropertyDescriptor() {
   for (Iterator<String> it = orderedExportedProperties.iterator(); it.hasNext(); ) {
     String propertyName = it.next();
     try {
       // we're using this specialized constructor since we want to allow properties that are
       // read-only (such as creationDate).
       // with the simpler constructor (String,Class) that would result in an Exception.
       // also note that we're using "is"+propertyName rather than get - that's the way the
       // PropertyDescriptor itself
       // does it in the constructor (String,Class) - resulting in a lookup of an is Method first
       // and then the get Method
       // this seems to be the correct standard here.
       PropertyDescriptor pd =
           new PropertyDescriptor(
               propertyName, LoggingObject.class, "is" + capitalize(propertyName), null);
       orderedExportedPropertyDescriptors.add(pd);
     } catch (IntrospectionException e) {
       log_.error(
           "initPropertyDescriptor: Could not retrieve property "
               + propertyName
               + " from LoggingObject, configuration error?",
           e);
     }
   }
 }
Example #4
0
 /**
  * Run the consistency check and validate the result against expectations.
  *
  * @param rf The factory for the reasoner to test
  */
 @Override
 public void runTest() {
   ValidityReport report = testResults();
   switch (expected) {
     case INCONSISTENT:
       assertTrue("expected inconsistent", !report.isValid());
       break;
     case WARNINGS:
       assertTrue("expected just warnings but reports not valid", report.isValid());
       assertFalse("expected warnings but reports clean", report.isClean());
       break;
     case CLEAN:
       assertTrue("expected clean", report.isClean());
   }
   if (culprit != null) {
     boolean foundit = false;
     for (Iterator<Report> i = report.getReports(); i.hasNext(); ) {
       ValidityReport.Report r = i.next();
       if (r.getExtension() != null && r.getExtension().equals(culprit)) {
         foundit = true;
         break;
       }
     }
     if (!foundit) {
       assertTrue("Expcted to find a culprint " + culprit, false);
     }
   }
 }
Example #5
0
  /**
   * Retrieves the access token used for interacting with Twitter.
   *
   * @return
   */
  public static AccessToken getAccessToken() {
    // Try to grab the token from the cache.
    StoredAccessToken storedToken = (StoredAccessToken) cache.get(ACCESS_TOKEN_KEY);

    if (storedToken != null) {
      return storedToken.getAccessToken();
    }

    // Now try to grab it from the datastore
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Extent<StoredAccessToken> extent = pm.getExtent(StoredAccessToken.class, false);

    try {
      Iterator<StoredAccessToken> itr = extent.iterator();
      storedToken = itr.next();

      // If the token was found, cache it and return.
      if (storedToken != null) {
        cache.put(ACCESS_TOKEN_KEY, storedToken);
        return storedToken.getAccessToken();
      }
    } finally {
      extent.closeAll();
      pm.close();
    }

    return null;
  }
  private static void filterBadAddresses(
      final Address address, final List<MapquestResult.Result> filtered) {
    boolean wasZipMatch = false;
    boolean wasCityMatch = false;
    boolean wasStreetMatch = false;

    for (MapquestResult.Result result : filtered) {

      if (address.getZipcode() != null && address.getZipcode().equals(result.getZip())) {
        wasZipMatch = true;
      }
      if (address.getMunicipality() != null && address.getMunicipality().equals(result.getCity())) {
        wasCityMatch = true;
      }
      if (address.getStreet() != null && result.getStreet().matches(".*" + address.getStreet())) {
        wasStreetMatch = true;
      }
    }

    final Iterator<MapquestResult.Result> it = filtered.iterator();
    while (it.hasNext()) {
      final MapquestResult.Result result = it.next();

      final boolean zip = wasZipMatch && !address.getZipcode().equals(result.getZip());
      final boolean city = wasCityMatch && !address.getMunicipality().equals(result.getCity());
      final boolean street =
          wasStreetMatch && !result.getStreet().matches(".*" + address.getStreet());

      if (zip || city || street) it.remove();
    }
  }