<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.util.annotation;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;

import com.google.common.collect.ImmutableList;
import com.opengamma.util.ArgumentChecker;

/**
 * Caches a set of annotated classes. The cache can be written to disk, and reloaded to survive a JVM restart.
 */
public final class AnnotationCache {

  private static final Logger s_logger = LoggerFactory.getLogger(AnnotationCache.class);

  /**
   * The cache path property name
   */
  public static final String CACHE_PATH_PROPERTY = "opengamma.annotationCachePath";

  private final Instant _timestamp;
  private final Collection<String> _classNames = new LinkedList<String>();
  private final Class<? extends Annotation> _annotationClass; 
  private final String _cacheFileName;

  private AnnotationCache(final Instant timestamp, Class<? extends Annotation> annotationClass) {
    _timestamp = timestamp;
    _annotationClass = annotationClass;
    _cacheFileName = "." + annotationClass.getSimpleName();
    
  }

  private void add(final String className) {
    _classNames.add(className);
  }

  private void addAll(final Collection<String> classNames) {
    _classNames.addAll(classNames);
  }

  /**
   * Returns the last modification timestamp.
   * 
   * @return the timestamp, not null
   */
  public Instant getTimestamp() {
    return _timestamp;
  }
 
  /**
   * Gets the classNames.
   * @return the classNames
   */
  public Collection<String> getClassNames() {
    return ImmutableList.copyOf(_classNames);
  }

  /**
   * Gets the annotationClass.
   * @return the annotationClass
   */
  public Class<? extends Annotation> getAnnotationClass() {
    return _annotationClass;
  }

  /**
   * Gets the cacheFileName.
   * @return the cacheFileName
   */
  public String getCacheFileName() {
    return _cacheFileName;
  }

  /**
   * Returns the classes from the cache that contain function annotations.
   * 
   * @return the classes
   * @throws ClassNotFoundException if entries in the cache are invalid
   */
  public Collection<Class<?>> getClasses() {
    if (getClassNames().isEmpty()) {
      return Collections.emptyList();
    }
    final Collection<Class<?>> classes = new ArrayList<Class<?>>(getClassNames().size());
    for (String className : getClassNames()) {
      try {
        classes.add(Class.forName(className));
      } catch (ClassNotFoundException e) {
        s_logger.info("Class not found", e);
      }
    }
    return classes;
  }<commit_msg>Checkstyle<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.util.annotation;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;

import com.google.common.collect.ImmutableList;
import com.opengamma.util.ArgumentChecker;

/**
 * Caches a set of annotated classes. The cache can be written to disk, and reloaded to survive a JVM restart.
 */
public final class AnnotationCache {

  private static final Logger s_logger = LoggerFactory.getLogger(AnnotationCache.class);

  /**
   * The cache path property name
   */
  public static final String CACHE_PATH_PROPERTY = "opengamma.annotationCachePath";

  private final Instant _timestamp;
  private final Collection<String> _classNames = new LinkedList<String>();
  private final Class<? extends Annotation> _annotationClass; 
  private final String _cacheFileName;

  private AnnotationCache(final Instant timestamp, Class<? extends Annotation> annotationClass) {
    _timestamp = timestamp;
    _annotationClass = annotationClass;
    _cacheFileName = "." + annotationClass.getSimpleName();
    
  }

  private void add(final String className) {
    _classNames.add(className);
  }

  private void addAll(final Collection<String> classNames) {
    _classNames.addAll(classNames);
  }

  /**
   * Returns the last modification timestamp.
   * 
   * @return the timestamp, not null
   */
  public Instant getTimestamp() {
    return _timestamp;
  }
 
  /**
   * Gets the classNames.
   * @return the classNames
   */
  public Collection<String> getClassNames() {
    return ImmutableList.copyOf(_classNames);
  }

  /**
   * Gets the annotationClass.
   * @return the annotationClass
   */
  public Class<? extends Annotation> getAnnotationClass() {
    return _annotationClass;
  }

  /**
   * Gets the cacheFileName.
   * @return the cacheFileName
   */
  public String getCacheFileName() {
    return _cacheFileName;
  }

  /**
   * Returns the classes from the cache that contain function annotations.
   * 
   * @return the classes
   */
  public Collection<Class<?>> getClasses() {
    if (getClassNames().isEmpty()) {
      return Collections.emptyList();
    }
    final Collection<Class<?>> classes = new ArrayList<Class<?>>(getClassNames().size());
    for (String className : getClassNames()) {
      try {
        classes.add(Class.forName(className));
      } catch (ClassNotFoundException e) {
        s_logger.info("Class not found", e);
      }
    }
    return classes;
  }
{'fraction_non_alphanumeric': 0.10103057948977869, 'fraction_numerical': 0.0020273694880892043, 'mean_word_length': 3.713375796178344, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4558857', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1647, 'n_words': 469}