// Copyright (C) 2011 The Android Open Source Project
//
// 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.gerrit.reviewdb.client;

import com.google.gwtorm.client.StringKey;

/**
 * Defining a project/branch subscription to a project/branch project.
 *
 * <p>This means a class instance represents a repo/branch subscription to a project/branch (the
 * subscriber).
 *
 * <p>A subscriber operates a submodule in defined path.
 */
public final class SubmoduleSubscription {
  /** Subscription key */
  public static class Key extends StringKey<Branch.NameKey> {
    private static final long serialVersionUID = 1L;

    /**
     * Indicates the super project, aka subscriber: the project owner of the gitlinks to the
     * submodules.
     */
    protected Branch.NameKey superProject;

    protected String submodulePath;

    protected Key() {
      superProject = new Branch.NameKey();
    }

    protected Key(Branch.NameKey superProject, String path) {
      this.superProject = superProject;
      this.submodulePath = path;
    }

    @Override
    public Branch.NameKey getParentKey() {
      return superProject;
    }

    @Override
    public String get() {
      return submodulePath;
    }

    @Override
    protected void set(String newValue) {
      this.submodulePath = newValue;
    }
  }

  protected Key key;

  protected Branch.NameKey submodule;

  protected SubmoduleSubscription() {}

  public SubmoduleSubscription(Branch.NameKey superProject, Branch.NameKey submodule, String path) {
    this.key = new Key(superProject, path);
    this.submodule = submodule;
  }

  public Key getKey() {
    return key;
  }

  public Branch.NameKey getSuperProject() {
    return key.superProject;
  }

  public String getPath() {
    return key.get();
  }

  public Branch.NameKey getSubmodule() {
    return submodule;
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof SubmoduleSubscription) {
      return key.equals(((SubmoduleSubscription) o).key)
          && submodule.equals(((SubmoduleSubscription) o).submodule);
    }
    return false;
  }

  @Override
  public int hashCode() {
    return key.hashCode();
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(getSuperProject()).append(':').append(getPath());
    sb.append(" follows ");
    sb.append(getSubmodule());
    return sb.toString();
  }
}

@@ -657,42 +657,25 @@
 ort 
-com.google.gwtorm.client.StringKey
+java.util.Objects
 ;%0A%0A/
@@ -977,447 +977,182 @@
 %7B%0A  
-/** Subscription key */%0A  public static class Key extends StringKey%3CBranch.NameKey%3E %7B%0A    private static final long serialVersionUID = 1L;%0A%0A    /**%0A     * Indicates the
+protected Branch.NameKey
  super
- p
+P
 roject
-, aka subscriber: the project owner of the gitlinks to the%0A     * submodules.%0A     */%0A    protected Branch.NameKey superProject;%0A%0A    protected String submodulePath;%0A%0A    protected Key() %7B%0A      superProject = new Branch.NameKey();%0A    %7D%0A%0A    protected Key(
+;%0A%0A  protected String submodulePath;%0A%0A  protected Branch.NameKey submodule;%0A%0A  public SubmoduleSubscription(Branch.NameKey superProject, 
 Bran
@@ -1164,26 +1164,23 @@
 meKey su
-perProject
+bmodule
 , String
@@ -1184,26 +1184,24 @@
 ing path) %7B%0A
-  
     this.sup
@@ -1226,18 +1226,16 @@
 roject;%0A
-  
     this
@@ -1248,171 +1248,10 @@
 dule
-Path = path;%0A    %7D%0A%0A    @Override%0A    public Branch.NameKey getParentKey() %7B%0A      return superProject;%0A    %7D%0A%0A    @Override%0A    public String get() %7B%0A      return
+ =
  sub
@@ -1260,452 +1260,165 @@
 dule
-Path
 ;%0A    
-%7D%0A%0A    @Override%0A    protected void set(String newValue) %7B%0A      this.submodulePath = newValue;%0A    %7D%0A  %7D%0A%0A  protected Key key;%0A%0A  protected Branch.NameKey submodule;%0A%0A 
+this.submodulePath = path;%0A  %7D%0A%0A  /**%0A   * Indicates the super
  pro
-tected SubmoduleSubscription() %7B%7D%0A%0A  public SubmoduleSubscription(Branch.NameKey superProject, Branch.NameKey submodule, String path) %7B%0A    this.key = new Key(superProject, path);%0A    this.submodule = submodule;%0A  %7D%0A%0A  public Key getKey() %7B%0A    return key;%0A  %7D%0A
+ject, aka subscriber: the project owner of the gitlinks to the%0A   * submodules.%0A   */
 %0A  p
@@ -1469,20 +1469,16 @@
  return 
-key.
 superPro
@@ -1531,17 +1531,21 @@
 urn 
-key.get()
+submodulePath
 ;%0A  
@@ -1719,57 +1719,108 @@
     
-return key.equals(((SubmoduleSubscription) o).key
+SubmoduleSubscription s = (SubmoduleSubscription) o;%0A      return superProject.equals(s.superProject
 )%0A  
@@ -1839,24 +1839,28 @@
 ubmodule
+Path
 .equals(
 ((Submod
@@ -1855,19 +1855,19 @@
 als(
-((S
+s.s
 ubmodule
 Subs
@@ -1866,24 +1866,45 @@
 dule
-Subscription) o)
+Path)%0A          && submodule.equals(s
 .sub
@@ -1994,21 +1994,59 @@
 urn 
-key.hashCode(
+Objects.hash(superProject, submodulePath, submodule
 );%0A 

Remove SubmoduleSubscription.Key