From: <jbo...@li...> - 2005-09-01 08:50:41
|
Author: aron.gombas Date: 2005-09-01 04:50:33 -0400 (Thu, 01 Sep 2005) New Revision: 1032 Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/CcProject.java trunk/labs/kosmos/src/java/hu/midori/kosmos/model/Identified.java trunk/labs/kosmos/src/java/hu/midori/kosmos/model/JiraProject.java trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SfRelease.java trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SvnRepository.java Log: Improved "persistent" IDs, fix for KOSMOS-13 bug Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/CcProject.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/model/CcProject.java 2005-09-01 07:54:49 UTC (rev 1031) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/model/CcProject.java 2005-09-01 08:50:33 UTC (rev 1032) @@ -38,8 +38,18 @@ /** URL of the tests-per-category chart image. */ private String testsPerCategoryChartUrl; + + /** + * By design this should be private to avoid instantiation + * without discriminator, but Hessian needs default ctor. + */ + public CcProject() { + super(null); + } public CcProject(String name, String buildLabel, int status, Date timestamp, int modifications, String buildTime, int tests, int errors, int failures, String testsPerCategoryChartUrl) { + super(name + buildLabel + timestamp.getTime()); + this.name = name; this.buildLabel = buildLabel; this.status = status; Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/Identified.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/model/Identified.java 2005-09-01 07:54:49 UTC (rev 1031) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/model/Identified.java 2005-09-01 08:50:33 UTC (rev 1032) @@ -8,25 +8,29 @@ import java.util.Collection; import java.util.Iterator; -import java.util.UUID; /** * Each identifiable entity class should extend this. - * It uses the <code>java.util.UUID</code> to generate unique - * identifiers for each object. + * The identifiable classes must pass a discriminator String to its ctor, + * that will be used to generate the integer ID. * * @author <a href="mailto:aro...@mi...">Aron Gombas</a> * @version $Id$ */ public abstract class Identified { /** Unique identifier. */ - private String id;// TODO this should be "UUID" type, but Hessian can't handle that + private int id; - public Identified() { - this.id = UUID.randomUUID().toString(); + /** + * @param discriminator must be unique and will be used to generate the integer ID. + * @see #getId() + */ + public Identified(String discriminator) { + // TODO if a simple Object.hashCode() doesn't work in practice, try a more intelligent hash (MD5?) from the crypto package + this.id = (discriminator == null) ? 0 : discriminator.hashCode(); } - public String getId() { + public int getId() { return id; } @@ -34,14 +38,25 @@ * Returns the <code>Identified</code> object from a collection * by using a simple linear search, or <code>null</code> if not found. */ - public static Identified findInCollection(Collection<? extends Identified> items, String id) { + public static Identified findInCollection(Collection<? extends Identified> items, int id) { Iterator<? extends Identified> it = items.iterator(); while(it.hasNext()) { Identified item = it.next(); - if(item.getId().equals(id)) + if(item.getId() == id) return item; } return null; } + + /** + * Returns the <code>Identified</code> object from a collection. + * It receives the ID as String, so can be passed from request + * params directly. + * + * @see #findInCollection(Collection, int) + */ + public static Identified findInCollection(Collection<? extends Identified> items, String id) { + return findInCollection(items, Integer.parseInt(id)); + } } Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/JiraProject.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/model/JiraProject.java 2005-09-01 07:54:49 UTC (rev 1031) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/model/JiraProject.java 2005-09-01 08:50:33 UTC (rev 1032) @@ -54,8 +54,18 @@ /** URL of the open-issues-per-assignee chart image. */ private String openIssuesPerAssigneeChartUrl; + /** + * By design this should be private to avoid instantiation + * without discriminator, but Hessian needs default ctor. + */ + public JiraProject() { + super(null); + } + public JiraProject(String name, String url, String key, String projectUrl, String description, String lead, int openIssues, int codingInProgressIssues, int reopenedIssues, int resolvedIssues, int closedIssues, int blockerOpenIssues, int criticalOpenIssues, int majorOpenIssues, int minorOpenIssues, int trivialOpenIssues, int optionalOpenIssues, List<Map.Entry<String,Integer>> issuesPerAssignee, String issuesPerStatusChartUrl, String openIssuesPerPriorityChartUrl, String openIssuesPerAssigneeChartUrl) { - this.name = name; + super(name + url + key + projectUrl); + + this.name = name; this.url = url; this.key = key; this.projectUrl = projectUrl; Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SfRelease.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SfRelease.java 2005-09-01 07:54:49 UTC (rev 1031) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SfRelease.java 2005-09-01 08:50:33 UTC (rev 1032) @@ -26,8 +26,18 @@ /** Release date. */ private Date date; + /** + * By design this should be private to avoid instantiation + * without discriminator, but Hessian needs default ctor. + */ + public SfRelease() { + super(null); + } + public SfRelease(String packageName, String packageUrl, String version, String versionUrl, Date date) { - this.packageName = packageName; + super(packageName + version + date.getTime()); + + this.packageName = packageName; this.packageUrl = packageUrl; this.version = version; this.versionUrl = versionUrl; Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SvnRepository.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SvnRepository.java 2005-09-01 07:54:49 UTC (rev 1031) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/model/SvnRepository.java 2005-09-01 08:50:33 UTC (rev 1032) @@ -62,8 +62,18 @@ /** Commits-per-file sorted by commits in descending order. */ private List<Map.Entry<String,Integer>> commitsPerFile; + /** + * By design this should be private to avoid instantiation + * without discriminator, but Hessian needs default ctor. + */ + public SvnRepository() { + super(null); + } + public SvnRepository(String location, long revision, Date createdDate, Date latestTouchDate, String latestTouchAuthor, String latestTouchMessage, int commitsTotal, int commitsToday, int commitsLast7Days, int commitsLast31Days, String commitsPerAuthorChartUrl, String commitsPerFileChartUrl, String commitsPerWeekChartUrl, String repoEntriesPerWeekChartUrl, int dirs, int files, int totalFileSize, List<Map.Entry<String,Integer>> commitsPerAuthor, List<Map.Entry<String,Integer>> commitsPerFile) { - this.location = location; + super(location + revision + latestTouchDate.getTime()); + + this.location = location; this.revision = revision; this.createdDate = createdDate; |