コード例 #1
0
 public static SortedMap<Integer, Double> shortestPath(DirectedGraph g, int source) {
   final SortedMap<Integer, Double> previousDistances = new TreeMap<Integer, Double>();
   final SortedMap<Integer, Double> currentDistances = new TreeMap<Integer, Double>();
   currentDistances.put(source, 0d);
   for (Integer v : g.getVertices()) {
     if (v != source) {
       currentDistances.put(v, Double.POSITIVE_INFINITY);
     }
   }
   for (int i = 1; i <= g.getNumVertices(); i++) {
     previousDistances.clear();
     previousDistances.putAll(currentDistances);
     currentDistances.clear();
     for (Integer v : g.getVertices()) {
       Double currentDistance = Double.POSITIVE_INFINITY;
       Double previousDistance = previousDistances.get(v);
       if (previousDistance < currentDistance) {
         currentDistance = previousDistance;
       }
       for (Edge e : g.getIncomingEdges(v)) {
         Double alternativeDistance = previousDistances.get(e.getVertexA()) + e.getLength();
         if (alternativeDistance < currentDistance) {
           currentDistance = alternativeDistance;
         }
       }
       currentDistances.put(v, currentDistance);
     }
   }
   if (!previousDistances.equals(currentDistances)) {
     // there are negative cost cycles
     return null;
   }
   return previousDistances;
 }
コード例 #2
0
 protected void clearItems() {
   for (TableItem i : mItems.values()) {
     i.mValue.deleteObserver(i);
   }
   mModel.setRowCount(0);
   mItems.clear();
 }
コード例 #3
0
ファイル: DataModel.java プロジェクト: gawrije/Vitro
  /** Data in the model has been updated. Refresh all derived data. */
  private void calculate() {
    // Clear all derived data.
    runStatus = Status.OK;

    suiteDataMap.clear();
    suiteMapByStatus.clear();
    for (Status s : Status.values()) {
      suiteMapByStatus.put(s, new ArrayList<SuiteData>());
    }

    allTests.clear();
    testMapByStatus.clear();
    for (Status s : Status.values()) {
      testMapByStatus.put(s, new ArrayList<TestData>());
    }

    /*
     * Populate the Suite map with all Suites.
     */
    Map<String, SuiteResults> resultsMap = new HashMap<String, SuiteResults>();
    for (SuiteResults result : suiteResults) {
      resultsMap.put(result.getName(), result);
    }
    Map<String, SuiteContents> contentsMap = new HashMap<String, SuiteContents>();
    for (SuiteContents contents : suiteContents) {
      contentsMap.put(contents.getName(), contents);
    }

    for (SuiteContents contents : suiteContents) {
      String name = contents.getName();
      SuiteResults result = resultsMap.get(name);
      boolean ignored = ignoredTestList.isIgnored(name);
      ProcessOutput failureMessages = dataListenerInfo.getFailureMessages().get(name);
      suiteDataMap.put(name, new SuiteData(name, ignored, contents, result, failureMessages));
    }

    /*
     * Map the Suites by status.
     */
    for (SuiteData s : suiteDataMap.values()) {
      getSuites(s.getStatus()).add(s);
    }

    /** Populate the Test map with all Tests, and map by status. */
    for (SuiteData s : suiteDataMap.values()) {
      for (TestData t : s.getTestMap().values()) {
        allTests.add(t);
        getTests(t.getStatus()).add(t);
      }
    }

    if (logStats.hasErrors() || !getSuites(Status.ERROR).isEmpty()) {
      runStatus = Status.ERROR;
    } else if (!getSuites(Status.PENDING).isEmpty()) {
      runStatus = Status.PENDING;
    } else {
      runStatus = Status.OK;
    }
  }
コード例 #4
0
ファイル: MemoryIndex.java プロジェクト: sail-umkc/Examples
 /** Resets the {@link MemoryIndex} to its initial state and recycles all internal buffers. */
 public void reset() {
   fields.clear();
   this.normSimilarity = IndexSearcher.getDefaultSimilarity();
   byteBlockPool.reset(false, false); // no need to 0-fill the buffers
   intBlockPool.reset(true, false); // here must must 0-fill since we use slices
   if (payloadsBytesRefs != null) {
     payloadsBytesRefs.clear();
   }
   this.frozen = false;
 }
コード例 #5
0
  /** Přidá geotaging vzory, ty jsou asynchronně a později */
  public void addPatterns(
      final SortedMap<String, String> pattsSouradnice,
      final SortedMap<String, String> pattsGeocoding) {
    allPatterns.clear();
    if (pattsSouradnice != null) {
      souradnicovePatterns.clear();
      souradnicovePatterns.putAll(pattsSouradnice);
    }
    allPatterns.putAll(souradnicovePatterns);

    if (pattsGeocoding != null) {
      geotaggingPatterns.clear();
      geotaggingPatterns.putAll(pattsGeocoding);
    }
    allPatterns.putAll(geotaggingPatterns);

    keys.clear();
    keys.addAll(allPatterns.keySet());
    vyskladejCheckBox();
  }
コード例 #6
0
 @Override
 public void dispose() {
   super.dispose();
   try {
     getLock().writeLock().lock();
     _sourceChunks.clear();
     _times.clear();
   } finally {
     getLock().writeLock().unlock();
   }
 }
コード例 #7
0
 /**
  * ************************************************************************* * * Stash our results
  * for later interrogation. *
  */
 protected boolean stashForOK() {
   if (getFromFile_) {
     reducedMap_.clear();
     return (true);
   }
   EditableTable.TableModel<RelationDirTableModel.TableRow> ecdtm = est_.getModel();
   List<RelationDirTableModel.TableRow> vals = ecdtm.getValuesFromTable();
   int numVals = vals.size();
   for (int i = 0; i < numVals; i++) {
     RelationDirTableModel.TableRow tr = vals.get(i);
     reducedMap_.put(new FabricLink.AugRelation(tr.relation, false), tr.isDir);
   }
   return (true);
 }
コード例 #8
0
 public void load() throws IOException {
   properties.clear();
   final BufferedReader in =
       new BufferedReader(
           new InputStreamReader(
               new FileInputStream(getPreferencesDir() + "preferences"), "utf-8"));
   int lineNumber = 0;
   ArrayList<Integer> errLines = new ArrayList<Integer>();
   for (String line = in.readLine(); line != null; line = in.readLine(), lineNumber++) {
     final int i = line.indexOf('=');
     if (i == -1 || i == 0) {
       errLines.add(lineNumber);
       continue;
     }
     properties.put(line.substring(0, i), line.substring(i + 1));
   }
   if (!errLines.isEmpty())
     throw new IOException(tr("Malformed config file at lines {0}", errLines));
   updateSystemProperties();
 }
コード例 #9
0
 /** headMap returns map with keys in requested range */
 public void testDescendingHeadMapContents() {
   ConcurrentNavigableMap map = dmap5();
   SortedMap sm = map.headMap(m4);
   assertTrue(sm.containsKey(m1));
   assertTrue(sm.containsKey(m2));
   assertTrue(sm.containsKey(m3));
   assertFalse(sm.containsKey(m4));
   assertFalse(sm.containsKey(m5));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(m1, k);
   k = (Integer) (i.next());
   assertEquals(m2, k);
   k = (Integer) (i.next());
   assertEquals(m3, k);
   assertFalse(i.hasNext());
   sm.clear();
   assertTrue(sm.isEmpty());
   assertEquals(2, map.size());
   assertEquals(m4, map.firstKey());
 }
コード例 #10
0
 /** headMap returns map with keys in requested range */
 public void testHeadMapContents() {
   ConcurrentNavigableMap map = map5();
   SortedMap sm = map.headMap(four);
   assertTrue(sm.containsKey(one));
   assertTrue(sm.containsKey(two));
   assertTrue(sm.containsKey(three));
   assertFalse(sm.containsKey(four));
   assertFalse(sm.containsKey(five));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(one, k);
   k = (Integer) (i.next());
   assertEquals(two, k);
   k = (Integer) (i.next());
   assertEquals(three, k);
   assertFalse(i.hasNext());
   sm.clear();
   assertTrue(sm.isEmpty());
   assertEquals(2, map.size());
   assertEquals(four, map.firstKey());
 }
コード例 #11
0
 /** @param none Removes all cytobandResultset in this CopyNumberResultsContainer object. */
 public void removeAllCytobandResultset() {
   cytobands.clear();
   reporterNames.clear();
 }
コード例 #12
0
ファイル: NoteCollectorWorker.java プロジェクト: mwager/jAM
  /**
   * <b>This is the most important function of the collector pipeline</b> First we detect the pitch
   * of the audioFloatBuffer using YIN or MPM.<br>
   * Then the collector process starts, checking onsets and offsets based on midiKeys and dB,
   * collects<br>
   * and convert these pich vectors to abc-notes based on the bpm, samplerate buffersize and
   * bufferoverlap.<br>
   */
  private void detectPitchAndCollect(float[] audioFloatBuffer, double level) {
    int midiKey;
    String note;

    // TODO
    pitchInHertz = getBestPitch(audioFloatBuffer);

    // ---------- ENTSCHEIDUNG ----------
    // pitchInHertz=mpm_pitch;
    pitch = Pitch.getInstance(PitchUnit.HERTZ, (double) pitchInHertz);
    midiKey =
        (int)
            pitch.getPitch(
                PitchUnit.MIDI_KEY); // PitchConverter.hertzToMidiKey((double)pitchInHertz);

    if (model.plottingSelected()) {
      plotterYIN.setData(yin.getCurrentBuffer());
      plotterYIN.setInfoString("CURRENT PITCH: " + pitchInHertz + "Hz PROB: " + pitch_probability);

      plotterMPM.setData(mpm.getCurrentBuffer());
      plotterMPM.setInfoString("CURRENT PITCH: " + pitchInHertz + "Hz PROB: " + pitch_probability);

      plotterBUFFER.setData(audioFloatBuffer);
      plotterBUFFER.setInfoString("level: " + level);
    }

    // nach dem pitch erkannt wurde muss ggf. entsprechend dem Instrument
    // transponiert werden
    if (model.getTransposeRecIndex() == 1) {
      // Bb Clarinet: 2 halftonesteps up
      pitch.convertPitch(2);
      pitchInHertz = (float) pitch.getPitch(PitchUnit.HERTZ);
      midiKey = PitchConverter.hertzToMidiKey((double) pitchInHertz);
    }

    String[] arr = pitch.getBaseNote(pitchInHertz).split(" ");
    String note2 = arr[0];
    int oktave = Integer.parseInt(arr[1]);
    //
    note = pitch.noteName();
    String str = "";

    // formatted Info output to GUI
    str =
        pitchInHertz == -1
            ? "NO PITCH DETECTED"
            : note
                + " at "
                + String.format("%.5g%n", pitchInHertz)
                + "Hz - IDEAL: "
                + String.format("%.5g%n", pitch.getIdealFreq(note2, oktave))
                + "Hz - PROB: "
                + String.format("%.5g%n", pitch_probability)
                + "%";

    model.firePropertyChange(ControllerEngine.INFO_LABEL_PROPERTY, "", str);

    countMSprocessing += (audioFloatBuffer.length - overlap) / audioSampleRate * 1000.0f;

    float duration = (bufferSize - overlap) / audioSampleRate * 1000.0f;
    // finally:
    //		collect(audioFloatBuffer, midiKey, duration, level, note);

    // ------------------------- begin collector process -------------------------
    // ----- sammel ALLE erkannten Noten fuer statistiken -----
    if (midiKeySammlerInsgesamt.get(midiKey) != null) {
      midiKeySammlerInsgesamt.put(midiKey, midiKeySammlerInsgesamt.get(midiKey) + duration);
    } else {
      midiKeySammlerInsgesamt.put(midiKey, duration);
    }

    // TODO level neuer Ansatz ? zusaetzliche offset/Onset bedingung
    //		levels.add(level);
    //
    //		boolean minima=true;
    //		Vector<double[]>extremwerte = jAMUtils.detectExtremum(levels, delta, minima);
    //
    //		//sysout
    //		if(!model.isEvaluating() && extremwerte.size()==1) {  //kann so immer nur 1 finden
    ////			jAMUtils.printArray(levels);
    //			String str="";
    //			for (int i = 0; i < extremwerte.size(); i++) {
    //				str+= "(" + extremwerte.get(i)[0] + ","+extremwerte.get(i)[1] + "),";
    //			}
    //			System.out.println("============> EXTREM!!!: " + str + " at levels: " + levels);
    //			System.out.println("midiKey: " + midiKey);
    //
    //			levels.clear(); //wenn ein minima entdeckt: offset und dann leeren ?
    //		}
    /**
     * * wenn eine note zb 200ms lang, dann -> 16tel aber die 50 ms muessen beim NŠchsten Mal
     * ignoriert werden wenn dies pausen entspricht !!! sonst kann sein dass zB z(3) gemalt wird
     * obwohl z(2) !!!
     *
     * <p>if(msToIgnore>0 && !ONSET) { //MINIMUM_DURATION dur+=duration; if(dur<msToIgnore) return;
     * else { System.out.println( "============================================>>>>>> IGNORED: " +
     * dur + "ms OF DATA - msToIgnore: " + msToIgnore); dur=0; msToIgnore=0; } }
     */
    boolean silence = jAMUtils.isSilence(audioFloatBuffer, MINIMUM_LEVEL);
    // 1. OFFSET basierend auf neuer note!
    if ((ONSET && midiKey > 0 && !silence /* level > MINIMUM_LEVEL*/)
        && (midiKey != lastTakenMidiKey)) { // es kommt ne andere /Note/
      // System.out.println("POSSIBLE NEW NOTE: "+ midiKey);

      if (newNoteCount == 0) // die erste "andere" Note
      newNoteCount++;
      else if (midiKey == lastDetectedMidiKey) newNoteCount++;

      if (newNoteCount
          > (int)
              (MINIMUM_DURATION
                  / duration)) { // 60/25.01 --> 2 also mind.  3  nehmen! wie  sonst auch
        ONSET =
            false; // dann macht er jetzt unten ne Entscheidung und beim next Mal fŠngt er an die
                   // neue note zu collecten
        NEW_NOTE_ONSET = true; // TODO sinn?

        newNoteCount = 0;

        // sysout
        if (!model.isEvaluating() && jAM.SYSOUT)
          System.out.println(
              timestamp()
                  + " ================================================== OFFSET NEWNOTE: "
                  + midiKey
                  + " could be possible new note");
      }

      // 2. ONSET
    } else if (!ONSET && midiKey > 0 && !silence /*&& level > MINIMUM_LEVEL*/) {
      newNoteCount = 0;

      // gibts diese note schon? und kam sie beim letzten Mal?
      if (midiKeySammler.get(midiKey) != null && midiKey == lastDetectedMidiKey) {
        midiKeySammler.put(midiKey, midiKeySammler.get(midiKey) + duration);
        if (midiKeySammler.get(midiKey) > MINIMUM_DURATION) {
          //
          // sysout
          if (!model.isEvaluating() && jAM.SYSOUT)
            System.out.println(
                timestamp()
                    + " ================================================== ONSET - Entscheidung basiert auf: "
                    + midiKeySammler);

          ONSET = true;

          // wir kšnnen davon ausgehen dass "note" die lastTakenNote
          // wird, da sie alle Bedingungen fuer ein note-OFFSET erfŸllt
          // Problem: es kann sein dass zb 3 buffer A1 kommen, das is
          // ne new note bedingung
          // der naechst kommt dann hier rein und is aber diesmal A3
          // also lastTakenNote="A3" anstatt A1 ???
          lastTakenMidiKey = midiKey;

          midiKeySammler.clear();
        }
      } else {
        midiKeySammler.put(midiKey, duration);
      }

      // 3. OFFSET basierend auf Pause
    } else if (silence
        || midiKey
            == 0 /*|| level < MINIMUM_LEVEL*/) { // sonst ist alles ne Pause: kein pitch und auch
                                                 // level < MIN_LEVEL
      /**
       * gibts diese Pause schon? und kam sie beim letzten Mal? ob sie beim letzten Mal kam is
       * unwichtig es mŸssen die Pausen gezŠhlt werden! BSP: 60,60,60,0,0,0,0,55,0,0,0, --> die 55
       * MUSS mitgezaehlt werden ! ??? stimmt das?
       */
      if (midiKeySammler.get(0) != null && lastDetectedMidiKey == 0) {
        midiKeySammler.put(0, midiKeySammler.get(0) + duration);

        if (midiKeySammler.get(0) > MINIMUM_DURATION) {
          if (ONSET) {
            if (!model.isEvaluating() && jAM.SYSOUT)
              System.out.println(
                  timestamp()
                      + " ================================================== OFFSET - Entscheidung basiert auf: "
                      + midiKeySammler);

            ONSET = false; // jetzt ist wieder vorbei
            NEW_NOTE_ONSET = false;
          }
          midiKeySammler.clear();
        }
      } else {
        midiKeySammler.put(0, duration);
      }
    }

    // ----- wenn nun ONSET==true anfangen zu sammeln bis ONSET==false!
    if (ONSET) {
      if (midiKeysRests.size() > 0
          && !NEW_NOTE_ONSET) { // hier sind nun pausen in der off Phase gezaehlt worden
        detectRest(duration);
      } else { // sonst: sammle noten
        // hier midiKey und level speichern:
        midiKeysAndLevels.add(new Float[] {(float) midiKey, (float) level});
      }
    } else { // wenn ein OFFSET und noten sind vorhanden: entscheidung!
      if (midiKeysAndLevels.size() > 0) {
        detectNote(duration);
      } else
        // sonst sammple pausen
        midiKeysRests.add(midiKey);
    }

    lastDetectedMidiKey = midiKey;

    // TODO fft
    //		fft(audioFloatBuffer);

    // TODO sysout
    if (!model.isEvaluating() && jAM.SYSOUT) {
      if (pitchInHertz == -1)
        System.out.println(
            timestamp()
                + "\t"
                + "--> Rest: "
                + note
                + (note.length() == 2 ? "\t" : "")
                + "\t\t midiKey: "
                + midiKey
                + "\t RMS: "
                + String.format("%.2f", level)
                + "  Zustand: "
                + (ONSET ? "ONSET " : "OFFSET ")
                + (silence ? "SILENCE" : "NO SILENCE"));
      else
        System.out.println(
            timestamp()
                + "\t"
                + "--> Note: "
                + note
                + (note.length() == 2 ? "\t" : "")
                + "\t midiKey: "
                + midiKey
                + "\t RMS: "
                + String.format("%.2f", level)
                + "  Zustand: "
                + (ONSET ? "ONSET " : "OFFSET ")
                + (silence ? "SILENCE" : "NO SILENCE"));
    }
  }
コード例 #13
0
ファイル: CollectionsTest.java プロジェクト: halset/ha-jdbc
  private <K, V> void verify(
      SortedMap<K, V> immutableMap, SortedMap<K, V> mutableMap, K key1, K key2, V value) {
    try {
      immutableMap.clear();

      Assert.assertTrue(mutableMap.isEmpty());
    } catch (UnsupportedOperationException e) {
      Assert.assertFalse(mutableMap.isEmpty());
    }

    Assert.assertEquals(immutableMap.containsKey(key1), mutableMap.containsKey(key1));
    Assert.assertEquals(immutableMap.containsKey(key2), mutableMap.containsKey(key2));

    Assert.assertEquals(immutableMap.containsValue(value), mutableMap.containsValue(value));
    Assert.assertEquals(immutableMap.containsValue(null), mutableMap.containsValue(null));

    Assert.assertEquals(immutableMap.entrySet(), mutableMap.entrySet());

    Assert.assertEquals(immutableMap.get(key1), mutableMap.get(key1));
    Assert.assertEquals(immutableMap.get(key2), mutableMap.get(key2));

    Assert.assertEquals(immutableMap.isEmpty(), mutableMap.isEmpty());

    Assert.assertEquals(immutableMap.keySet(), mutableMap.keySet());

    try {
      immutableMap.put(key1, value);
      Assert.fail();
    } catch (UnsupportedOperationException e) {
    }

    try {
      immutableMap.putAll(java.util.Collections.singletonMap(key1, value));
      Assert.fail();
    } catch (UnsupportedOperationException e) {
    }

    try {
      immutableMap.remove(key1);
    } catch (UnsupportedOperationException e) {
    }

    Assert.assertEquals(immutableMap.size(), mutableMap.size());

    // Is it OK that this fails?
    // Assert.assertEquals(immutableMap.values(), mutableMap.values());
    Assert.assertEquals(immutableMap.values().size(), mutableMap.values().size());
    if (!mutableMap.isEmpty()) {
      Assert.assertEquals(
          immutableMap.values().iterator().next(), mutableMap.values().iterator().next());
    }

    Assert.assertSame(immutableMap.comparator(), mutableMap.comparator());

    if (!mutableMap.isEmpty()) {
      Assert.assertEquals(immutableMap.firstKey(), mutableMap.firstKey());
      Assert.assertEquals(immutableMap.lastKey(), mutableMap.lastKey());
    } else {
      try {
        immutableMap.firstKey();
        Assert.fail();
      } catch (NoSuchElementException e) {
      }

      try {
        immutableMap.lastKey();
        Assert.fail();
      } catch (NoSuchElementException e) {
      }
    }

    Assert.assertEquals(immutableMap.headMap(key1), mutableMap.headMap(key1));
    Assert.assertEquals(immutableMap.headMap(key2), mutableMap.headMap(key2));

    Assert.assertEquals(immutableMap.subMap(key1, key2), mutableMap.subMap(key1, key2));

    Assert.assertEquals(immutableMap.tailMap(key1), mutableMap.tailMap(key1));
    Assert.assertEquals(immutableMap.tailMap(key2), mutableMap.tailMap(key2));
  }
コード例 #14
0
 // TODO: since context stores GameRoom, we do not need to pass Game to method calls.
 // Create Server-side strategy interface.
 @Override
 public void phaseStart() {
   rolls.clear();
 }
コード例 #15
0
 public void clearActions() {
   mActions.clear();
   mPrimaryAction = null;
   updateActions();
 }
コード例 #16
0
ファイル: PCClass.java プロジェクト: grimreaper/pcgen
 /** Clear any data from the class levels. Primarily for use by the Classes LST editor. */
 public void clearClassLevels() {
   levelMap.clear();
 }
コード例 #17
0
 /** Fires event... */
 public void clear() {
   items.clear();
   fireItemsChanged();
 }
コード例 #18
0
ファイル: Entity.java プロジェクト: vintikjeny/cayenne
 public void clearAttributes() {
   attributes.clear();
 }
コード例 #19
0
 /** Clear all variables (constants are not affected). */
 public MathEval clear() {
   variables.clear();
   return this;
 }
コード例 #20
0
 public final void resetToDefault() {
   properties.clear();
 }
コード例 #21
0
 public void clear() {
   checkInit();
   delegate.clear();
 }
コード例 #22
0
 public void clear() throws MaltChainedException {
   terminalPool.checkInAll();
   terminalNodes.clear();
   sentenceID = 0;
   super.clear();
 }
コード例 #23
0
ファイル: Entity.java プロジェクト: vintikjeny/cayenne
 public void clearRelationships() {
   relationships.clear();
 }