| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CategoryInfoImpl |
|
| 1.6;1,6 |
| 1 | /******************************************************************************* |
|
| 2 | * Copyright (c) 2005 Gabriel Handford. |
|
| 3 | * All rights reserved. |
|
| 4 | * |
|
| 5 | * Contributors: |
|
| 6 | * Gabriel Handford - |
|
| 7 | *******************************************************************************/ |
|
| 8 | package net.sf.tacos.services.impl; |
|
| 9 | ||
| 10 | import java.util.List; |
|
| 11 | ||
| 12 | import net.sf.tacos.services.CategoryInfo; |
|
| 13 | ||
| 14 | import org.apache.commons.lang.builder.EqualsBuilder; |
|
| 15 | import org.apache.commons.lang.builder.HashCodeBuilder; |
|
| 16 | import org.apache.commons.lang.builder.ToStringBuilder; |
|
| 17 | import org.apache.commons.lang.builder.ToStringStyle; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * This class describes a site map category containing page names. |
|
| 21 | * |
|
| 22 | * @author Gabriel Handford |
|
| 23 | */ |
|
| 24 | public class CategoryInfoImpl implements CategoryInfo { |
|
| 25 | ||
| 26 | private String name; |
|
| 27 | private List pageNames; |
|
| 28 | private String image; |
|
| 29 | private String inactiveImage; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Construct named category with list of pages. |
|
| 33 | * @param name The category name |
|
| 34 | * @param pageNames List of the page names in this category |
|
| 35 | */ |
|
| 36 | 0 | public CategoryInfoImpl(String name, List pageNames) { |
| 37 | 0 | this.name = name; |
| 38 | 0 | this.pageNames = pageNames; |
| 39 | 0 | } |
| 40 | ||
| 41 | /** |
|
| 42 | * Construct named category with list of pages, active and inactive image. |
|
| 43 | * @param name The category name |
|
| 44 | * @param pageNames List of the page names in this category |
|
| 45 | */ |
|
| 46 | public CategoryInfoImpl(String name, List pageNames, |
|
| 47 | 8 | String image, String inactiveImage) { |
| 48 | 8 | this.name = name; |
| 49 | 8 | this.pageNames = pageNames; |
| 50 | 8 | this.image = image; |
| 51 | 8 | this.inactiveImage = inactiveImage; |
| 52 | 8 | } |
| 53 | ||
| 54 | /** |
|
| 55 | * Get category name. |
|
| 56 | * @return name The category name |
|
| 57 | */ |
|
| 58 | public String getName() { |
|
| 59 | 12 | return name; |
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Get the default page. |
|
| 64 | * @return The default page, or the first page, or null. |
|
| 65 | */ |
|
| 66 | public String getDefaultPage() { |
|
| 67 | 9 | if (pageNames.size() > 0) |
| 68 | 9 | return (String)pageNames.get(0); |
| 69 | else |
|
| 70 | 0 | return null; |
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Get list of pages in category. |
|
| 75 | * @return pageNames The page names in this category |
|
| 76 | */ |
|
| 77 | public List getPageNames() { |
|
| 78 | 4 | return pageNames; |
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * Returns active image for category. |
|
| 83 | * @return |
|
| 84 | */ |
|
| 85 | public String getImage() |
|
| 86 | { |
|
| 87 | 1 | return image; |
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * Returns the inactive image for category. |
|
| 92 | * @return |
|
| 93 | */ |
|
| 94 | public String getInactiveImage() |
|
| 95 | { |
|
| 96 | 1 | return inactiveImage; |
| 97 | } |
|
| 98 | ||
| 99 | /** |
|
| 100 | * @see java.lang.Object#toString() |
|
| 101 | */ |
|
| 102 | public String toString() { |
|
| 103 | 0 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE) |
| 104 | .append("name", this.name).append("pageNames", this.pageNames) |
|
| 105 | .toString(); |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * @see java.lang.Object#equals(Object) |
|
| 110 | */ |
|
| 111 | public boolean equals(Object object) { |
|
| 112 | 3 | if (object == this) { |
| 113 | 3 | return true; |
| 114 | } |
|
| 115 | 0 | if (!(object instanceof CategoryInfo)) { |
| 116 | 0 | return false; |
| 117 | } |
|
| 118 | 0 | CategoryInfo rhs = (CategoryInfo) object; |
| 119 | 0 | return new EqualsBuilder().append(this.name, rhs.getName()) |
| 120 | .isEquals(); |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * @see java.lang.Object#hashCode() |
|
| 125 | */ |
|
| 126 | public int hashCode() { |
|
| 127 | 0 | return new HashCodeBuilder(1471056309, 288593091).append(this.name) |
| 128 | .toHashCode(); |
|
| 129 | } |
|
| 130 | } |