Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fgiust committed Aug 12, 2014
1 parent b5768fc commit c045f1a
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public final String finishRow()
StringBuffer buffer = new StringBuffer(1000);

// Grand totals...
if (getViewIndex() == ((List) getDecoratedObject()).size() - 1)
if (getViewIndex() == ((List<Object>) getDecoratedObject()).size() - 1)
{
if (groupPropertyName != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class ExportViewFactory
/**
* Map containing MediaTypeEnum - View class.
*/
private final Map<MediaTypeEnum, Class> viewClasses = new HashMap<MediaTypeEnum, Class>();
private final Map<MediaTypeEnum, Class<ExportView>> viewClasses = new HashMap<MediaTypeEnum, Class<ExportView>>();

/**
* Private constructor.
Expand Down Expand Up @@ -89,10 +89,10 @@ public static synchronized ExportViewFactory getInstance()
*/
public void registerExportView(String name, String viewClassName)
{
Class exportClass;
Class<ExportView> exportClass;
try
{
exportClass = ReflectHelper.classForName(viewClassName);
exportClass = (Class<ExportView>) ReflectHelper.classForName(viewClassName);
}
catch (ClassNotFoundException e)
{
Expand All @@ -103,7 +103,8 @@ public void registerExportView(String name, String viewClassName)
catch (NoClassDefFoundError e)
{
log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
, new Object[]{name, viewClassName, e.getMessage()}));
,
new Object[]{name, viewClassName, e.getMessage()}));
return;
}

Expand All @@ -126,7 +127,8 @@ public void registerExportView(String name, String viewClassName)
catch (NoClassDefFoundError e)
{
log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
, new Object[]{name, viewClassName, e.getMessage()}));
,
new Object[]{name, viewClassName, e.getMessage()}));
return;
}

Expand Down Expand Up @@ -154,11 +156,11 @@ public ExportView getView(MediaTypeEnum exportType, TableModel tableModel, boole
{
ExportView view;

Class viewClass = viewClasses.get(exportType);
Class<ExportView> viewClass = viewClasses.get(exportType);

try
{
view = (ExportView) viewClass.newInstance();
view = viewClass.newInstance();
}
catch (InstantiationException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public ExcelHssfView()
{
}


/**
* @see org.displaytag.export.ExportView#setParameters(TableModel, boolean, boolean, boolean)
*/
Expand Down Expand Up @@ -126,13 +125,13 @@ public void doExport(OutputStream out) throws JspException
// Create an header row
HSSFRow xlsRow = sheet.createRow(rowNum++);

Iterator iterator = this.model.getHeaderCellList().iterator();
Iterator<HeaderCell> iterator = this.model.getHeaderCellList().iterator();

while (iterator.hasNext())
{
HeaderCell headerCell = (HeaderCell) iterator.next();
HeaderCell headerCell = iterator.next();

HSSFCell cell = xlsRow.createCell( colNum++);
HSSFCell cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(getHeaderCellValue(headerCell)));
cell.setCellStyle(createHeaderStyle(getWb(), headerCell));
}
Expand Down Expand Up @@ -176,16 +175,15 @@ public void doExport(OutputStream out) throws JspException
}

/**
* Uses POI Autosizing.
*
* WARNING. This has been known to cause performance problems and various exceptions. use at your own risk! Overriding this method is suggested.
*
* From POI HSSF documentation for autoSizeColumn:
* "To calculate column width HSSFSheet.autoSizeColumn uses Java2D classes that throw exception if graphical environment is not available.
* In case if graphical environment is not available, you must tell Java that you are running in headless mode and set the following system property: java.awt.headless=true."
* Uses POI Autosizing. WARNING. This has been known to cause performance problems and various exceptions. use at
* your own risk! Overriding this method is suggested. From POI HSSF documentation for autoSizeColumn: "To calculate
* column width HSSFSheet.autoSizeColumn uses Java2D classes that throw exception if graphical environment is not
* available. In case if graphical environment is not available, you must tell Java that you are running in headless
* mode and set the following system property: java.awt.headless=true."
*/
protected void autosizeColumns() {
for (int i=0; i < getModel().getNumberOfColumns(); i++)
protected void autosizeColumns()
{
for (int i = 0; i < getModel().getNumberOfColumns(); i++)
{
getSheet().autoSizeColumn((short) i);
// since this usually creates column widths that are just too short, adjust here!
Expand All @@ -197,13 +195,14 @@ protected void autosizeColumns() {
}

/**
* Write the value to the cell. Override this method if you have complex data types that may need to be exported.
* Write the value to the cell. Override this method if you have complex data types that may need to be exported.
* @param value the value of the cell
* @param cell the cell to write it to
*/
protected void writeCell(Object value, HSSFCell cell)
{
if (value == null) {
if (value == null)
{
cell.setCellValue(new HSSFRichTextString(""));
}
else if (value instanceof Integer)
Expand Down Expand Up @@ -242,7 +241,6 @@ else if (value instanceof Calendar)
}
}


/**
* Templated method that is called for all non-header & non-total cells.
* @param wb
Expand Down Expand Up @@ -324,14 +322,16 @@ public String getSheetName()

public void setSheetName(String sheetName) throws JspException
{
// this is due to either the POI limitations or excel (I'm not sure). you get the following error if you don't do this:
// Exception: [.ExcelHssfView] !ExcelView.errorexporting! Cause: Sheet name cannot be blank, greater than 31 chars, or contain any of /\*?[]
// this is due to either the POI limitations or excel (I'm not sure). you get the following error if you don't
// do this:
// Exception: [.ExcelHssfView] !ExcelView.errorexporting! Cause: Sheet name cannot be blank, greater than 31
// chars, or contain any of /\*?[]
if (StringUtils.isBlank(sheetName))
{
throw new JspException("The sheet name property " + ExcelUtils.EXCEL_SHEET_NAME + " must not be blank.");
}
sheetName = sheetName.replaceAll("/|\\\\|\\*|\\?|\\[|\\]","");
this.sheetName = sheetName.length() <= 31 ? sheetName : sheetName.substring(0,31-3) + "...";
sheetName = sheetName.replaceAll("/|\\\\|\\*|\\?|\\[|\\]", "");
this.sheetName = sheetName.length() <= 31 ? sheetName : sheetName.substring(0, 31 - 3) + "...";
}

public HSSFCellStyle getNewCellStyle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static String escapeColumnValue(Object rawValue)
return null;
}
// str = Patterns.replaceAll(str, "(\\r\\n|\\r|\\n|\\n\\r)\\s*", "");
String returnString = rawValue != null ? rawValue.toString() : StringUtils.EMPTY;
String returnString = rawValue.toString();
// escape the String to get the tabs, returns, newline explicit as \t \r \n
returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString));
// remove tabs, insert four whitespaces instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected static void writeExport(HttpServletResponse response, ServletRequest r
// response (this is the signal from table tag that it is going to write exported data)
log.debug("Filter operating in buffered mode. ");

Map bean = (Map) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY);
Map<String, Object> bean = (Map<String, Object>) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY);

if (log.isDebugEnabled())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Locale resolveLocale(HttpServletRequest request)
Locale result = null;
OgnlValueStack stack = ActionContext.getContext().getValueStack();

Iterator iterator = stack.getRoot().iterator();
Iterator<Object> iterator = stack.getRoot().iterator();
while (iterator.hasNext())
{
Object o = iterator.next();
Expand Down Expand Up @@ -93,7 +93,7 @@ public String getResource(String resourceKey, String defaultValue, Tag tag, Page

String message = null;
OgnlValueStack stack = TagUtils.getStack(pageContext);
Iterator iterator = stack.getRoot().iterator();
Iterator<Object> iterator = stack.getRoot().iterator();

while (iterator.hasNext())
{
Expand Down
6 changes: 3 additions & 3 deletions displaytag/src/main/java/org/displaytag/model/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author Fabrizio Giustina
* @version $Revision$ ($Author$)
*/
public class Cell implements Comparable, Cloneable
public class Cell implements Comparable<Cell>, Cloneable
{

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ public int compareTo(Object obj, Collator collator)
{
String a = (String) this.staticValue;
String b = (String) otherStatic;
return collator.compare(a,b);
return collator.compare(a, b);
}
else
{
Expand All @@ -114,7 +114,7 @@ public int compareTo(Object obj, Collator collator)
* @see java.lang.Comparable#compareTo(Object)
*/
@Override
public int compareTo(Object obj)
public int compareTo(Cell obj)
{
return compareTo(obj, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author rapruitt
* @version $Revision$ ($Author$)
*/
public class DefaultComparator implements Comparator
public class DefaultComparator implements Comparator<Object>
{

/**
Expand Down Expand Up @@ -64,7 +64,7 @@ public int compare(Object object1, Object object2)
}
else if (object1 instanceof Cell)
{
return ((Cell)object1).compareTo(object2, collator);
return ((Cell) object1).compareTo(object2, collator);
}
else if (object1 instanceof Comparable && object2 instanceof Comparable)
{
Expand Down
9 changes: 5 additions & 4 deletions displaytag/src/main/java/org/displaytag/model/RowSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author Fabrizio Giustina
* @version $Revision$ ($Author$)
*/
public class RowSorter implements Comparator
public class RowSorter implements Comparator<Object>
{

/**
Expand Down Expand Up @@ -196,9 +196,10 @@ public final boolean equals(Object object)
{
if (object instanceof RowSorter)
{
return new EqualsBuilder().append(this.property, ((RowSorter) object).property).append(
this.columnIndex,
((RowSorter) object).columnIndex).isEquals();
return new EqualsBuilder()
.append(this.property, ((RowSorter) object).property)
.append(this.columnIndex, ((RowSorter) object).columnIndex)
.isEquals();
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface PaginatedList
* Returns the current partial list
* @return the current partial list
*/
List getList();
List<Object> getList();

/**
* Returns the page number of the partial list (starts from 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* Class to help pagination when dealing with lists.
* </p>
* <p>
* The class will attempt to use <code>java.util.List.subList(int,int)</code> to index into the list for the
* appropriate page.
* The class will attempt to use <code>java.util.List.subList(int,int)</code> to index into the list for the appropriate
* page.
* </p>
* <p>
* If the list does not contain enough elements to support the sub list, then the first <code>pageSize</code> elements
Expand All @@ -44,17 +44,17 @@ public PaginationHelper(int pageNumber, int pageSize)
this.pageSize = pageSize;
}

public Iterator getIterator(Object data)
public Iterator<Object> getIterator(Object data)
{
if (data instanceof List)
{
return getIterator((List) data);
return getIterator((List<Object>) data);
}

return IteratorUtils.getIterator(data);
}

public Iterator getIterator(List data)
public Iterator<Object> getIterator(List<Object> data)
{
int start = getStart(data.size());
int end = getEnd(data.size(), start);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.Messages;
import org.displaytag.model.Row;
import org.displaytag.properties.TableProperties;
import org.displaytag.util.Href;

Expand Down Expand Up @@ -363,8 +364,11 @@ else if (pagination.isLast())
bannerFormat = this.properties.getPagingBannerFull();
}

return pagination.getFormattedBanner(this.properties.getPagingPageLink(), this.properties
.getPagingPageSelected(), this.properties.getPagingPageSeparator(), bannerFormat);
return pagination.getFormattedBanner(
this.properties.getPagingPageLink(),
this.properties.getPagingPageSelected(),
this.properties.getPagingPageSeparator(),
bannerFormat);
}

/**
Expand Down
18 changes: 6 additions & 12 deletions displaytag/src/main/java/org/displaytag/portlet/PortletHref.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,21 +543,15 @@ public String toString()
}
}

for (final Iterator paramItr = this.parameters.entrySet().iterator(); paramItr.hasNext();)
for (final Iterator<Entry<String, String[]>> paramItr = this.parameters.entrySet().iterator(); paramItr
.hasNext();)
{
final Map.Entry entry = (Map.Entry) paramItr.next();
final Entry<String, String[]> entry = paramItr.next();

final String name = (String) entry.getKey();
final Object value = entry.getValue();
final String name = entry.getKey();
final String[] value = entry.getValue();

if (value instanceof String)
{
url.setParameter(name, (String) value);
}
else if (value instanceof String[])
{
url.setParameter(name, (String[]) value);
}
url.setParameter(name, value);
}

if (this.getAnchor() == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Integer getIntParameter(String key)
* @see org.displaytag.util.RequestHelper#getParameterMap()
*/
@Override
public Map getParameterMap()
public Map<String, String[]> getParameterMap()
{
return this.portletRequest.getParameterMap();
}
Expand Down
Loading

0 comments on commit c045f1a

Please sign in to comment.