/*
 * Copyright 2000-2014 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.vcs.log.graph;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class GraphCommitImpl<CommitId> implements GraphCommit<CommitId> {

  @NotNull private final CommitId myId;
  @NotNull private final List<CommitId> myParents;
  private final long myTimestamp;

  public GraphCommitImpl(@NotNull CommitId id, @NotNull List<CommitId> parents, long timestamp) {
    myId = id;
    myParents = parents;
    myTimestamp = timestamp;
  }

  @NotNull
  @Override
  public CommitId getId() {
    return myId;
  }

  @NotNull
  @Override
  public List<CommitId> getParents() {
    return myParents;
  }

  @Override
  public long getTimestamp() {
    return myTimestamp;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || !(o instanceof GraphCommit)) return false;
    GraphCommit commit = (GraphCommit)o;
    return myId.equals(commit.getId());
  }

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

@@ -631,16 +631,103 @@
 graph;%0A%0A
+import com.intellij.util.ArrayUtil;%0Aimport com.intellij.util.containers.ImmutableList;%0A
 import o
@@ -823,16 +823,48 @@
 ommitId%3E
+ extends ImmutableList%3CCommitId%3E
  impleme
@@ -888,17 +888,16 @@
 ommitId%3E
- 
 %7B%0A%0A  @No
@@ -956,30 +956,22 @@
 e final 
-List%3CCommitId%3E
+Object
  myParen
@@ -1126,33 +1126,8 @@
 id;%0A
-    myParents = parents;%0A
     
@@ -1157,166 +1157,970 @@
 ;%0A  
-%7D%0A%0A  @NotNull%0A  @Override%0A  public CommitId getId() %7B%0A    return myId;%0A  %7D%0A%0A  @NotNull%0A  @Override%0A  public List%3CCommitId%3E getParents() %7B%0A    return myParents
+  if (parents.isEmpty()) %7B%0A      myParents = ArrayUtil.EMPTY_OBJECT_ARRAY;%0A    %7D else if (parents.size() == 1) %7B%0A      myParents = parents.get(0);%0A      assert !(myParents instanceof Object%5B%5D);%0A    %7D else %7B%0A      myParents = parents.toArray();%0A    %7D%0A  %7D%0A%0A  @NotNull%0A  @Override%0A  public CommitId getId() %7B%0A    return myId;%0A  %7D%0A%0A  @NotNull%0A  @Override%0A  public List%3CCommitId%3E getParents() %7B%0A    return this;%0A  %7D%0A%0A  @SuppressWarnings(%22unchecked%22)%0A  @Override%0A  public CommitId get(int index) %7B%0A    if (myParents instanceof Object%5B%5D) %7B%0A      Object%5B%5D array = (Object%5B%5D)myParents;%0A      if (index %3C 0 %7C%7C index %3E= array.length) %7B%0A        throw new ArrayIndexOutOfBoundsException(index);%0A      %7D%0A      return (CommitId)array%5Bindex%5D;%0A    %7D%0A    if (index != 0) %7B%0A      throw new ArrayIndexOutOfBoundsException(index);%0A    %7D%0A    return (CommitId)myParents;%0A  %7D%0A%0A  @Override%0A  public int size() %7B%0A    return myParents instanceof Object%5B%5D ? ((Object%5B%5D)myParents).length : 1
 ;%0A  

use less memory for storing parent commits in GraphCommitImpl