/** * Sets the fields for this group. The given list must contain Strings defining the needed fields from the DataRow. * Don't reference Function-Fields here, functions are not supported in th groupfield definition. * * @param c * the list containing strings. * @throws NullPointerException * if the given list is null or the list contains null-values. */ public void setFields( final List<String> c ) { if ( c == null ) { throw new NullPointerException(); } final String[] fields = c.toArray( new String[c.size()] ); setFieldsArray( fields ); }
/** * 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." ); } final ArrayList<String> fieldsList = new ArrayList<String>( getFields() ); fieldsList.add( name ); Collections.sort( fieldsList ); setFieldsArray( fieldsList.toArray( new String[fieldsList.size()] ) ); }
@Test( expected = NullPointerException.class ) public void testSetFieldsArrayException() { group.setFieldsArray( null ); }
@Test public void testSetFieldsArray() { String[] fields = new String[] { "test_field" }; group.setFieldsArray( fields ); assertThat( (String[]) group.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.GROUP_FIELDS ), is( equalTo( new String[] { "test_field" } ) ) ); }