<commit_before>//Copyright 2008 <NAME>
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
package org.metasyntactic.caches.scores;

import org.metasyntactic.NowPlayingModel;
import org.metasyntactic.caches.AbstractCache;
import org.metasyntactic.data.Movie;
import org.metasyntactic.data.Review;
import org.metasyntactic.data.Score;
import org.metasyntactic.threading.ThreadingUtilities;

import android.sax.RootElement;

import java.io.File;
import java.util.Collections;
import java.util.List;

public class ScoreCache extends AbstractCache {
  private final ScoreProvider rottenTomatoesScoreProvider;
  private final ScoreProvider metacriticScoreProvider;
  private final ScoreProvider googleScoreProvider;
  private final ScoreProvider noneScoreProvider;

  public ScoreCache(final NowPlayingModel model) {
    super(model);
    this.rottenTomatoesScoreProvider = new RottenTomatoesScoreProvider(model);
    this.metacriticScoreProvider = new MetacriticScoreProvider(model);
    this.googleScoreProvider = new GoogleScoreProvider(model);
    this.noneScoreProvider = new NoneScoreProvider(model);
  }

  private ScoreProvider[] getProviders() {
    return new ScoreProvider[] {
        this.rottenTomatoesScoreProvider,
        this.metacriticScoreProvider,
        this.googleScoreProvider,
        this.noneScoreProvider
    };
  }

  public void shutdown() {
    for (final ScoreProvider provider : getProviders()) {
      provider.shutdown();
    }
  }

  public void createDirectories() {
    for (final ScoreProvider provider : getProviders()) {
      provider.createDirectory();
    }
  }

  private ScoreProvider getCurrentScoreProvider() {
    if (this.model.getScoreType().equals(ScoreType.Google)) {
      return this.googleScoreProvider;
    } else if (this.model.getScoreType().equals(ScoreType.Metacritic)) {
      return this.metacriticScoreProvider;
    } else if (this.model.getScoreType().equals(ScoreType.RottenTomatoes)) {
      return this.rottenTomatoesScoreProvider;
    } else if (this.model.getScoreType().equals(ScoreType.None)) {
      return this.noneScoreProvider;
    } else {
      throw new RuntimeException();
    }
  }

  public Score getScore(final List<Movie> movies, final Movie movie) {
    return getCurrentScoreProvider().getScore(movies, movie);
  }

  public void update() {
    final Runnable runnable = new Runnable() {
      public void run() {
        for (final ScoreProvider provider : getProviders()) {
          provider.update();
        }
      }
    };

    ThreadingUtilities.performOnBackgroundThread("Update score providers", runnable, this.lock, true);
  }

  public List<Review> getReviews(final List<Movie> movies, final Movie movie) {
    if (this.model.getScoreType().equals(ScoreType.Google)) {
      return this.googleScoreProvider.getReviews(movies, movie);
    } else if (this.model.getScoreType().equals(ScoreType.Metacritic)) {
      return this.metacriticScoreProvider.getReviews(movies, movie);
    } else if (this.model.getScoreType().equals(ScoreType.RottenTomatoes)) {
      return this.metacriticScoreProvider.getReviews(movies, movie);
    } else if (this.model.getScoreType().equals(ScoreType.None)) {
      return this.noneScoreProvider.getReviews(movies, movie);
    } else {
      throw new RuntimeException();
    }
  }

  public void prioritizeMovie(final List<Movie> movies, final Movie movie) {
    for (final ScoreProvider provider : getProviders()) {
      provider.prioritizeMovie(movies, movie);
    }
  }

  public void clearStaleData() {
    for (final ScoreProvider provider : getProviders()) {
      provider.clearStaleData();
    }
  }

  @Override
  protected List<File> getCacheDirectories() {
    return Collections.emptyList();
  }
}<commit_msg>start with primary provider<commit_after>//Copyright 2008 <NAME>
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
package org.metasyntactic.caches.scores;

import org.metasyntactic.NowPlayingModel;
import org.metasyntactic.caches.AbstractCache;
import org.metasyntactic.data.Movie;
import org.metasyntactic.data.Review;
import org.metasyntactic.data.Score;
import org.metasyntactic.threading.ThreadingUtilities;

import android.sax.RootElement;

import java.io.File;
import java.util.Collections;
import java.util.List;

public class ScoreCache extends AbstractCache {
  private final ScoreProvider rottenTomatoesScoreProvider;
  private final ScoreProvider metacriticScoreProvider;
  private final ScoreProvider googleScoreProvider;
  private final ScoreProvider noneScoreProvider;

  public ScoreCache(final NowPlayingModel model) {
    super(model);
    this.rottenTomatoesScoreProvider = new RottenTomatoesScoreProvider(model);
    this.metacriticScoreProvider = new MetacriticScoreProvider(model);
    this.googleScoreProvider = new GoogleScoreProvider(model);
    this.noneScoreProvider = new NoneScoreProvider(model);
  }

  private ScoreProvider[] getProviders() {
    return new ScoreProvider[] {
        this.rottenTomatoesScoreProvider,
        this.metacriticScoreProvider,
        this.googleScoreProvider,
        this.noneScoreProvider
    };
  }

  public void shutdown() {
    for (final ScoreProvider provider : getProviders()) {
      provider.shutdown();
    }
  }

  public void createDirectories() {
    for (final ScoreProvider provider : getProviders()) {
      provider.createDirectory();
    }
  }

  private ScoreProvider getScoreProvider(final ScoreType type) {
    if (type.equals(ScoreType.Google)) {
      return this.googleScoreProvider;
    } else if (type.equals(ScoreType.Metacritic)) {
      return this.metacriticScoreProvider;
    } else if (type.equals(ScoreType.RottenTomatoes)) {
      return this.rottenTomatoesScoreProvider;
    } else if (type.equals(ScoreType.None)) {
      return this.noneScoreProvider;
    } else {
      throw new RuntimeException();
    }
  }

  private ScoreProvider getCurrentScoreProvider() {
    return getScoreProvider(this.model.getScoreType());
  }

  public Score getScore(final List<Movie> movies, final Movie movie) {
    return getCurrentScoreProvider().getScore(movies, movie);
  }

  public void update() {
    final ScoreType scoreType = this.model.getScoreType();
    final Runnable runnable = new Runnable() {
      public void run() {
        final ScoreProvider primaryScoreProvider = getScoreProvider(scoreType);
        primaryScoreProvider.update();

        for (final ScoreProvider provider : getProviders()) {
          if (provider != primaryScoreProvider) {
            provider.update();
          }
        }
      }
    };

    ThreadingUtilities.performOnBackgroundThread("Update score providers", runnable, this.lock, true);
  }

  public List<Review> getReviews(final List<Movie> movies, final Movie movie) {
    return getScoreProvider(this.model.getScoreType()).getReviews(movies, movie);
  }

  public void prioritizeMovie(final List<Movie> movies, final Movie movie) {
    for (final ScoreProvider provider : getProviders()) {
      provider.prioritizeMovie(movies, movie);
    }
  }

  public void clearStaleData() {
    for (final ScoreProvider provider : getProviders()) {
      provider.clearStaleData();
    }
  }

  @Override
  protected List<File> getCacheDirectories() {
    return Collections.emptyList();
  }
}
{'fraction_non_alphanumeric': 0.09543970001209628, 'fraction_numerical': 0.0019354058304100641, 'mean_word_length': 3.939068100358423, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5326591', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2273, 'n_words': 586}