summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/google/gerrit/client/reviewdb/Branch.java
blob: 98e72828c0d9110805705b048d111cc9d3dae509 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2008 Google Inc.
//
// 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.client.reviewdb;

import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.IntKey;
import com.google.gwtorm.client.StringKey;

/** Registered line of development within a {@link Project}. */
public final class Branch {
  /** Branch name key */
  public static class NameKey extends StringKey<Project.NameKey> {
    @Column
    protected Project.NameKey projectName;

    @Column
    protected String branchName;

    protected NameKey() {
      projectName = new Project.NameKey();
    }

    public NameKey(final Project.NameKey proj, final String n) {
      projectName = proj;
      branchName = n;
    }

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

    @Override
    protected void set(String newValue) {
      branchName = newValue;
    }

    @Override
    public Project.NameKey getParentKey() {
      return projectName;
    }

    public String getShortName() {
      final String n = get();

      // Git style branches will tend to start with "refs/heads/".
      // 
      if (n.startsWith("refs/heads/")) {
        return n.substring("refs/heads/".length());
      }

      return n;
    }
  }

  /** Synthetic key to link to within the database */
  public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> {
    @Column
    protected int id;

    protected Id() {
    }

    public Id(final int id) {
      this.id = id;
    }

    @Override
    public int get() {
      return id;
    }

    @Override
    protected void set(int newValue) {
      id = newValue;
    }
  }

  @Column(name = Column.NONE)
  protected NameKey name;

  @Column
  protected Id branchId;

  protected Branch() {
  }

  public Branch(final Branch.NameKey newName, final Branch.Id newId) {
    name = newName;
    branchId = newId;
  }

  public Branch.Id getId() {
    return branchId;
  }

  public Branch.NameKey getNameKey() {
    return name;
  }

  public String getName() {
    return name.get();
  }

  public String getShortName() {
    return name.getShortName();
  }
}