📄 group.java
字号:
*/
public void setFields(final List c)
{
if (c == null)
{
throw new NullPointerException();
}
fields.clear();
fieldsCached = null;
final Iterator it = c.iterator();
while (it.hasNext())
{
final String field = (String) it.next();
addField(field);
}
}
/**
* Adds a field to the group. The field names must correspond to the column names in the
* report's TableModel.
*
* @param name the field name (null not permitted).
*
* @throws NullPointerException if the name is null
*/
public void addField(final String name)
{
if (name == null)
{
throw new NullPointerException("Group.addField(...): name is null.");
}
fields.add(name);
fieldsCached = null;
}
/**
* Returns the list of fields for this group.
*
* @return a list (unmodifiable) of fields for the group.
*/
public List getFields()
{
if (fieldsCached == null)
{
fieldsCached = (String[]) fields.toArray(new String[fields.size()]);
}
return Collections.unmodifiableList(Arrays.asList(fieldsCached));
}
/**
* Returns the group fields as array.
*
* @return the fields as string array.
*/
public String[] getFieldsArray ()
{
if (fieldsCached == null)
{
fieldsCached = (String[]) fields.toArray(new String[fields.size()]);
}
return fieldsCached;
}
/**
* Clones this Element.
*
* @return a clone of this element.
*
* @throws CloneNotSupportedException should never be thrown.
*/
public Object clone() throws CloneNotSupportedException
{
final Group g = (Group) super.clone();
g.fields = new TreeSet(fields);
g.fieldsCached = fieldsCached;
g.footer = (GroupFooter) footer.clone();
g.header = (GroupHeader) header.clone();
g.styleSheetCollectionHelper = new GroupStyleSheetCollectionHelper(g);
return g;
}
/**
* Compares this group with an other object.
*
* @param o the object which should be compared with this group.
*
* @return true, if the given object is a group with the same name and fields,
* false otherwise
*/
public boolean equals(final Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof Group))
{
return false;
}
final Group group = (Group) o;
if (name != null ? !name.equals(group.name) : group.name != null)
{
return false;
}
return compareTo(group) == 0;
}
/**
* Calculates the hashcode for this group.
*
* @return the hashcode.
*/
public int hashCode()
{
int result;
result = (name != null ? name.hashCode() : 0);
result = 29 * result + (fields != null ? fields.hashCode() : 0);
return result;
}
/**
* Compares two objects (required to be instances of the Group class).
* The group's field lists are compared, order of the fields does not
* matter.
*
* @param o the to be compared object.
*
* @return an integer indicating the relative ordering of the two groups.
*/
public int compareTo(final Object o)
{
final Group g = (Group) o;
/** Remove all element, which are in both lists, they are equal */
if (fields.size() == g.fields.size())
{
// both lists contain the same elements.
if (fields.containsAll(g.fields))
{
return 0;
}
else
{
// groups with the same number of -, but different fields, are not compareable.
throw new IllegalArgumentException("These groups are not comparable, they don't have any "
+ "subgroup relation");
}
}
if (fields.containsAll(g.fields))
{
// c2 contains all elements of c1, so c1 is subgroup of c2
return 1;
}
if (g.fields.containsAll(fields))
{
// c1 contains all elements of c2, so c2 is subgroup of c1
return -1;
}
// not compareable, invalid groups
// return 0;
throw new IllegalArgumentException("These groups are not comparable, they don't have any "
+ "subgroup relation");
}
/**
* Returns a string representation of the group (useful for debugging).
*
* @return A string.
*/
public String toString()
{
final StringBuffer b = new StringBuffer();
b.append("Group={Name='");
b.append(getName());
b.append("', fields=");
b.append(fields);
b.append(", header=");
b.append(header);
b.append(", footer=");
b.append(footer);
b.append("} ");
return b.toString();
}
/**
* Returns the stylesheet collection which is assigned with this group and
* all stylesheets of this group.
*
* @return the stylesheet collection or null, if no collection is assigned.
*/
public StyleSheetCollection getStyleSheetCollection()
{
return styleSheetCollectionHelper.getStyleSheetCollection();
}
/**
* Registers the given StyleSheet collection with this group. If there is already
* another stylesheet collection registered, this method will throw an
* <code>InvalidStyleSheetCollectionException</code>.
*
* @param styleSheetCollection the stylesheet collection that should be registered.
* @throws com.jrefinery.report.targets.style.InvalidStyleSheetCollectionException
* if there is already an other stylesheet registered.
* @throws NullPointerException if the given stylesheet collection is null.
*/
public void registerStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
{
styleSheetCollectionHelper.registerStyleSheetCollection(styleSheetCollection);
}
/**
* Unregisters the given stylesheet collection from this group. If this stylesheet
* collection is not registered with this group, this method will throw an
* <code>InvalidStyleSheetCollectionException</code>
*
* @param styleSheetCollection the stylesheet collection that should be unregistered.
* @throws com.jrefinery.report.targets.style.InvalidStyleSheetCollectionException
* if there is an other stylesheet collection already registered with that element.
* @throws NullPointerException if the given stylesheet collection is null.
*/
public void unregisterStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
{
styleSheetCollectionHelper.unregisterStyleSheetCollection(styleSheetCollection);
}
/**
* Updates the stylesheet collection for this group and all bands of the group.
* This method must be called after the group was cloned, to make sure that
* all stylesheets are registered properly.
* <p>
* If you don't call this function after cloning prepare to be doomed.
* This method will replace all inherited stylesheets with clones from the stylesheet
* collection.
*
* @param sc the stylesheet collection that contains the updated information and
* that should be assigned with that element.
* @throws NullPointerException if the given stylesheet collection is null.
* @throws com.jrefinery.report.targets.style.InvalidStyleSheetCollectionException
* if there is an other stylesheet collection already registered with that element.
*/
public void updateStyleSheetCollection(final StyleSheetCollection sc)
{
footer.updateStyleSheetCollection(sc);
header.updateStyleSheetCollection(sc);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -