Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.iplog;
  44. import java.util.ArrayList;
  45. import java.util.Collections;
  46. import java.util.Comparator;
  47. import java.util.Date;
  48. import java.util.HashSet;
  49. import java.util.List;
  50. import java.util.Set;
  51. /** A project committer. */
  52. class Committer {
  53. /** Sorts committers by their name first name, then last name. */
  54. static final Comparator<Committer> COMPARATOR = new Comparator<Committer>() {
  55. public int compare(Committer a, Committer b) {
  56. int cmp = a.firstName.compareTo(b.firstName);
  57. if (cmp == 0)
  58. cmp = a.lastName.compareTo(b.lastName);
  59. return cmp;
  60. }
  61. };
  62. private final String id;
  63. private String firstName;
  64. private String lastName;
  65. private String affiliation;
  66. private boolean hasCommits;
  67. private String comments;
  68. private final Set<String> emailAddresses = new HashSet<String>();
  69. private final List<ActiveRange> active = new ArrayList<ActiveRange>(2);
  70. /**
  71. * @param id
  72. * unique identity of the committer
  73. */
  74. Committer(String id) {
  75. this.id = id;
  76. }
  77. /** @return unique identity of this committer in the foundation database. */
  78. String getID() {
  79. return id;
  80. }
  81. /** @return first name of the committer; their given name. */
  82. String getFirstName() {
  83. return firstName;
  84. }
  85. void setFirstName(String firstName) {
  86. this.firstName = firstName;
  87. }
  88. /** @return last name of the committer; their surname or family name. */
  89. String getLastName() {
  90. return lastName;
  91. }
  92. void setLastName(String lastName) {
  93. this.lastName = lastName;
  94. }
  95. /** @return the organization the committer is affiliated with. */
  96. String getAffiliation() {
  97. return affiliation;
  98. }
  99. void setAffiliation(String affiliation) {
  100. this.affiliation = affiliation;
  101. }
  102. /** @return true if this committer is still an active member of the project. */
  103. boolean isActive() {
  104. if (active.isEmpty())
  105. return false;
  106. ActiveRange last = active.get(active.size() - 1);
  107. return last.end == null;
  108. }
  109. /** @return true if this committer has commits in the project. */
  110. boolean hasCommits() {
  111. return hasCommits;
  112. }
  113. void setHasCommits(boolean hasCommits) {
  114. this.hasCommits = hasCommits;
  115. }
  116. /** @return any additional comments about this committer. */
  117. String getComments() {
  118. return comments;
  119. }
  120. void setComments(String comments) {
  121. this.comments = comments;
  122. }
  123. void addEmailAddress(String email) {
  124. emailAddresses.add(email);
  125. }
  126. void addActiveRange(ActiveRange r) {
  127. active.add(r);
  128. Collections.sort(active, new Comparator<ActiveRange>() {
  129. public int compare(ActiveRange a, ActiveRange b) {
  130. return a.begin.compareTo(b.begin);
  131. }
  132. });
  133. }
  134. /**
  135. * @param when
  136. * @return true if the event occurred while an active committer.
  137. */
  138. boolean inRange(Date when) {
  139. for (ActiveRange ar : active) {
  140. if (ar.contains(when))
  141. return true;
  142. }
  143. return false;
  144. }
  145. @Override
  146. public String toString() {
  147. return "Committer " + getFirstName() + " " + getLastName();
  148. }
  149. /** Date period during which the committer was active. */
  150. static class ActiveRange {
  151. private final Date begin;
  152. private final Date end;
  153. /**
  154. * @param begin
  155. * @param end
  156. */
  157. ActiveRange(Date begin, Date end) {
  158. this.begin = begin;
  159. this.end = end;
  160. }
  161. /**
  162. * @param when
  163. * @return true if {@code when} is within this date span.
  164. */
  165. boolean contains(Date when) {
  166. if (when.compareTo(begin) < 0)
  167. return false;
  168. if (end == null)
  169. return true;
  170. return when.compareTo(end) < 0;
  171. }
  172. }
  173. }