/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * 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.intellij.openapi.vcs;

import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author yole
 */
public class VcsDirectoryMapping {
  public static final String PROJECT_CONSTANT = "<Project>";
  public static final VcsDirectoryMapping[] EMPTY_ARRAY = new VcsDirectoryMapping[0];

  @NotNull private final String myDirectory;
  private String myVcs;
  private VcsRootSettings myRootSettings;

  public VcsDirectoryMapping(@NotNull final String directory, final String vcs) {
    this(directory, vcs, null);
  }

  public VcsDirectoryMapping(@NotNull String directory, @Nullable String vcs, @Nullable VcsRootSettings rootSettings) {
    myDirectory = directory;
    myVcs = vcs;
    myRootSettings = rootSettings;
  }

  @NotNull
  public String getDirectory() {
    return myDirectory;
  }

  @NotNull
  public String systemIndependentPath() {
    return FileUtil.toSystemIndependentName(myDirectory);
  }

  public String getVcs() {
    return myVcs;
  }

  public void setVcs(final String vcs) {
    myVcs = vcs;
  }

  /**
   * Returns the VCS-specific settings for the given mapping.
   *
   * @return VCS-specific settings, or null if none have been defined.
   * @see AbstractVcs#getRootConfigurable(VcsDirectoryMapping)
   */
  @Nullable
  public VcsRootSettings getRootSettings() {
    return myRootSettings;
  }

  /**
   * Sets the VCS-specific settings for the given mapping.
   *
   * @param rootSettings the VCS-specific settings.
   */
  public void setRootSettings(final VcsRootSettings rootSettings) {
    myRootSettings = rootSettings;
  }

  public boolean isDefaultMapping() {
    return myDirectory.length() == 0;
  }

  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final VcsDirectoryMapping mapping = (VcsDirectoryMapping)o;

    if (!myDirectory.equals(mapping.myDirectory)) return false;
    if (myVcs != null ? !myVcs.equals(mapping.myVcs) : mapping.myVcs != null) return false;
    if (myRootSettings != null ? !myRootSettings.equals(mapping.myRootSettings) : mapping.myRootSettings != null) return false;

    return true;
  }

  public int hashCode() {
    int result;
    result = myDirectory.hashCode();
    result = 31 * result + (myVcs != null ? myVcs.hashCode() : 0);
    return result;
  }

  @Override
  public String toString() {
    return isDefaultMapping() ? PROJECT_CONSTANT : myDirectory;
  }
}
@@ -762,16 +762,43 @@
 lable;%0A%0A
+import java.util.Objects;%0A%0A
 /**%0A * @
@@ -2633,29 +2633,15 @@
 if (
-myVcs != null ? !myVc
+!Object
 s.eq
@@ -2649,24 +2649,14 @@
 als(
-mapping.
 myVcs
-) :
+,
  map
@@ -2665,24 +2665,17 @@
 ng.myVcs
- != null
+)
 ) return
@@ -2694,47 +2694,15 @@
 if (
-myRootSettings != null ? !myRootSetting
+!Object
 s.eq
@@ -2706,24 +2706,16 @@
 .equals(
-mapping.
 myRootSe
@@ -2720,19 +2720,17 @@
 Settings
-) :
+,
  mapping
@@ -2744,24 +2744,17 @@
 Settings
- != null
+)
 ) return

use Objects.equals