Skip to content

Commit

Permalink
Prefer empty array in Collection#toArray calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilliger committed Nov 2, 2019
1 parent d2f0f8c commit efa4e9f
Show file tree
Hide file tree
Showing 34 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 191,7 @@ else if (tailFrom.after(from)) {
* @return an {@link Iterator} containing elememts of type {@link TimeRange}.
*/
public TimeRange[] getTimeRanges() {
return m_multipleTimeRangeMap.values().toArray(new TimeRange[m_multipleTimeRangeMap.size()]);
return m_multipleTimeRangeMap.values().toArray(new TimeRange[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 326,7 @@ public void updateDisplayTexts(List<ITableRow> rows) {

//
if (!batchCall.isEmpty()) {
ITableRow[] tableRows = batchRowList.toArray(new ITableRow[batchRowList.size()]);
ITableRow[] tableRows = batchRowList.toArray(new ITableRow[0]);
IBatchLookupService service = BEANS.get(IBatchLookupService.class);
List<List<ILookupRow<?>>> resultArray = service.getBatchDataByKey(batchCall);
for (int i = 0; i < tableRows.length; i ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 654,7 @@ protected void initConfig() {

// add dynamic keyStrokes
List<IKeyStroke> ksList = new ActionFinder().findActions(actionList, IKeyStroke.class, true);
addKeyStrokes(ksList.toArray(new IKeyStroke[ksList.size()]));
addKeyStrokes(ksList.toArray(new IKeyStroke[0]));
addPropertyChangeListener(new P_LocalPropertyChangeListener());

addAddOn(BEANS.get(PopupManager.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 598,7 @@ protected void execAction() {
names.add(((Bookmark) bookmark.getCell().getValue()).getTitle());
}
}
if (MessageBoxes.showDeleteConfirmationMessage(names.toArray(new String[names.size()]))) {
if (MessageBoxes.showDeleteConfirmationMessage(names.toArray(new String[0]))) {
// delete bookmarks
for (ITreeNode bookmark : bookmarks) {
tree.removeNode(bookmark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 2246,7 @@ public void loadFromXml(Element root) {
xmlFieldIds.add(element.getAttribute("fieldId"));
}
xmlFieldIds.add(xField.getAttribute("fieldId"));
FindFieldByXmlIdsVisitor v = new FindFieldByXmlIdsVisitor(xmlFieldIds.toArray(new String[xmlFieldIds.size()]));
FindFieldByXmlIdsVisitor v = new FindFieldByXmlIdsVisitor(xmlFieldIds.toArray(new String[0]));
visit(v, IFormField.class);
IFormField f = v.getField();
if (f != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 235,7 @@ private void attachCheckFromToListeners() {
//fields with equal types
ArrayList<IValueField> valueFieldList = getComparableValueFields();
if (valueFieldList.size() >= 2) {
final IValueField[] valueFields = valueFieldList.toArray(new IValueField[valueFieldList.size()]);
final IValueField[] valueFields = valueFieldList.toArray(new IValueField[0]);
for (int i = 0; i < valueFields.length; i ) {
final int index = i;
valueFields[index].addPropertyChangeListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 42,7 @@ public void validate(ISplitBox splitBox) {
f.setGridDataInternal(data);
}
}
m_fields = list.toArray(new IFormField[list.size()]);
m_fields = list.toArray(new IFormField[0]);
layoutStatic();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 42,7 @@ public void validate(ITabBox tabBox) {
f.setGridDataInternal(data);
}
}
m_fields = list.toArray(new IFormField[list.size()]);
m_fields = list.toArray(new IFormField[0]);
layoutStatic();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 80,7 @@ public void addParameters(List<PropertyParameter> propertyParameters) {
for (PropertyParameter parameter : propertyParameters) {
if (m_parameters.containsKey(parameter.getName())) {
PropertyParameter existingParameter = m_parameters.get(parameter.getName());
existingParameter.addValues(parameter.getValueSet().toArray(new String[parameter.getValueSet().size()]));
existingParameter.addValues(parameter.getValueSet().toArray(new String[0]));
}
else {
m_parameters.put(parameter.getName(), parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 138,7 @@ public Property readProperty() throws IOException {
}
parameterList.add(parametersPart.substring(nextParamStart));

Property property = parseParameters(parameterList.toArray(new String[parameterList.size()]));
Property property = parseParameters(parameterList.toArray(new String[0]));

/**************
* READ VALUE *
Expand Down Expand Up @@ -259,7 259,7 @@ private Property parseParameters(String[] parameters) {
}
else if (VCardProperties.PARAM_NAME_TYPE.equalsIgnoreCase(name)) {
// add values for parameter TYPE directly as property parameters for easier accessibility
for (String v : values.toArray(new String[values.size()])) {
for (String v : values.toArray(new String[0])) {
// the parameter values of the parameter "TYPE" are case-insensitive for all properties defined in RFC-2426
v = v.toUpperCase();
if (VCardProperties.PARAM_VALUE_CAR.equals(v)) {
Expand All @@ -284,10 284,10 @@ else if (VCardProperties.PARAM_VALUE_WORK.equals(v)) {
property.addParameters(VCardProperties.PARAM_WORK);
}
}
property.addParameters(new PropertyParameter(VCardProperties.PARAM_NAME_TYPE, values.isEmpty() ? null : values.toArray(new String[values.size()])));
property.addParameters(new PropertyParameter(VCardProperties.PARAM_NAME_TYPE, values.isEmpty() ? null : values.toArray(new String[0])));
}
else {
PropertyParameter p = new PropertyParameter(name, values.isEmpty() ? null : values.toArray(new String[values.size()]));
PropertyParameter p = new PropertyParameter(name, values.isEmpty() ? null : values.toArray(new String[0]));
property.addParameters(p);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 782,7 @@ protected InternetAddress[] createInternetAddresses(List<? extends MailParticipa
addrList.add(internetAddress);
}
}
return addrList.toArray(new InternetAddress[addrList.size()]);
return addrList.toArray(new InternetAddress[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 117,7 @@ public static ClassIdentifier[] convertClassArrayToClassIdentifierArray(Class<?>
result.add(new ClassIdentifier(c));
}
}
return result.toArray(new ClassIdentifier[result.size()]);
return result.toArray(new ClassIdentifier[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 138,7 @@ public static StackTraceElement[] unionStackTrace(Throwable t) {
list.addAll(0, Arrays.asList(t.getStackTrace()));
t = t.getCause();
}
return list.toArray(new StackTraceElement[list.size()]);
return list.toArray(new StackTraceElement[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 132,7 @@ public JobEventFilterBuilder andMatchFuture(final Collection<IFuture<?>> futures
* To match all events for jobs which belong to one of the given Futures.
*/
public <RESULT> JobEventFilterBuilder andMatchFuture(final List<IFuture<RESULT>> futures) {
andMatch(new FutureFilterWrapperJobEventFilter(new FutureFilter(futures.toArray(new IFuture<?>[futures.size()]))));
andMatch(new FutureFilterWrapperJobEventFilter(new FutureFilter(futures.toArray(new IFuture<?>[0]))));
return this;
}

Expand All @@ -156,7 156,7 @@ public JobEventFilterBuilder andMatchNotFuture(final Collection<IFuture<?>> futu
* To match all events for jobs which do not belong to any of the given Futures.
*/
public <RESULT> JobEventFilterBuilder andMatchNotFuture(final List<IFuture<RESULT>> futures) {
andMatchNot(new FutureFilterWrapperJobEventFilter(new FutureFilter(futures.toArray(new IFuture<?>[futures.size()]))));
andMatchNot(new FutureFilterWrapperJobEventFilter(new FutureFilter(futures.toArray(new IFuture<?>[0]))));
return this;
}

Expand Down Expand Up @@ -260,7 260,7 @@ protected static IFuture<?>[] calculateFutureIntersection(final Collection<Predi
return null; // NOSONAR
}

return intersection.toArray(new IFuture<?>[intersection.size()]);
return intersection.toArray(new IFuture<?>[0]);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 44,7 @@ public boolean test(final IFuture<?> future) {
@Override
public <T> T getAdapter(final Class<T> type) {
if (type == IFuture[].class) {
return (T) m_futures.toArray(new IFuture[m_futures.size()]);
return (T) m_futures.toArray(new IFuture[0]);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 103,7 @@ public FutureFilterBuilder andMatchFuture(final Collection<IFuture<?>> futures)
* To match all jobs which are represented by one of the given Futures.
*/
public <RESULT> FutureFilterBuilder andMatchFuture(final List<IFuture<RESULT>> futures) {
andMatch(new FutureFilter(futures.toArray(new IFuture<?>[futures.size()])));
andMatch(new FutureFilter(futures.toArray(new IFuture<?>[0])));
return this;
}

Expand All @@ -127,7 127,7 @@ public FutureFilterBuilder andMatchNotFuture(final Collection<IFuture<?>> future
* To match all jobs which are not represented by any of the given Futures.
*/
public <RESULT> FutureFilterBuilder andMatchNotFuture(final List<IFuture<RESULT>> futures) {
andMatchNot(new FutureFilter(futures.toArray(new IFuture<?>[futures.size()])));
andMatchNot(new FutureFilter(futures.toArray(new IFuture<?>[0])));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 529,7 @@ private void processChangeBuffer() {
PropertyChangeEvent[] a = null;
synchronized (m_listenerLock) {
if (m_propertyEventBuffer != null) {
a = m_propertyEventBuffer.toArray(new PropertyChangeEvent[m_propertyEventBuffer.size()]);
a = m_propertyEventBuffer.toArray(new PropertyChangeEvent[0]);
}
m_propertyEventBuffer = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 28,7 @@ public class FastBeanInfo {
public FastBeanInfo(Class<?> beanClass, Class<?> stopClass) {
m_beanClass = beanClass;
m_propertyMap = Collections.unmodifiableMap(FastBeanUtility.createPropertyDescriptorMap(beanClass, stopClass));
m_propertyArray = m_propertyMap.values().toArray(new FastPropertyDescriptor[m_propertyMap.size()]);
m_propertyArray = m_propertyMap.values().toArray(new FastPropertyDescriptor[0]);
}

public Class getBeanClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 123,7 @@ public static Method[] getDeclaredPublicMethods(Class c) {
}
}
}
return methodsList.toArray(new Method[methodsList.size()]);
return methodsList.toArray(new Method[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 59,7 @@ public static Class<?>[] getInterfaces(Class<?> clazz) {
interfaces.addAll(Arrays.asList(clazz.getInterfaces()));
clazz = clazz.getSuperclass();
}
return interfaces.toArray(new Class<?>[interfaces.size()]);
return interfaces.toArray(new Class<?>[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 99,7 @@ public ITransactionMember[] getMembers() {
}

private ITransactionMember[] getMembersNoLocking() {
return m_memberMap.values().toArray(new ITransactionMember[m_memberMap.size()]);
return m_memberMap.values().toArray(new ITransactionMember[0]);
}

@Override
Expand Down Expand Up @@ -198,7 198,7 @@ public boolean hasFailures() {

@Override
public Throwable[] getFailures() {
return m_failures.toArray(new Throwable[m_failures.size()]);
return m_failures.toArray(new Throwable[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 159,7 @@ public static FastPropertyDescriptor[] getFastPropertyDescriptors(Class<?> clazz
filteredProperties.add(pd);
}
}
return filteredProperties.toArray(new FastPropertyDescriptor[filteredProperties.size()]);
return filteredProperties.toArray(new FastPropertyDescriptor[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 452,7 @@ public static void writeString(Writer out, String s) {
public static File[] listFilesInSubtree(File dir, FileFilter filter) {
ArrayList<File> list = new ArrayList<>();
listFilesRec(dir, filter, list);
return list.toArray(new File[list.size()]);
return list.toArray(new File[0]);
}

private static void listFilesRec(File dir, FileFilter filter, ArrayList<File> intoList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 1500,8 @@ else if (parentAliasMap.size() == 1) {

@SuppressWarnings("squid:S138")
public String createSqlOpValuePart(Integer aggregationType, String sql, int operation, List<String> bindNames, List<Object> bindValues, boolean plainBind) {
String[] names = (bindNames != null ? bindNames.toArray(new String[bindNames.size()]) : new String[0]);
Object[] values = (bindValues != null ? bindValues.toArray(new Object[bindValues.size()]) : new Object[0]);
String[] names = (bindNames != null ? bindNames.toArray(new String[0]) : new String[0]);
Object[] values = (bindValues != null ? bindValues.toArray(new Object[0]) : new Object[0]);
if (plainBind && operation != OPERATOR_NONE) {
//rewrite bindNames by plain values
for (int i = 0; i < names.length; i ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 35,7 @@ else if (token instanceof ValueOutputToken) {
ioList.add(token);
}
}
m_ioTokens = ioList.toArray(new IToken[ioList.size()]);
m_ioTokens = ioList.toArray(new IToken[0]);
}

public IToken[] getAllTokens() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 89,7 @@ public BindModel parse() {
if (m_pos.getIndex() < m_str.length()) {
LOG.warn("statement not fully parsed (index {}): {}", m_pos.getIndex(), m_str);
}
return new BindModel(m_tokenList.toArray(new IToken[m_tokenList.size()]));
return new BindModel(m_tokenList.toArray(new IToken[0]));
}

private boolean parseStatement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 52,7 @@ public static void removeDiagnosticStatusProvider(IDiagnostic statusProvider) {

public static IDiagnostic[] getDiagnosticProviders() {
synchronized (DIAGNOSTIC_STATUS_PROVIDERS) {
IDiagnostic[] copy = DIAGNOSTIC_STATUS_PROVIDERS.toArray(new IDiagnostic[DIAGNOSTIC_STATUS_PROVIDERS.size()]);
IDiagnostic[] copy = DIAGNOSTIC_STATUS_PROVIDERS.toArray(new IDiagnostic[0]);
return copy;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 87,7 @@ private void renderCallTable(HtmlComponent p, SessionInspector session) {
long startTime = callInspectors[i].getInfo().getStartTime();
timeToCalls.put(new CompositeObject(startTime, i), callInspectors[i]);
}
CallInspector[] sorted = timeToCalls.values().toArray(new CallInspector[timeToCalls.size()]);
CallInspector[] sorted = timeToCalls.values().toArray(new CallInspector[0]);
p.bold("Calls");
p.startTable(1, 0, 3);
p.startTableRow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 61,7 @@ public void activated() {
for (IService service : BEANS.all(IService.class)) {
list.add(new ServiceInspector(service));
}
m_serviceInspectors = list.toArray(new ServiceInspector[list.size()]);
m_serviceInspectors = list.toArray(new ServiceInspector[0]);
}
catch (Exception e) { // NOSONAR
// nop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 97,7 @@ protected SessionInspector[] getSortedSessions() {
long lastAccess = NumberUtility.nvl(sessionInspectors[i].getInfo().getLastAccessedTime(), 0L);
userAndTimeToSessions.put(new CompositeObject(lastAccess, user, i), sessionInspectors[i]);
}
return userAndTimeToSessions.values().toArray(new SessionInspector[userAndTimeToSessions.size()]);
return userAndTimeToSessions.values().toArray(new SessionInspector[0]);
}

protected void renderSessionTableHeader(HtmlTable table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 114,7 @@ public <T extends AbstractPropertyData> void setPropertyByClass(Class<T> c, T v)

@Override
public AbstractPropertyData[] getAllProperties() {
return m_propertyMap != null ? m_propertyMap.values().toArray(new AbstractPropertyData[m_propertyMap.size()]) : new AbstractPropertyData[0];
return m_propertyMap != null ? m_propertyMap.values().toArray(new AbstractPropertyData[0]) : new AbstractPropertyData[0];
}

public AbstractFormFieldData getFieldById(String id) {
Expand Down Expand Up @@ -167,7 167,7 @@ private <T extends AbstractFormFieldData> Class<? extends T> getReplacingFieldDa
* @return all fields of the form data itself, not including fields in external field templates
*/
public AbstractFormFieldData[] getFields() {
return m_fieldMap.values().toArray(new AbstractFormFieldData[m_fieldMap.size()]);
return m_fieldMap.values().toArray(new AbstractFormFieldData[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 142,7 @@ public <T extends AbstractPropertyData> void setPropertyByClass(Class<T> c, T v)

@Override
public AbstractPropertyData[] getAllProperties() {
return m_propertyMap != null ? m_propertyMap.values().toArray(new AbstractPropertyData[m_propertyMap.size()]) : new AbstractPropertyData[0];
return m_propertyMap != null ? m_propertyMap.values().toArray(new AbstractPropertyData[0]) : new AbstractPropertyData[0];
}

public AbstractFormFieldData getFieldById(String id) {
Expand Down Expand Up @@ -206,7 206,7 @@ public AbstractFormFieldData[] getFields() {
if (m_fieldMap == null) {
return new AbstractFormFieldData[0];
}
return m_fieldMap.values().toArray(new AbstractFormFieldData[m_fieldMap.size()]);
return m_fieldMap.values().toArray(new AbstractFormFieldData[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 176,7 @@ public void setBusyStatus(int a) {

@Override
public String[] getRecipientEmail() {
return m_recipientEmail.toArray(new String[m_recipientEmail.size()]);
return m_recipientEmail.toArray(new String[0]);
}

public void addRecipientEmail(String recipientEmail) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 64,7 @@ public void clear() {
}

public String[] getDisplayTexts() {
return m_displayTexts.toArray(new String[m_displayTexts.size()]);
return m_displayTexts.toArray(new String[0]);
}

public void setDisplayTexts(String[] displayTexts) {
Expand Down

0 comments on commit efa4e9f

Please sign in to comment.