Exemplo n.º 1
0
  public void restore() {
    _listByIndex.clear();
    _listByClassId.clear();
    List<SubClass> subclasses = CharacterSubclassDAO.getInstance().restore(_owner);
    int lastFreeIndex = 2;
    for (SubClass sub : subclasses) {
      if (sub == null) // Невозможно, но хай будет.
      continue;

      if (size() >= MAX_SUB_COUNT) {
        _log.warn(
            "SubClassList:restore: Limit is subclass! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
        break;
      }

      if (sub.isActive()) {
        _activeSubClass = sub;
      }

      if (sub.isBase()) {
        _baseSubClass = sub;
        sub.setIndex(1);
      } else {
        sub.setIndex(lastFreeIndex);
        lastFreeIndex++;
      }

      if (_listByIndex.containsKey(sub.getIndex()))
        _log.warn(
            "SubClassList:restore: Duplicate index in player subclasses! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
      _listByIndex.put(sub.getIndex(), sub);

      if (_listByClassId.containsKey(sub.getClassId()))
        _log.warn(
            "SubClassList:restore: Duplicate class_id in player subclasses! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
      _listByClassId.put(sub.getClassId(), sub);
    }

    _lastFreeIndex = lastFreeIndex;

    if (_listByIndex.size() != _listByClassId.size()) // Невозможно, но хай будет.
    _log.warn(
          "SubClassList:restore: The size of the lists do not match! Player: "
              + _owner.getName()
              + "("
              + _owner.getObjectId()
              + ")");
  }
Exemplo n.º 2
0
  public String[] getNontransmitted() {
    String control[] = new String[getChildrenNum()];
    TreeMap<String, Integer> controlMap = NewIt.newTreeMap();
    // how to deal with missing data???

    if (childrenGenoMap.size() == 1) { // situation 1
      // System.out.println("Table1 s1");

      String[] genopool = new String[1];
      genopool[0] = childrenGenoMap.firstKey();
      double[] freq = new double[1];
      freq[0] = 1.0;
      Produce(control, controlMap, genopool, freq);
    } else if (childrenGenoMap.size() == 2) { // situation 2, 3
      // System.out.println("Table1 s2,3");

      String[] genopool = new String[2];
      genopool[0] = childrenGenoMap.firstKey();
      genopool[1] = childrenGenoMap.lastKey();
      double[] freq = new double[2];
      freq[0] = 0.5;
      freq[1] = 1.0;
      do {
        controlMap.clear();
        Produce(control, controlMap, genopool, freq);
      } while (!(controlMap.size() > 1));
    } else {
      System.err.println("Wrecked in Rabinowitz table 1");
    }
    return control;
  }
Exemplo n.º 3
0
  private boolean refresh(String importString) {
    this.scope = new Scope(new VariableList(), Parser.getExistingFunctionScope());

    TreeMap imports = this.parser.getImports();
    imports.clear();

    if (importString.length() > 0) {
      String[] importList = importString.split(",");

      for (int i = 0; i < importList.length; ++i) {
        try {
          this.parser.importFile(importList[i], this.scope);
        } catch (ScriptException e) {
          // The user changed the script since it was validated
          KoLmafia.updateDisplay(MafiaState.ERROR, e.getMessage());
          return false;
        } catch (Exception e) {
          StaticEntity.printStackTrace(e);
          return false;
        }
      }
    }

    this.lastImportString = importString;
    return true;
  }
Exemplo n.º 4
0
 public void close() {
   ensureOpen();
   if (this.open.compareAndSet(true, false)) {
     IOUtils.closeWhileHandlingException(nodes.values());
     nodes.clear();
   }
 }
 @Override
 public synchronized YieldCurveDefinitionDocument update(YieldCurveDefinitionDocument document) {
   ArgumentChecker.notNull(document, "document");
   ArgumentChecker.notNull(document.getYieldCurveDefinition(), "document.yieldCurveDefinition");
   final Currency currency = document.getYieldCurveDefinition().getCurrency();
   final String name = document.getYieldCurveDefinition().getName();
   final UniqueId uid = UniqueId.of(getUniqueIdScheme(), name + "_" + currency.getCode());
   if (!uid.equals(document.getUniqueId())) {
     throw new IllegalArgumentException("Invalid unique identifier");
   }
   final Pair<Currency, String> key = Pair.of(currency, name);
   final TreeMap<Instant, YieldCurveDefinition> value = _definitions.get(key);
   if (value == null) {
     throw new DataNotFoundException("UID '" + uid + "' not found");
   }
   if (_sourceVersionCorrection.getVersionAsOf() != null) {
     // Don't need to keep the old values before the one needed by "versionAsOfInstant"
     final Instant oldestNeeded = value.floorKey(_sourceVersionCorrection.getVersionAsOf());
     value.headMap(oldestNeeded).clear();
   } else {
     // Don't need any old values
     value.clear();
   }
   Instant now = Instant.now();
   value.put(now, document.getYieldCurveDefinition());
   document.setUniqueId(uid);
   changeManager().entityChanged(ChangeType.CHANGED, uid.getObjectId(), null, null, now);
   return document;
 }
Exemplo n.º 6
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    TreeMap<Long, Long> tmap = new TreeMap<>();
    long res = 0;
    while (t-- > 0) {
      res = 0;
      int n = in.nextInt();
      long m = in.nextLong();
      tmap.clear();
      long[] arr = new long[n];
      res = in.nextLong();
      arr[0] = res % m;
      res = Long.MIN_VALUE;
      tmap.put(arr[0], arr[0]);
      for (int i = 1; i < arr.length; i++) {
        arr[i] = in.nextLong();
        arr[i] %= m;
        arr[i] += arr[i - 1];
        arr[i] %= m;

        if (tmap.higherEntry(arr[i]) == null) {
          res = Math.max(res, arr[i]);
          tmap.put(arr[i], arr[i]);
          continue;
        }
        long val = tmap.higherEntry(arr[i]).getValue();
        res = Math.max(res, (arr[i] - val + m) % m);
        tmap.put(arr[i], arr[i]);
      }

      System.out.println(res);
    }
  }
Exemplo n.º 7
0
  /**
   * @param txt input
   * @param urls out URLs
   */
  public void getURLs(String txt, ArrayList<MarkdownURL> urls) {
    if (txt == null) {
      txt = "";
    }
    // Standardize line endings:
    txt.replaceAll("\\r\\n", "\n"); // DOS to Unix
    txt.replaceAll("\\r", "\n"); // Mac to Unix
    txt.replaceAll("^[ \\t]+$", "");

    //        // Make sure $text ends with a couple of newlines:
    //        text.append("\n\n");

    //        text.detabify();
    txt.replaceAll("^[ ]+$", "");

    urls.clear();

    TreeMap<Integer, Integer> startToEndOffsetMap = new TreeMap<Integer, Integer>();

    // doAnchors originally called from runBlockGamut -> formParagraphs -> runSpanGamut
    txt = doAnchorURLs(txt, urls, startToEndOffsetMap);
    txt = doAutoLinkURLs(txt, urls, startToEndOffsetMap);
    txt = doAutoLinkSubredditURLs(txt, urls, startToEndOffsetMap);

    startToEndOffsetMap.clear();

    Collections.sort(urls);
  }
Exemplo n.º 8
0
 @Override
 public void close() throws IOException {
   try {
     IOUtils.close(postingsReader);
   } finally {
     fields.clear();
   }
 }
 @Override
 public boolean del() {
   for (IFile file : fileMap.values()) {
     file.del();
   }
   fileMap.clear();
   return thisDir.delete();
 }
Exemplo n.º 10
0
 public void dispose() {
   UMOContainerContext container;
   for (Iterator iterator = containers.values().iterator(); iterator.hasNext(); ) {
     container = (UMOContainerContext) iterator.next();
     container.dispose();
   }
   containers.clear();
   containers = null;
 }
 @Override
 public void close() throws IOException {
   try {
     IOUtils.close(termsIn, postingsReader);
   } finally {
     // Clear so refs to terms index is GCable even if
     // app hangs onto us:
     fields.clear();
   }
 }
Exemplo n.º 12
0
 public void clear() {
   lock.lock();
   try {
     children.clear();
     children = null;
     hasCache = false;
   } finally {
     lock.unlock();
   }
 }
Exemplo n.º 13
0
 public void syncChanges(ArrayList<TreeMap<Integer, FactoryObject>> dataArray) {
   if (dataArray.size() == 1) {
     TreeMap<Integer, FactoryObject> changeData = dataArray.get(0);
     fos.clear();
     fos = changeData;
   } else {
     System.out.println("Warning: Corrupt frame data");
   }
   repaint();
 }
Exemplo n.º 14
0
  private void applySort() {
    if (row2srcMap != null) row2srcMap.clear();
    row2srcMap = null;

    if (src2rowMap != null) src2rowMap.clear();
    src2rowMap = null;

    if (rowComparator == null) return;
    if (tableModel == null) return;

    int rowCo = tableModel.getRowCount();

    List<Integer> indexes = new ArrayList<Integer>();
    for (int i = 0; i < rowCo; i++) {
      indexes.add(i);
    }

    Comparator<Integer> srcRowCmp =
        new Comparator<Integer>() {
          @Override
          public int compare(Integer row1, Integer row2) {
            RowData rowA = new RowData();
            rowA.setTableModel(tableModel);
            rowA.setRowIndex(row1);
            RowData rowB = new RowData();
            rowB.setTableModel(tableModel);
            rowB.setRowIndex(row2);
            int res = rowComparator.compare(rowA, rowB);
            return res;
          }
        };

    Collections.sort(indexes, srcRowCmp);

    src2rowMap = new TreeMap<Integer, Integer>();
    row2srcMap = new TreeMap<Integer, Integer>();
    for (int outRowIndex = 0; outRowIndex < indexes.size(); outRowIndex++) {
      int innerRowIndex = indexes.get(outRowIndex);
      row2srcMap.put(outRowIndex, innerRowIndex);
      src2rowMap.put(innerRowIndex, outRowIndex);
    }
  }
Exemplo n.º 15
0
  public static int report() {
    int bytes = 0;
    for (Reporter r : report.values()) {
      System.out.println(r);
      bytes += r.bytes;
    }

    report.clear();

    return bytes;
  }
Exemplo n.º 16
0
 @Override
 public void clear() {
   super.clear();
   scaling = Scaling.Absolute;
   reliefShading = false;
   interpolate = true;
   forceValuesIntoRange = false;
   min = null;
   max = null;
   cache = null;
 }
Exemplo n.º 17
0
 /** Removes the SimpleTimer. */
 public void removeSimpleTimer() {
   synchronized (_events) {
     runn.setAnswer(false);
     _events.clear();
     _eventTimes.clear();
     _events.notifyAll();
   }
   synchronized (_readyEvents) {
     _readyEvents.clear();
     _readyEvents.notifyAll();
   }
 }
Exemplo n.º 18
0
  public synchronized void unregistered(byte[] guid) {
    if (LOG.isDebugEnabled())
      LOG.debug("ranker unregistered with guid " + (new GUID(guid)).toHexString(), new Exception());

    running = false;
    newHosts.addAll(verifiedHosts);
    newHosts.addAll(testedLocations);
    verifiedHosts.clear();
    pingedHosts.clear();
    testedLocations.clear();
    lastPingTime = 0;
  }
Exemplo n.º 19
0
 @Override
 public String isStale(String uri, Calendar modified) throws IOException {
   // TODO finish this method
   results.clear();
   for (Entry<String, CacheStalenessCheck> e : checks.entrySet()) {
     String uri2 = e.getKey();
     String result = e.getValue().isStale(uri2, modified_dates.get(uri2));
     if (result != null) {
       results.put(uri2, result);
     }
   }
   return null;
 }
Exemplo n.º 20
0
 /**
  * Clear the entire contents of the cache and delete the backing files. This should only be used
  * when the server is reinitializing, because the users are going to lose their files.
  */
 public static void purgeCache(Configuration conf, MRAsyncDiskService service) throws IOException {
   synchronized (cachedArchives) {
     LocalFileSystem localFs = FileSystem.getLocal(conf);
     for (Map.Entry<String, CacheStatus> f : cachedArchives.entrySet()) {
       try {
         deleteLocalPath(service, localFs, f.getValue().localizedLoadPath);
       } catch (IOException ie) {
         LOG.debug("Error cleaning up cache", ie);
       }
     }
     cachedArchives.clear();
   }
 }
Exemplo n.º 21
0
 public void refreshCache() throws IOException {
   lock.lock();
   try {
     if (children == null) {
       children = new TreeMap<>();
     }
     children.clear();
     doRefreshCache();
     hasCache = true;
   } finally {
     lock.unlock();
   }
 }
Exemplo n.º 22
0
  // 1 : new turn, redo all collision prediction
  public void redoCollisionPrediction(long time, long dtms) {
    // clean
    collisionDetected.clear();
    for (Forme f2 : allObjects) {
      f2.predictions.clear();
    }

    // maj
    for (Forme f1 : movingObjects) {
      System.out.println("check forme " + f1 + " : " + f1.physicUpdate + f1.position);
      if (f1.physicUpdate) {
        for (Forme f2 : allObjects) {
          if (f1 == f2) continue;
          // first lazy check (TODOAFTER: check if it's really useful)
          System.out.println(
              "redocollpred: dtms="
                  + dtms
                  + " , dtmsf1="
                  + (time - f1.time)
                  + ", time="
                  + time
                  + ", time f1="
                  + f1.time);
          long timeCollide = canCollide(f1, f1.time, time - f1.time, f2, f2.time, time - f2.time);
          System.out.println(
              "redocollpred: tiemCollide=" + timeCollide + " => " + (timeCollide - time));
          if (timeCollide > 0) {

            System.out.println("possible collision " + f1.predictions.get(f2));
            // check if collision exist (and it's not a joint)
            CollisionPrediction collider = f1.predictions.get(f2);
            if (collider == null /* && !f1.joint.containsKey(f2) */) {
              System.out.println("poCreate ssible collision ");
              // create a collisionPrediction
              collider = new CollisionPrediction();
              collider.moment = timeCollide;
              collider.precisionMoment = Precision.INITIAL;
              collider.maxMomentError =
                  (f1.position.distance(f2.position) + f1.roundBBRayon + f2.roundBBRayon)
                      / (f1.getCachedVitesse(f1.time) + f2.getCachedVitesse(f2.time));
              collider.forme1 = f1;
              collider.forme2 = f2;
              f1.predictions.put(f2, collider);
              f2.predictions.put(f1, collider);
              collisionDetected.put(timeCollide, collider);
            }
          }
        }
      }
    }
  }
  @Override
  public List<UniqueId> replaceAllVersions(
      ObjectIdentifiable objectIdentifiable,
      List<YieldCurveDefinitionDocument> replacementDocuments) {
    ArgumentChecker.notNull(replacementDocuments, "replacementDocuments");
    ArgumentChecker.notNull(objectIdentifiable, "objectIdentifiable");

    final Instant now = Instant.now();

    for (YieldCurveDefinitionDocument replacementDocument : replacementDocuments) {
      ArgumentChecker.notNull(replacementDocument, "document");
      ArgumentChecker.notNull(
          replacementDocument.getYieldCurveDefinition(), "document.yieldCurveDefinition");
      final Currency currency = replacementDocument.getYieldCurveDefinition().getCurrency();
      final String name = replacementDocument.getYieldCurveDefinition().getName();
      final UniqueId id = UniqueId.of(getUniqueIdScheme(), name + "_" + currency.getCode());
      ArgumentChecker.isTrue(id.equals(objectIdentifiable), "Invalid object identifier");
    }

    YieldCurveDefinitionDocument storedDocument = get(objectIdentifiable, null);
    if (storedDocument == null) {
      throw new DataNotFoundException("Document not found: " + objectIdentifiable);
    }
    final Currency currency = storedDocument.getYieldCurveDefinition().getCurrency();
    final String name = storedDocument.getYieldCurveDefinition().getName();
    Pair<Currency, String> key = Pair.of(currency, name);

    final TreeMap<Instant, YieldCurveDefinition> value = _definitions.get(key);
    if (value == null) {
      throw new DataNotFoundException("OID '" + objectIdentifiable + "' not found");
    }
    value.clear();

    List<YieldCurveDefinitionDocument> orderedReplacementDocuments =
        MasterUtils.adjustVersionInstants(now, null, null, replacementDocuments);

    final Instant lowestVersionFrom = orderedReplacementDocuments.get(0).getVersionFromInstant();

    ArgumentChecker.notNull(
        lowestVersionFrom, "You must define version from of the first document");

    for (YieldCurveDefinitionDocument replacementDocument : orderedReplacementDocuments) {
      value.put(
          replacementDocument.getVersionFromInstant(),
          replacementDocument.getYieldCurveDefinition());
      changeManager()
          .entityChanged(ChangeType.CHANGED, replacementDocument.getObjectId(), null, null, now);
    }
    return MasterUtils.mapToUniqueIDs(orderedReplacementDocuments);
  }
 /*
  * retainAll: 重なっている内容のみ保持し、重ならない内容は削除する。
  */
 public static void clearStaticFields() {
   types.clear();
   types.putAll(original_types);
   // functions.retainAll(original_functions);
   functions.clear();
   functions.addAll(original_functions);
   numOfSameWords.clear();
   bestRoots.clearTable(); // これやってもやらなくても変わらないようだ。
   //		System.gc();
   // used memoryの測定(単位:KByte)
   //		Runtime rt = Runtime.getRuntime();
   //		long usedMemory = rt.totalMemory()/1024 - rt.freeMemory()/1024;
   //		System.out.println("使用メモリ量= " + usedMemory + "KByte");
 }
Exemplo n.º 25
0
  /**
   * Method that reads data generated by Market2.getAutoMarketStatus() on the server. All data for
   * all BM units sent at once. "|" used to seperate units, * used to seperate fields inside each
   * unit.
   */
  public void setBMData(String command) {

    // create tokenizer
    StringTokenizer mainTokenizer = new StringTokenizer(command, "$");

    // clear all current BM data
    BlackMarket.clear();

    while (mainTokenizer.hasMoreTokens()) {
      boolean hidden = Boolean.parseBoolean(mwclient.getserverConfigs("HiddenBMUnits"));
      CBMUnit currBMUnit = new CBMUnit(TokenReader.readString(mainTokenizer), this, hidden);
      BlackMarket.put(currBMUnit.getAuctionID(), currBMUnit);
    }
  }
Exemplo n.º 26
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == RELOAD_ID) {
     // re-create the thread
     downloadListIndexThread = new DownloadIndexListThread();
     downloadIndexList();
   } else {
     final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter) getListAdapter();
     if (item.getItemId() == SELECT_ALL_ID) {
       int selected = 0;
       for (int i = 0; i < listAdapter.getCount(); i++) {
         IndexItem es = listAdapter.getItem(i);
         if (!entriesToDownload.containsKey(es.getFileName())) {
           selected++;
           entriesToDownload.put(es.getFileName(), createDownloadEntry(es));
         }
       }
       Toast.makeText(
               this,
               MessageFormat.format(getString(R.string.items_were_selected), selected),
               Toast.LENGTH_SHORT)
           .show();
       listAdapter.notifyDataSetInvalidated();
       if (selected > 0) {
         findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
       }
     } else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
       final Collection<String> listAlreadyDownloaded = listAlreadyDownloadedWithAlternatives();
       final List<IndexItem> filtered = new ArrayList<IndexItem>();
       for (String file : listAlreadyDownloaded) {
         IndexItem fileItem = listAdapter.getIndexFiles().get(file);
         if (fileItem != null) {
           filtered.add(fileItem);
         }
       }
       listAdapter.clear();
       for (IndexItem fileItem : filtered) {
         listAdapter.add(fileItem);
       }
     } else if (item.getItemId() == DESELECT_ALL_ID) {
       entriesToDownload.clear();
       listAdapter.notifyDataSetInvalidated();
       findViewById(R.id.DownloadButton).setVisibility(View.GONE);
     } else {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 27
0
  private void insertInternalRow(int internalRowIndex) {
    if (src2rowMap == null) return;
    if (row2srcMap == null) return;

    for (int outI = 0; outI < row2srcMap.size(); outI++) {
      int innI = row2srcMap.get(outI);
      if (innI > internalRowIndex) {
        row2srcMap.put(outI, innI + 1);
      }
    }

    src2rowMap.clear();
    for (Map.Entry<Integer, Integer> e : row2srcMap.entrySet()) {
      int outIdx = e.getKey();
      int innIdx = e.getValue();
      src2rowMap.put(innIdx, outIdx);
    }
  }
Exemplo n.º 28
0
  public void setComponentConverter(String converterData) {
    try {
      StringTokenizer st = new StringTokenizer(converterData, "#");

      ComponentConverter.clear();
      while (st.hasMoreTokens()) {
        ComponentToCritsConverter converter = new ComponentToCritsConverter();
        converter.setCritName(TokenReader.readString(st));
        converter.setMinCritLevel(TokenReader.readInt(st));
        converter.setComponentUsedType(TokenReader.readInt(st));
        converter.setComponentUsedWeight(TokenReader.readInt(st));
        ComponentConverter.put(converter.getCritName(), converter);
      }
      mwclient.setWaiting(false);
    } catch (Exception ex) {
      CampaignData.mwlog.errLog(ex);
    }
  }
 /** Clears the maps just incase the data is not being reassigned. */
 private void clearMaps() {
   if (shapeStatsList != null) shapeStatsList.clear();
   shapeStatsList = null;
   if (pixelStats != null) pixelStats.clear();
   pixelStats = null;
   if (shapeMap != null) shapeMap.clear();
   shapeMap = null;
   if (maxStats != null) maxStats.clear();
   maxStats = null;
   if (meanStats != null) meanStats.clear();
   meanStats = null;
   if (minStats != null) minStats.clear();
   minStats = null;
   if (sumStats != null) sumStats.clear();
   sumStats = null;
   if (stdDevStats != null) stdDevStats.clear();
   stdDevStats = null;
 }
 /**
  * Dispose of the manager. During disposal a manager is required to release all references such as
  * listeners and internal resources in preparation for garbage collection.
  */
 public synchronized void dispose() {
   try {
     m_model.removeCacheListener(this);
     synchronized (m_resourceHosts) {
       ResourceHost[] hosts =
           (ResourceHost[]) m_resourceHosts.values().toArray(new ResourceHost[0]);
       for (int i = 0; i < hosts.length; i++) {
         ResourceHost host = hosts[i];
         terminate(host);
       }
       m_resourceHosts.clear();
     }
     terminate(m_registry);
   } catch (RemoteException e) {
     final String warning =
         "Unexpected remote exception occured while attempting to dispose of the cache handler.";
     getLogger().error(warning, e);
   }
 }