CpeMemoryIndex.java

  1. /*
  2.  * This file is part of dependency-check-core.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  * Copyright (c) 2020 Jeremy Long. All Rights Reserved.
  17.  */
  18. package org.owasp.dependencycheck.data.cpe;

  19. import javax.annotation.concurrent.ThreadSafe;

  20. /**
  21.  * <p>
  22.  * An in memory Lucene index that contains the vendor/product combinations from
  23.  * the CPE (application) identifiers within the NVD CVE data.</p>
  24.  *
  25.  * This is the last remaining singleton in dependency-check-core; The use of
  26.  * this singleton - while it may not technically be thread-safe (one database
  27.  * used to build this index may not have the same entries as another) the risk
  28.  * of this is currently believed to be small. As this memory index consumes a
  29.  * large amount of memory we will remain using the singleton pattern for now.
  30.  *
  31.  * @author Jeremy Long
  32.  */
  33. @ThreadSafe
  34. public final class CpeMemoryIndex extends AbstractMemoryIndex {

  35.     /**
  36.      * Singleton instance.
  37.      */
  38.     private static final CpeMemoryIndex INSTANCE = new CpeMemoryIndex();

  39.     /**
  40.      * private constructor for singleton.
  41.      */
  42.     private CpeMemoryIndex() {
  43.     }

  44.     /**
  45.      * Gets the singleton instance of the CpeMemoryIndex.
  46.      *
  47.      * @return the instance of the CpeMemoryIndex
  48.      */
  49.     public static CpeMemoryIndex getInstance() {
  50.         return INSTANCE;
  51.     }

  52.     /**
  53.      * Gets the singleton instance of the CpeMemoryIndex.
  54.      *
  55.      * @return the instance of the CpeMemoryIndex
  56.      */
  57.     @Override
  58.     protected AbstractMemoryIndex instance() {
  59.         return (AbstractMemoryIndex) INSTANCE;
  60.     }
  61. }