Пример #1
0
 public void remove(Track track) {
   synchronized (this) {
     docElt.removeChild(track.getElement());
     tracks.remove(track);
     hash.remove(track.getKey());
   }
 }
Пример #2
0
 /**
  * A nice ol' bubble sort. This is used because it has a passable performance when the list starts
  * off sorted.
  */
 public void sort() {
   synchronized (this) {
     boolean swap;
     do {
       swap = false;
       for (int i = 1; i < tracks.size(); i++) {
         Track lastTrack = (Track) tracks.elementAt(i - 1);
         Track track = (Track) tracks.elementAt(i);
         if (compare(lastTrack, track) > 0) {
           tracks.setElementAt(track, i - 1);
           tracks.setElementAt(lastTrack, i);
           swap = true;
         }
       }
     } while (swap);
   }
 }
Пример #3
0
 public Track add(Track track) {
   synchronized (this) {
     Track copy;
     if ((copy = getTrack(track)) == null) {
       copy = new Track((Element) doc.importNode(track.getElement(), false));
       docElt.appendChild(copy.getElement());
       tracks.add(copy);
       hash.put(copy.getKey(), copy);
     }
     return copy;
   }
 }
Пример #4
0
 public void load(InputStream is) throws IOException, ParserConfigurationException, SAXException {
   doc = db.parse(is);
   docElt = doc.getDocumentElement();
   if (docElt.getTagName().equals(docElementName)) {
     NodeList nl = docElt.getElementsByTagName(trackElementName);
     for (int i = 0; i < nl.getLength(); i++) {
       Element elt = (Element) nl.item(i);
       Track track = new Track(elt);
       tracks.add(track);
       hash.put(track.getKey(), track);
     }
   }
 }
Пример #5
0
 public int getNoOfTracks() {
   return tracks.size();
 }
Пример #6
0
 public void purge() {
   for (int i = tracks.size() - 1; i >= 0; i--) {
     Track track = (Track) tracks.elementAt(i);
     if (track.isHidden()) tracks.remove(i);
   }
 }