@Override
    public Void doInBackground() {

      setProgress(0);

      MetaData metaData;
      final Loader loader = new Loader();
      final File file = loader.load();

      final Collection<File> files =
          FileUtils.listFiles(
              file, new RegexFileFilter("^(.*.mp3)"), DirectoryFileFilter.DIRECTORY);
      final List<Song> songList = new ArrayList<Song>();
      int onePercent = files.size() / 100;
      if (onePercent == 0) {
        onePercent = 1;
      }
      int progressSoFar = 0;
      for (final File singleFile : files) {
        metaData = new MetaData(singleFile);
        songList.add(new Song(metaData, singleFile));

        progress++;
        if (progress % onePercent == 0) {
          setProgress(Math.min(++progressSoFar, 99));
        }
      }

      songLibrary = new SongLibrary(songList);
      setProgress(100);
      pcs.firePropertyChange("libraryLoaded", 0, songLibrary);
      return null;
    }
Beispiel #2
0
  @Override
  public List load(EntityInfo... entityInfos) {
    // no need to timeouManage here, the underlying loader is the real time consumer
    List results = new ArrayList(entityInfos.length);
    if (entityInfos.length == 0) {
      return results;
    }

    if (projectionEnabledOnThis(entityInfos[0])) {
      Loader objectLoader = getObjectLoader();
      objectLoader.load(entityInfos); // load by batch
      for (EntityInfo entityInfo : entityInfos) {
        final Object entityInstance = objectLoader.loadWithoutTiming(entityInfo);
        entityInfo.populateWithEntityInstance(entityInstance);
      }
    }
    for (EntityInfo entityInfo : entityInfos) {
      if (transformer != null) {
        results.add(transformer.transformTuple(entityInfo.getProjection(), aliases));
      } else {
        results.add(entityInfo.getProjection());
      }
    }

    return results;
  }
Beispiel #3
0
 @Test
 public void testEmptyZip() throws Exception {
   exception.expect(IllegalArgumentException.class);
   URL badURL = Resources.getResource(LoaderTests.class, EMPTY_ZIP);
   String badURI = URLDecoder.decode(badURL.getPath(), "UTF-8");
   Loader.load(Paths.get(badURI));
 }
Beispiel #4
0
  public BranchGroup createSceneGraph(URL url) {

    try {
      Loader loader = new com.sun.j3d.loaders.objectfile.ObjectFile();
      Scene scene = loader.load(url);
      BranchGroup bg = scene.getSceneGroup();
      System.out.println(bg);
      TransformGroup[] views = scene.getViewGroups();
      if (views != null) {
        for (int i = 0; i < views.length; i++) {
          System.out.print(views[i]);
        }
        if (views.length > 0) viewStart = views[0];
      }
      return bg;
    } catch (Exception ex) {
      // in case there was a problem, print the stack out
      ex.printStackTrace();
      // System.out.println(ex);
      add("South", new Label(ex.toString()));
      System.out.println("URL: " + url);
      BranchGroup bg = new BranchGroup();
      bg.addChild(new ColorCube());
      System.out.println(bg);
      return bg;
    }
  }
Beispiel #5
0
 @Override
 public Object load(EntityInfo entityInfo) {
   // no need to timeouManage here, the underlying loader is the real time consumer
   if (projectionEnabledOnThis(entityInfo)) {
     Loader objectLoader = getObjectLoader();
     final Object entityInstance = objectLoader.load(entityInfo);
     entityInfo.populateWithEntityInstance(entityInstance);
   }
   if (transformer != null) {
     return transformer.transformTuple(entityInfo.getProjection(), aliases);
   } else {
     return entityInfo.getProjection();
   }
 }
 @Override
 public RecordProxy<KEY, RECORD, ADDITIONAL> getOrLoad(KEY key, ADDITIONAL additionalData) {
   RecordProxy<KEY, RECORD, ADDITIONAL> result = recordChanges.get(key);
   if (result == null) {
     result =
         new RecordChange<>(
             recordChanges,
             changeCounter,
             key,
             loader.load(key, additionalData),
             loader,
             manageBeforeState,
             false,
             additionalData);
   }
   return result;
 }
  private void doLoad(
      final int index,
      final Runnable onSuccess,
      final ICallback<Pair<String, Throwable>> onFailure) {
    // Base case: if there are no more page objects to load, we're done
    if (index >= pageObjects.length) {
      onSuccess.run();
      return;
    }

    Class<?> pageObjectCls = pageObjects[index];

    // If the session already contains the needed object, then there is
    // nothing to do for this object, and we should continue on the
    // next object (if any).
    if (session.get(pageObjectCls) != null) {
      doLoad(index + 1, onSuccess, onFailure);
      return;
    }

    // Get a Loader for the object
    Loader loader = loaderMap.get(pageObjectCls);
    if (loader == null) {
      onFailure.call(new Pair<String, Throwable>("No Loader for " + pageObjectCls.getName(), null));
      return;
    }

    // Continuation if the current page object is loaded successfully:
    // attempts to load the next page object (if any)
    Runnable successContinuation =
        new Runnable() {
          @Override
          public void run() {
            doLoad(index + 1, onSuccess, onFailure);
          }
        };

    // Use Loader to load current page object and, if successful, continue recursively
    loader.load(successContinuation, onFailure);
  }
Beispiel #8
0
  public V get(K key) {
    CacheEntry<K, V> cachedEntry = map.get(key);
    if (cachedEntry != null) {
      lruQueue.purgeEmptyNodes();
      return cachedEntry.value;
    }

    // race condition but negligible (no side effect due to putIfAbsent)
    V loadedValue = source.load(key);
    CacheEntry<K, V> entry = new CacheEntry<K, V>(key, loadedValue, null);
    CacheEntry<K, V> existingValue = map.putIfAbsent(key, entry);

    if (existingValue == null) {
      if (evictionThresholdIsExceeded()) {
        evictLruEntry();
      }
      lruQueue.offer(key);
      return loadedValue;
    } else {
      return existingValue.value;
    }
  }
 static {
   Loader.load();
 }
Beispiel #10
0
 public static void main(String[] args) throws Exception {
   URL emptyURL = Resources.getResource(LoaderTests.class, BAD_FOLDER);
   Loader.load(Paths.get(emptyURL.getPath()));
 }
Beispiel #11
0
 @Test
 public void testBadPath() throws Exception {
   exception.expect(IllegalArgumentException.class);
   Loader.load(Paths.get(BAD_PATH));
 }
Beispiel #12
0
 @Test
 public void testNullPath() throws Exception {
   exception.expect(NullPointerException.class);
   Loader.load(null);
 }