public boolean equals(final Object other) {
   if (!(other instanceof TIntObjectHashMap)) {
     return false;
   }
   final TIntObjectHashMap that = (TIntObjectHashMap) other;
   return that.size() == this.size() && this.forEachEntry(new EqProcedure(that));
 }
Ejemplo n.º 2
0
  public TIntObjectHashMap<TIntHashSet> resolve(
      DirectedGraph<Integer, RDFEdge> graph,
      Set<Set<Integer>> literalSubjectPairs,
      Document document,
      KnowledgeBase kb) {

    TIntObjectHashMap<TIntHashSet> resolvedSubjects = new TIntObjectHashMap<TIntHashSet>();

    TIntHashSet ham = new TIntHashSet();
    TIntHashSet spam = new TIntHashSet();

    resolvedSubjects.put(0, spam);
    resolvedSubjects.put(1, ham);

    for (Set<Integer> c : literalSubjectPairs) {
      TIntHashSet subjects = getAmbiguousURIRefs(c);

      if (subjects.size() > 1) {
        ham.add(subjects.toArray()[new Random().nextInt(subjects.size())]);
        if (resolvedSubjects.size() < subjects.size()) {
          for (int s : subjects.toArray()) {
            if (!ham.contains(s)) {
              spam.add(s);
            }
          }
        }
      }
    }
    return resolvedSubjects;
  }
Ejemplo n.º 3
0
  public final ItemAuction[] getAuctions() {
    final ItemAuction[] auctions;

    synchronized (_auctions) {
      auctions = _auctions.getValues(new ItemAuction[_auctions.size()]);
    }

    return auctions;
  }
 public ContextRelevantStaticMethod(
     final PsiMethod psiMethod, @Nullable final TIntObjectHashMap<PsiVariable> parameters) {
   this.psiMethod = psiMethod;
   if (parameters == null) {
     this.parameters = null;
   } else {
     this.parameters = new TIntObjectHashMap<>(parameters.size());
     parameters.forEachEntry(
         new TIntObjectProcedure<PsiVariable>() {
           @SuppressWarnings("ConstantConditions")
           @Override
           public boolean execute(final int pos, final PsiVariable var) {
             ContextRelevantStaticMethod.this.parameters.put(
                 pos, new VariableSubLookupElement(var));
             return true;
           }
         });
   }
 }
  private void storeIds(@NotNull ConcurrentIntObjectMap<int[]> fileToForwardIds) {
    int forwardSize = 0;
    int backwardSize = 0;
    final TIntObjectHashMap<TIntArrayList> fileToBackwardIds =
        new TIntObjectHashMap<TIntArrayList>(fileToForwardIds.size());
    for (ConcurrentIntObjectMap.IntEntry<int[]> entry : fileToForwardIds.entries()) {
      int fileId = entry.getKey();
      int[] forwardIds = entry.getValue();
      forwardSize += forwardIds.length;
      for (int forwardId : forwardIds) {
        TIntArrayList backIds = fileToBackwardIds.get(forwardId);
        if (backIds == null) {
          backIds = new TIntArrayList();
          fileToBackwardIds.put(forwardId, backIds);
        }
        backIds.add(fileId);
        backwardSize++;
      }
    }
    log("backwardSize = " + backwardSize);
    log("forwardSize = " + forwardSize);
    log("fileToForwardIds.size() = " + fileToForwardIds.size());
    log("fileToBackwardIds.size() = " + fileToBackwardIds.size());
    assert forwardSize == backwardSize;

    // wrap in read action so that sudden quit (in write action) would not interrupt us
    myApplication.runReadAction(
        () -> {
          if (!myApplication.isDisposed()) {
            fileToBackwardIds.forEachEntry(
                new TIntObjectProcedure<TIntArrayList>() {
                  @Override
                  public boolean execute(int fileId, TIntArrayList backIds) {
                    storage.addAll(fileId, backIds.toNativeArray());
                    return true;
                  }
                });
          }
        });
  }
Ejemplo n.º 6
0
 @Override
 public int size() {
   return _cubics.size();
 }
Ejemplo n.º 7
0
 public TreeNode[] copyChildren() {
   return children.getValues(new TreeNode[children.size()]);
 }
Ejemplo n.º 8
0
 /** @return wrappedItemData() */
 public int size() {
   return wrappedItemData.size();
 }
Ejemplo n.º 9
0
 public boolean nonEmpty() {
   return myBindings.size() > 0;
 }
Ejemplo n.º 10
0
 /** @return items.size() */
 public int size() {
   return items.size();
 }
Ejemplo n.º 11
0
 public int size() {
   return npctlistData.size();
 }
Ejemplo n.º 12
0
  public ItemAuctionInstance(final int instanceId, final AtomicInteger auctionIds, final Node node)
      throws Exception {
    _instanceId = instanceId;
    _auctionIds = auctionIds;
    _auctions = new TIntObjectHashMap<ItemAuction>();
    _items = new ArrayList<AuctionItem>();

    final NamedNodeMap nanode = node.getAttributes();
    final StatsSet generatorConfig = new StatsSet();
    for (int i = nanode.getLength(); i-- > 0; ) {
      final Node n = nanode.item(i);
      if (n != null) generatorConfig.set(n.getNodeName(), n.getNodeValue());
    }

    _dateGenerator = new AuctionDateGenerator(generatorConfig);

    for (Node na = node.getFirstChild(); na != null; na = na.getNextSibling()) {
      try {
        if ("item".equalsIgnoreCase(na.getNodeName())) {
          final NamedNodeMap naa = na.getAttributes();
          final int auctionItemId =
              Integer.parseInt(naa.getNamedItem("auctionItemId").getNodeValue());
          final int auctionLenght =
              Integer.parseInt(naa.getNamedItem("auctionLenght").getNodeValue());
          final long auctionInitBid =
              Integer.parseInt(naa.getNamedItem("auctionInitBid").getNodeValue());

          final int itemId = Integer.parseInt(naa.getNamedItem("itemId").getNodeValue());
          final int itemCount = Integer.parseInt(naa.getNamedItem("itemCount").getNodeValue());

          if (auctionLenght < 1)
            throw new IllegalArgumentException(
                "auctionLenght < 1 for instanceId: " + _instanceId + ", itemId " + itemId);

          final StatsSet itemExtra = new StatsSet();
          final AuctionItem item =
              new AuctionItem(
                  auctionItemId, auctionLenght, auctionInitBid, itemId, itemCount, itemExtra);

          if (!item.checkItemExists())
            throw new IllegalArgumentException("Item with id " + itemId + " not found");

          for (final AuctionItem tmp : _items) {
            if (tmp.getAuctionItemId() == auctionItemId)
              throw new IllegalArgumentException("Dublicated auction item id " + auctionItemId);
          }

          _items.add(item);

          for (Node nb = na.getFirstChild(); nb != null; nb = nb.getNextSibling()) {
            if ("extra".equalsIgnoreCase(nb.getNodeName())) {
              final NamedNodeMap nab = nb.getAttributes();
              for (int i = nab.getLength(); i-- > 0; ) {
                final Node n = nab.item(i);
                if (n != null) itemExtra.set(n.getNodeName(), n.getNodeValue());
              }
            }
          }
        }
      } catch (final IllegalArgumentException e) {
        _log.log(Level.WARNING, "ItemAuctionInstance: Failed loading auction item", e);
      }
    }

    if (_items.isEmpty()) throw new IllegalArgumentException("No items defined");

    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement =
          con.prepareStatement("SELECT auctionId FROM item_auction WHERE instanceId=?");
      statement.setInt(1, _instanceId);
      ResultSet rset = statement.executeQuery();

      while (rset.next()) {
        final int auctionId = rset.getInt(1);
        try {
          final ItemAuction auction = loadAuction(auctionId);
          if (auction != null) {
            _auctions.put(auctionId, auction);
          } else {
            ItemAuctionManager.deleteAuction(auctionId);
          }
        } catch (final SQLException e) {
          _log.log(Level.WARNING, "ItemAuctionInstance: Failed loading auction: " + auctionId, e);
        }
      }
    } catch (final SQLException e) {
      _log.log(Level.SEVERE, "L2ItemAuctionInstance: Failed loading auctions.", e);
      return;
    } finally {
      L2DatabaseFactory.close(con);
    }

    _log.log(
        Level.INFO,
        "L2ItemAuctionInstance: Loaded "
            + _items.size()
            + " item(s) and registered "
            + _auctions.size()
            + " auction(s) for instance "
            + _instanceId
            + ".");
    checkAndSetCurrentAndNextAuction();
  }
Ejemplo n.º 13
0
  final void checkAndSetCurrentAndNextAuction() {
    final ItemAuction[] auctions = _auctions.getValues(new ItemAuction[_auctions.size()]);

    ItemAuction currentAuction = null;
    ItemAuction nextAuction = null;

    switch (auctions.length) {
      case 0:
        {
          nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
          break;
        }

      case 1:
        {
          switch (auctions[0].getAuctionState()) {
            case CREATED:
              {
                if (auctions[0].getStartingTime()
                    < (System.currentTimeMillis() + START_TIME_SPACE)) {
                  currentAuction = auctions[0];
                  nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
                } else {
                  nextAuction = auctions[0];
                }
                break;
              }

            case STARTED:
              {
                currentAuction = auctions[0];
                nextAuction =
                    createAuction(
                        Math.max(
                            currentAuction.getEndingTime() + FINISH_TIME_SPACE,
                            System.currentTimeMillis() + START_TIME_SPACE));
                break;
              }

            case FINISHED:
              {
                currentAuction = auctions[0];
                nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
                break;
              }

            default:
              throw new IllegalArgumentException();
          }
          break;
        }

      default:
        {
          Arrays.sort(
              auctions,
              new Comparator<ItemAuction>() {
                @Override
                public final int compare(final ItemAuction o1, final ItemAuction o2) {
                  return ((Long) o2.getStartingTime()).compareTo(o1.getStartingTime());
                }
              });

          // just to make sure we won`t skip any auction because of little different times
          final long currentTime = System.currentTimeMillis();

          for (int i = 0; i < auctions.length; i++) {
            final ItemAuction auction = auctions[i];
            if (auction.getAuctionState() == ItemAuctionState.STARTED) {
              currentAuction = auction;
              break;
            } else if (auction.getStartingTime() <= currentTime) {
              currentAuction = auction;
              break; // only first
            }
          }

          for (int i = 0; i < auctions.length; i++) {
            final ItemAuction auction = auctions[i];
            if (auction.getStartingTime() > currentTime && currentAuction != auction) {
              nextAuction = auction;
              break;
            }
          }

          if (nextAuction == null)
            nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
          break;
        }
    }

    _auctions.put(nextAuction.getAuctionId(), nextAuction);

    _currentAuction = currentAuction;
    _nextAuction = nextAuction;

    if (currentAuction != null && currentAuction.getAuctionState() != ItemAuctionState.FINISHED) {
      if (currentAuction.getAuctionState() == ItemAuctionState.STARTED)
        setStateTask(
            ThreadPoolManager.getInstance()
                .scheduleGeneral(
                    new ScheduleAuctionTask(currentAuction),
                    Math.max(currentAuction.getEndingTime() - System.currentTimeMillis(), 0L)));
      else
        setStateTask(
            ThreadPoolManager.getInstance()
                .scheduleGeneral(
                    new ScheduleAuctionTask(currentAuction),
                    Math.max(currentAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
      _log.log(
          Level.INFO,
          "L2ItemAuctionInstance: Schedule current auction "
              + currentAuction.getAuctionId()
              + " for instance "
              + _instanceId);
    } else {
      setStateTask(
          ThreadPoolManager.getInstance()
              .scheduleGeneral(
                  new ScheduleAuctionTask(nextAuction),
                  Math.max(nextAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
      _log.log(
          Level.INFO,
          "L2ItemAuctionInstance: Schedule next auction "
              + nextAuction.getAuctionId()
              + " on "
              + DATE_FORMAT.format(new Date(nextAuction.getStartingTime()))
              + " for instance "
              + _instanceId);
    }
  }