public void testMaliciousGetIcons() {
    Iterable<WWIcon> icons = createExampleIterable();

    IconLayer layer = new IconLayer();
    layer.addIcons(icons);

    Iterable<WWIcon> layerIcons = layer.getIcons();

    // Test that the returned list cannot be modified.
    try {
      if (layerIcons instanceof java.util.Collection) {
        java.util.Collection<WWIcon> collection = (java.util.Collection<WWIcon>) layerIcons;
        collection.clear();
      } else {
        java.util.Iterator<WWIcon> iter = layerIcons.iterator();
        while (iter.hasNext()) {
          iter.next();
          iter.remove();
        }
      }
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }

    // Test that the layer contents do not change, even if the returned list can be modified.
    assertEquals("", icons, layerIcons);
  }
  /*
   * (non-Javadoc)
   * @see de.hpi.bpt.graph.abs.IDirectedEdge#setVertices(de.hpi.bpt.hypergraph.abs.IVertex, de.hpi.bpt.hypergraph.abs.IVertex)
   */
  @SuppressWarnings("unchecked")
  public void setVertices(V s, V t) {
    if (this.graph == null) return;
    if (s == null || t == null) return;

    if (!this.graph.isMultiGraph()) {
      Collection<IDirectedHyperEdge<V>> es = this.graph.getEdgesWithSourceAndTarget(s, t);
      if (es.size() > 0) {
        Iterator<IDirectedHyperEdge<V>> i = es.iterator();
        while (i.hasNext()) {
          IDirectedHyperEdge<V> e = i.next();
          if (e.getVertices().size() == 2) return;
        }
      }
    }

    Collection<V> ss = new ArrayList<V>();
    Collection<V> ts = new ArrayList<V>();
    if (this.source != null && this.target != null) {
      ss.add(this.source);
      ts.add(this.target);
      super.removeSourceAndTagetVertices(ss, ts);
    }
    ss.clear();
    ss.add(s);
    ts.clear();
    ts.add(t);
    super.addSourceAndTagetVertices(ss, ts);
    this.source = s;
    this.target = t;
  }
  private void prepareAnimation() {
    yMap.clear();
    positionMap.clear();
    beforeVisible.clear();
    afterVisible.clear();

    adapter.setMayNotify(false);

    final int childCount = getChildCount();

    final int firstVisiblePosition = getFirstVisiblePosition();

    for (int i = 0; i < childCount; i++) {
      final View child = getChildAt(i);
      final long id = adapter.getItemId(firstVisiblePosition + i);

      yMap.put(id, ViewHelper.getY(child));
      positionMap.put(id, firstVisiblePosition + i);
    }

    for (int i = 0; i < firstVisiblePosition; i++) {
      final long id = adapter.getItemId(i);
      beforeVisible.add(id);
    }

    final int count = adapter.getCount();

    for (int i = firstVisiblePosition + childCount; i < count; i++) {
      final long id = adapter.getItemId(i);
      afterVisible.add(id);
    }
  }
示例#4
0
  /**
   * Handles activation of the editor or it's associated views.
   * <!--
   * begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  protected void handleActivate() {
    // Recompute the read only state.
    //
    if (editingDomain.getResourceToReadOnlyMap() != null) {
      editingDomain.getResourceToReadOnlyMap().clear();

      // Refresh any actions that may become enabled or disabled.
      //
      setSelection(getSelection());
    }

    if (!removedResources.isEmpty()) {
      if (handleDirtyConflict()) {
        getSite().getPage().closeEditor(RmapEditor.this, false);
      } else {
        removedResources.clear();
        changedResources.clear();
        savedResources.clear();
      }
    } else if (!changedResources.isEmpty()) {
      changedResources.removeAll(savedResources);
      handleChangedResources();
      changedResources.clear();
      savedResources.clear();
    }
  }
 public void reset() {
   dotsA.clear();
   dotsB.clear();
   fillWithDots(dotsA, oval1a, dotsCountA1);
   fillWithDots(dotsA, oval1b, dotsCountA2);
   fillWithDots(dotsB, oval2, dotsCountB);
   resetConnections();
 }
 public void clearInformation() {
   assertions_.clear();
   standing_ = new WeightedStanding();
   infoboxType_ = null;
   concreteAssertions_.clear();
   concreteParentageAssertions_.clear();
   minedTypes_ = -1;
   isModified_ = false;
 }
示例#7
0
 /** Clear all observers */
 public void clear() {
   lock.lock();
   try {
     onceUsedObservers.clear();
   } finally {
     lock.unlock();
   }
   observers.clear();
   attackCalcObservers.clear();
 }
  /** Cleans up resources to avoid excessive memory usage. */
  public void cleanUp() {
    topSnapshot.set(null);
    singleMsgs.clear();
    fullMsgs.clear();
    rcvdIds.clear();
    oldestNode.set(null);
    partReleaseFut = null;

    Collection<ClusterNode> rmtNodes = this.rmtNodes;

    if (rmtNodes != null) rmtNodes.clear();
  }
  @Override
  protected void finalizeDismiss() {
    if (getActiveDismissCount() == 0 && getActiveSwipeCount() == 0) {
      restoreViewPresentations(mDismissedViews);
      notifyCallback(mDismissedPositions);

      Collection<Integer> newUndoPositions =
          ListViewAnimationsUtils.processDeletions(mUndoPositions, mDismissedPositions);
      mUndoPositions.clear();
      mUndoPositions.addAll(newUndoPositions);

      mDismissedViews.clear();
      mDismissedPositions.clear();
    }
  }
示例#10
0
 @BeforeTest
 public void reset() {
   first = false;
   second = false;
   values.clear();
   out.println("NEW TEST");
 }
示例#11
0
  /**
   * Creates an instance of an AtomCache that is pointed to the a particular path in the file
   * system.
   *
   * @param pdbFilePath a directory in the file system to use as a location to cache files.
   * @param cachePath
   */
  public AtomCache(String pdbFilePath, String cachePath) {

    logger.debug(
        "Initialising AtomCache with pdbFilePath={}, cachePath={}", pdbFilePath, cachePath);

    if (!pdbFilePath.endsWith(FILE_SEPARATOR)) {
      pdbFilePath += FILE_SEPARATOR;
    }

    // we are caching the binary files that contain the PDBs gzipped
    // that is the most memory efficient way of caching...
    // set the input stream provider to caching mode
    System.setProperty(InputStreamProvider.CACHE_PROPERTY, "true");

    setPath(pdbFilePath);

    this.cachePath = cachePath;

    fetchBehavior = FetchBehavior.DEFAULT;
    obsoleteBehavior = ObsoleteBehavior.DEFAULT;

    currentlyLoading.clear();
    params = new FileParsingParameters();

    setUseMmCif(true);
  }
  public void index() {
    returns.clear();
    yields.clear();
    code.visit(
        new AbstractIRVisitor() {
          @Override
          public void visitReturn(ReturnInstruction returnInstruction) {
            returns.add(returnInstruction);
          }

          @Override
          public void visitYieldCall(YieldCall yieldCall) {
            yields.add(yieldCall);
          }
        });
  }
  protected void clearCollection(final Collection val) {
    if (val == null) {
      return;
    }

    val.clear();
  }
 protected void makeCopyOfPoints(Collection<Point> col) {
   Collection<Point> col_copy = new LinkedList<Point>(col);
   col.clear();
   for (Point p : col_copy) {
     col.add((Point) p.clone());
   }
 }
示例#15
0
  public static Collection<Element> getElements(Element root, String path) {
    String tPath = path;

    List<Element> fila = new LinkedList<Element>();
    fila.add(root);

    Collection<Element> resp = new LinkedList<Element>();
    do {
      int p = tPath.indexOf("/");
      String name = p > 0 ? tPath.substring(0, p) : tPath;

      fila.addAll(resp);
      resp.clear();

      while (!fila.isEmpty()) {
        Element element = (Element) fila.remove(0);
        NodeList nodes = element.getElementsByTagName(name);

        for (int i = 0; i < nodes.getLength(); i++) {
          resp.add((Element) nodes.item(i));
        }
      }

      tPath = p > 0 ? tPath.substring(p + 1) : "";
    } while (tPath.length() != 0);

    return resp;
  }
示例#16
0
  @Override
  public Collection<Coin> getChangeFor(int pence, Product p)
      throws NotEnoughChangeException, NotEnoughMoneyException {

    changeInProgress.clear();
    int difference = pence - p.getProductPrice();

    loadConfig();

    if (enoughMoneyProvided(pence, p)) {
      if (enoughChange(difference)) {
        for (Coin coin : Coin.values()) {
          if (isCoinTypeNeeded(coin, difference - getCurrentChange())) {
            supplyThisCoinType(coin, difference - getCurrentChange(), true);
          }
        }
        if (getCurrentChange() != difference)
          throw new NotEnoughChangeException("The machine has run out of change.");
        updateConfig();
      } else {
        throw new NotEnoughChangeException("The machine has run out of change.");
      }
    } else {
      throw new NotEnoughMoneyException("You have not provided enough money.");
    }

    return changeInProgress;
  }
 public static void tickAll() {
   for (Animation a : animations) {
     a.tick();
   }
   animations.removeAll(removeAnimations);
   removeAnimations.clear();
 }
  @Override
  public synchronized void close() throws SQLException {
    try {
      closeLock.writeLock().lock();
      if (closed) {
        return;
      }
      closed = true;
    } finally {
      closeLock.writeLock().unlock();
    }

    try {
      Collection<ConnectionQueryServices> connectionQueryServices =
          connectionQueryServicesMap.values();
      try {
        SQLCloseables.closeAll(connectionQueryServices);
      } finally {
        connectionQueryServices.clear();
      }
    } finally {
      if (services != null) {
        try {
          services.close();
        } finally {
          ExecutorService executor = services.getExecutor();
          // Even if something wrong happened while closing services above, we still
          // want to set it to null. Otherwise, we will end up having a possibly non-working
          // services instance.
          services = null;
          executor.shutdown();
        }
      }
    }
  }
示例#19
0
  public static <E> void replace(final Collection<E> into, final Collection<E> values) {
    checkNotNull(into, "target cannot be null");
    checkNotNull(values, "source cannot be null");

    into.clear();
    into.addAll(values);
  }
示例#20
0
  protected void clearGroups() {
    for (Collection<Tuple> collection : collections) {
      collection.clear();

      if (collection instanceof Spillable) ((Spillable) collection).setGrouping(grouping);
    }
  }
示例#21
0
  /**
   * Converts the values of an FeatureMap, the values of the collection are converted to and added
   * to the list in the correct feature in the modelObject.
   *
   * @param eObject the eObject from which the value is read
   * @param modelObject the {@link ModelObject} in which the value is to be set
   * @param eFeature the eFeature which is converted
   */
  protected void convertFeatureMap(
      final EObject eObject, final ModelObject<?> modelObject, final EStructuralFeature eFeature) {
    final Collection<?> eValues = (Collection<?>) eObject.eGet(eFeature);

    @SuppressWarnings("unchecked")
    final Collection<Object> values = (Collection<Object>) modelObject.eGet(eFeature);

    // clear as the object may have been read from the db
    values.clear();

    for (final Object eValue : eValues) {
      final FeatureMap.Entry eEntry = (FeatureMap.Entry) eValue;

      final Object featureMapEntry = ModelResolver.getInstance().createFeatureMapEntry(eFeature);
      final ModelFeatureMapEntry<?> mEntry =
          ModelResolver.getInstance().getModelFeatureMapEntry(eFeature, featureMapEntry);
      mEntry.setEStructuralFeature(eEntry.getEStructuralFeature());

      final Object convertedValue;
      if (mEntry.getEStructuralFeature() instanceof EAttribute) {
        convertedValue =
            convertEAttributeValue(
                eEntry.getValue(),
                ((EAttribute) eEntry.getEStructuralFeature()).getEAttributeType());
      } else {
        convertedValue = createTarget((EObject) eEntry.getValue());
      }

      mEntry.setValue(convertedValue);
      values.add(featureMapEntry);
    }
  }
示例#22
0
 public static void main(String[] args) {
   Collection c = new ArrayList();
   // 添加元素
   c.add("孙悟空");
   // 虽然集合里不能放基本类型的值,但Java支持自动装箱
   c.add(6);
   System.out.println("c集合的元素个数为:" + c.size());
   // 删除指定元素
   c.remove(6);
   System.out.println("c集合的元素个数为:" + c.size());
   // 判断是否包含指定字符串
   System.out.println("c集合的是否包含\"孙悟空\"字符串:" + c.contains("孙悟空"));
   c.add("轻量级Java EE企业应用实战");
   System.out.println("c集合的元素:" + c);
   Collection books = new HashSet();
   books.add("轻量级Java EE企业应用实战");
   books.add("疯狂Java讲义");
   System.out.println("c集合是否完全包含books集合?" + c.containsAll(books));
   // 用c集合减去books集合里的元素
   c.removeAll(books);
   System.out.println("c集合的元素:" + c);
   // 删除c集合里所有元素
   c.clear();
   System.out.println("c集合的元素:" + c);
   // books集合里只剩下c集合里也包含的元素
   books.retainAll(c);
   System.out.println("books集合的元素:" + books);
 }
 /**
  * Set the refs collection to the entity reference strings from the entities collection (and
  * nothing more)
  *
  * @param refs The collection (String) of entity references to modify.
  * @param entities The collection (Entity) of entity objects to use.
  */
 public static void setEntityRefsFromEntities(Collection refs, Collection entities) {
   refs.clear();
   for (Iterator i = entities.iterator(); i.hasNext(); ) {
     Entity entity = (Entity) i.next();
     refs.add(entity.getReference());
   }
 }
示例#24
0
 // look up and apply coarts for given rels to each sign in result
 private void applyCoarts(List<String> coartRels, Collection<Sign> result) {
   List<Sign> inputSigns = new ArrayList<Sign>(result);
   result.clear();
   List<Sign> outputSigns = new ArrayList<Sign>(inputSigns.size());
   // for each rel, lookup coarts and apply to input signs, storing results in output signs
   for (Iterator<String> it = coartRels.iterator(); it.hasNext(); ) {
     String rel = it.next();
     Collection<String> preds = (Collection<String>) _coartRelsToPreds.get(rel);
     if (preds == null) continue; // not expected
     Collection<Sign> coartResult = getSignsFromRelAndPreds(rel, preds);
     if (coartResult == null) continue;
     for (Iterator<Sign> it2 = coartResult.iterator(); it2.hasNext(); ) {
       Sign coartSign = it2.next();
       // apply to each input
       for (int j = 0; j < inputSigns.size(); j++) {
         Sign sign = inputSigns.get(j);
         grammar.rules.applyCoart(sign, coartSign, outputSigns);
       }
     }
     // switch output to input for next iteration
     inputSigns.clear();
     inputSigns.addAll(outputSigns);
     outputSigns.clear();
   }
   // add results back
   result.addAll(inputSigns);
 }
示例#25
0
  @Override
  public boolean uninstall(OTEStatusCallback<ConfigurationStatus> statusCallback) {
    boolean result = true;
    for (Bundle bundle : installedBundles) {
      try {
        bundle.uninstall();
      } catch (BundleException ex) {
        result = false;
        statusCallback.error("Failed to uninstall " + bundle.getSymbolicName(), ex);
      }
    }
    installedBundles.clear();

    for (Bundle bundle : runningBundles) {
      try {
        String entry = bundle.getHeaders().get("Fragment-Host");
        if (entry == null) {
          bundle.stop();
        }
        bundle.uninstall();
      } catch (BundleException ex) {
        result = false;
        statusCallback.error("Failed to stop and uninstall " + bundle.getSymbolicName(), ex);
      }
    }
    runningBundles.clear();

    return result;
  }
示例#26
0
 /** @see junit.framework.TestCase */
 protected void tearDown() throws Exception {
   assertNotNull("The collection of logs is null!", logs);
   logs.clear();
   logs = null;
   logRecv = null;
   super.tearDown();
 }
示例#27
0
文件: Table.java 项目: andrus/ashwood
 public void refreshColumns(DatabaseMetaData metaData) throws SQLException {
   columns.clear();
   ResultSet rs = null;
   try {
     rs = metaData.getColumns(catalog, schema, name, null);
     while (rs.next()) {
       Column column = new Column();
       columns.add(column);
       column.setOwner(this);
       column.setName(rs.getString("COLUMN_NAME"));
       column.setDataType(rs.getInt("DATA_TYPE"));
       column.setTypeName(rs.getString("TYPE_NAME"));
       column.setSize(rs.getInt("COLUMN_SIZE"));
       column.setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
       column.setRadix(rs.getInt("NUM_PREC_RADIX"));
       column.setNullable(rs.getInt("NULLABLE"));
       column.setRemarks(rs.getString("REMARKS"));
       column.setDefaultValue(rs.getString("COLUMN_DEF"));
       column.setCharOctetLength(rs.getInt("CHAR_OCTET_LENGTH"));
       column.setOrdinalPosition(rs.getInt("ORDINAL_POSITION"));
     }
   } catch (SQLException sqle) {
     throw sqle;
   } finally {
     try {
       rs.close();
     } catch (Exception ex) {
     }
   }
 }
  /** @param cnt Count. */
  private void checkPoll(int cnt) {
    init();

    int step = 10;

    assert cnt % step == 0;

    Collection<Long> set = new HashSet<>(step);

    for (int i = 0; i < cnt; i++) lru.offer(0, i, i);

    assertEquals(cnt, lru.size());

    for (int i = 0; i < cnt; i += step) {
      for (int j = 0; j < step; j++) {
        long qAddr = lru.prePoll();

        assertTrue(qAddr != 0);
        assertTrue(set.add(qAddr));
      }

      for (long qAddr : set) lru.poll(qAddr);

      set.clear();
    }

    assertEquals(0, lru.size());
  }
示例#29
0
 private void finishCurrentDataSourceOperation(boolean theIsTop) throws DataSourceException {
   if (theIsTop) {
     mCascadePending.clear();
     mOp.execute();
     mOp = null;
   }
 }
示例#30
0
文件: Table.java 项目: andrus/ashwood
 public void refreshForeignKeys(DatabaseMetaData metaData) throws SQLException {
   foreignKeys.clear();
   ResultSet rs = null;
   try {
     rs = metaData.getImportedKeys(catalog, schema, name);
     while (rs.next()) {
       ForeignKey fk = new ForeignKey();
       foreignKeys.add(fk);
       fk.setOwner(this);
       fk.setPkTableCatalog(rs.getString("PKTABLE_CAT"));
       fk.setPkTableSchema(rs.getString("PKTABLE_SCHEM"));
       fk.setPkTableName(rs.getString("PKTABLE_NAME"));
       fk.setPkColumnName(rs.getString("PKCOLUMN_NAME"));
       fk.setColumnName(rs.getString("FKCOLUMN_NAME"));
       fk.setKeySequence(rs.getShort("KEY_SEQ"));
       fk.setUpdateRule(rs.getShort("UPDATE_RULE"));
       fk.setDeleteRule(rs.getShort("DELETE_RULE"));
       fk.setName(rs.getString("FK_NAME"));
       fk.setPkName(rs.getString("PK_NAME"));
       fk.setDeferrability(rs.getShort("DEFERRABILITY"));
     }
   } catch (SQLException sqle) {
     throw sqle;
   } finally {
     try {
       rs.close();
     } catch (Exception ex) {
     }
   }
 }