aboutsummaryrefslogtreecommitdiff
path: root/generator/src/main/java/com/google/archivepatcher/generator/similarity/SimilarityFinder.java
blob: 37a12570cde4cdd0031d1f495bdd5f837a678698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2016 Google Inc. All rights reserved.
//
// 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 com.google.archivepatcher.generator.similarity;

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

import com.google.archivepatcher.generator.MinimalZipEntry;

/**
 * A class that analyzes an archive to find files similar to a specified file.
 */
public abstract class SimilarityFinder {

  /**
   * The base archive that contains the entries to be searched.
   */
  protected final File baseArchive;

  /**
   * The entries in the base archive that are eligible to be searched.
   */
  protected final Collection<MinimalZipEntry> baseEntries;

  /**
   * Create a new instance to check for similarity of arbitrary files against the specified entries
   * in the specified archive.
   * @param baseArchive the base archive that contains the entries to be scored against
   * @param baseEntries the entries in the base archive that are eligible to be scored against.
   */
  public SimilarityFinder(File baseArchive, Collection<MinimalZipEntry> baseEntries) {
    this.baseArchive = baseArchive;
    this.baseEntries = baseEntries;
  }

  /**
   * Searches for files similar to the specified entry in the specified new archive against all of
   * the available entries in the base archive.
   * @param newArchive the new archive that contains the new entry
   * @param newEntry the new entry to compare against the entries in the base archive
   * @return a {@link List} of {@link MinimalZipEntry} entries (possibly empty but never null) from
   * the base archive that are similar to the new archive; if the list has more than one entry, the
   * entries should be in order from most similar to least similar.
   */
  public abstract List<MinimalZipEntry> findSimilarFiles(File newArchive, MinimalZipEntry newEntry);
}