#1738 - Refactor toArray() plus various

This commit is contained in:
rob bygrave
2019-06-29 00:40:16 +12:00
parent 7fa5e2aa8c
commit ddf200ffdd
33 changed files with 50 additions and 53 deletions
@@ -219,7 +219,6 @@ abstract class AbstractBeanCollection<E> implements BeanCollection<E> {
/**
* Copies all relevant properties for a clone. See {@link #getShallowCopy()}
* @param other
*/
protected void setFromOriginal(AbstractBeanCollection<E> other) {
this.disableLazyLoad = other.disableLazyLoad;
@@ -77,6 +77,9 @@ public class PlatformConfig {
this.geometrySRID = platformConfig.geometrySRID;
this.dbUuid = platformConfig.dbUuid;
this.caseSensitiveCollation = platformConfig.caseSensitiveCollation;
this.allQuotedIdentifiers = platformConfig.allQuotedIdentifiers;
this.databaseInetAddressVarchar = platformConfig.databaseInetAddressVarchar;
this.customDbTypeMappings = platformConfig.customDbTypeMappings;
}
/**
@@ -223,7 +223,6 @@ public interface BeanType<T> {
/**
* Visit all children recursively
* @param visitor
*/
void visitAllInheritanceChildren(Consumer<BeanType<?>> visitor);
@@ -115,10 +115,10 @@ public class BindParams implements Serializable {
* Return a Natural Key bind param if supported.
*/
public NaturalKeyBindParam getNaturalKeyBindParam() {
if (positionedParameters != null) {
if (!positionedParameters.isEmpty()) {
return null;
}
if (namedParameters != null && namedParameters.size() == 1) {
if (namedParameters.size() == 1) {
Entry<String, Param> e = namedParameters.entrySet().iterator().next();
return new NaturalKeyBindParam(e.getKey(), e.getValue().getInValue());
}
@@ -134,7 +134,7 @@ public class BaseTableDdl implements TableDdl {
if (defaultValue == null) {
handleStrictError(tableName, columnName);
}
before = Arrays.asList(platformDdl.getUpdateNullWithDefault());
before = Collections.singletonList(platformDdl.getUpdateNullWithDefault());
} else {
before = getScriptsForPlatform(alter.getBefore(), platformDdl.getPlatform().getName());
}
@@ -150,7 +150,7 @@ public class CurrentModel {
List<DdlScript> ddlScript = extraDdl.getDdlScript();
for (DdlScript script : ddlScript) {
if (script.isInit() && ExtraDdlXmlReader.matchPlatform(server.getDatabasePlatform().getName(), script.getPlatforms())) {
ddl.append(prefix + script.getName()).append('\n');
ddl.append(prefix).append(script.getName()).append('\n');
ddl.append(script.getValue());
}
}
@@ -769,7 +769,7 @@ public class MTable {
nullableColumns.add(columnName);
}
}
uniq.setNullableColumns(nullableColumns.toArray(new String[nullableColumns.size()]));
uniq.setNullableColumns(nullableColumns.toArray(new String[0]));
}
}
@@ -100,7 +100,7 @@ public final class RelationalQueryRequest extends AbstractSqlQueryRequest {
for (int i = 1; i < columnsPlusOne; i++) {
propNames.add(metaData.getColumnLabel(i));
}
return propNames.toArray(new String[propNames.size()]);
return propNames.toArray(new String[0]);
}
/**
@@ -39,7 +39,7 @@ public final class BeanDescriptorDraftHelp<T> {
}
}
return list.toArray(new BeanProperty[list.size()]);
return list.toArray(new BeanProperty[0]);
}
/**
@@ -142,7 +142,7 @@ class BeanLifecycleAdapterFactory {
* Utility method to covert List of Method into array (because we care about performance here).
*/
static Method[] toArray(List<Method> methodList) {
return methodList.toArray(new Method[methodList.size()]);
return methodList.toArray(new Method[0]);
}
static RuntimeException unwrapException(ReflectiveOperationException e) {
@@ -683,7 +683,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
}
return list.toArray(new ExportedProperty[list.size()]);
return list.toArray(new ExportedProperty[0]);
}
/**
@@ -582,7 +582,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
}
return list.toArray(new ExportedProperty[list.size()]);
return list.toArray(new ExportedProperty[0]);
}
/**
@@ -769,10 +769,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
writeJson.writeNullField(name);
} else {
if (writeJson.isParentBean(value)) {
// bi-directional and already rendered parent
} else {
if (!writeJson.isParentBean(value)) {
// Hmmm, not writing complex non-entity bean
if (value instanceof EntityBean) {
writeJson.beginAssocOne(name, bean);
@@ -44,7 +44,7 @@ public class ChainedBeanPersistController implements BeanPersistController {
*/
public ChainedBeanPersistController(List<BeanPersistController> list) {
this.list = list;
BeanPersistController[] c = list.toArray(new BeanPersistController[list.size()]);
BeanPersistController[] c = list.toArray(new BeanPersistController[0]);
Arrays.sort(c, SORTER);
this.chain = c;
}
@@ -50,7 +50,7 @@ public class ChainedBeanPersistListener implements BeanPersistListener {
*/
public ChainedBeanPersistListener(List<BeanPersistListener> list) {
this.list = list;
this.chain = list.toArray(new BeanPersistListener[list.size()]);
this.chain = list.toArray(new BeanPersistListener[0]);
}
/**
@@ -19,7 +19,7 @@ public class ChainedBeanPostConstructListener implements BeanPostConstructListen
*/
public ChainedBeanPostConstructListener(List<BeanPostConstructListener> list) {
this.list = list;
this.chain = list.toArray(new BeanPostConstructListener[list.size()]);
this.chain = list.toArray(new BeanPostConstructListener[0]);
}
/**
@@ -19,7 +19,7 @@ public class ChainedBeanPostLoad implements BeanPostLoad {
*/
public ChainedBeanPostLoad(List<BeanPostLoad> list) {
this.list = list;
this.chain = list.toArray(new BeanPostLoad[list.size()]);
this.chain = list.toArray(new BeanPostLoad[0]);
}
/**
@@ -24,7 +24,7 @@ public class ChainedBeanQueryAdapter implements BeanQueryAdapter {
*/
public ChainedBeanQueryAdapter(List<BeanQueryAdapter> list) {
this.list = list;
BeanQueryAdapter[] c = list.toArray(new BeanQueryAdapter[list.size()]);
BeanQueryAdapter[] c = list.toArray(new BeanQueryAdapter[0]);
Arrays.sort(c, SORTER);
this.chain = c;
}
@@ -78,7 +78,7 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
*/
public static ImportedIdSimple[] sort(List<ImportedIdSimple> list) {
ImportedIdSimple[] importedIds = list.toArray(new ImportedIdSimple[list.size()]);
ImportedIdSimple[] importedIds = list.toArray(new ImportedIdSimple[0]);
// sort into the same order as the BeanProperties
Arrays.sort(importedIds, COMPARATOR);
@@ -561,7 +561,7 @@ public class DeployBeanDescriptor<T> {
if (indexDefinitions == null) {
return null;
} else {
return indexDefinitions.toArray(new IndexDefinition[indexDefinitions.size()]);
return indexDefinitions.toArray(new IndexDefinition[0]);
}
}
@@ -284,7 +284,7 @@ public class DeployBeanPropertyLists {
* properties).
*/
public BeanProperty[] getBaseScalar() {
return baseScalar.toArray(new BeanProperty[baseScalar.size()]);
return baseScalar.toArray(new BeanProperty[0]);
}
public BeanProperty getId() {
@@ -292,11 +292,11 @@ public class DeployBeanPropertyLists {
}
public BeanProperty[] getNonTransients() {
return nonTransients.toArray(new BeanProperty[nonTransients.size()]);
return nonTransients.toArray(new BeanProperty[0]);
}
public BeanProperty[] getTransients() {
return transients.toArray(new BeanProperty[transients.size()]);
return transients.toArray(new BeanProperty[0]);
}
public BeanProperty getVersionProperty() {
@@ -304,23 +304,23 @@ public class DeployBeanPropertyLists {
}
public BeanProperty[] getLocal() {
return local.toArray(new BeanProperty[local.size()]);
return local.toArray(new BeanProperty[0]);
}
public BeanProperty[] getMutable() {
return mutable.toArray(new BeanProperty[mutable.size()]);
return mutable.toArray(new BeanProperty[0]);
}
public BeanPropertyAssocOne<?>[] getEmbedded() {
return embedded.toArray(new BeanPropertyAssocOne[embedded.size()]);
return embedded.toArray(new BeanPropertyAssocOne[0]);
}
public BeanPropertyAssocOne<?>[] getOneImported() {
return onesImported.toArray(new BeanPropertyAssocOne[onesImported.size()]);
return onesImported.toArray(new BeanPropertyAssocOne[0]);
}
public BeanPropertyAssocOne<?>[] getOnes() {
return ones.toArray(new BeanPropertyAssocOne[ones.size()]);
return ones.toArray(new BeanPropertyAssocOne[0]);
}
public BeanPropertyAssocOne<?>[] getOneExportedSave() {
@@ -340,11 +340,11 @@ public class DeployBeanPropertyLists {
}
public BeanProperty[] getNonMany() {
return nonManys.toArray(new BeanProperty[nonManys.size()]);
return nonManys.toArray(new BeanProperty[0]);
}
public BeanPropertyAssocMany<?>[] getMany() {
return manys.toArray(new BeanPropertyAssocMany[manys.size()]);
return manys.toArray(new BeanPropertyAssocMany[0]);
}
public BeanPropertyAssocMany<?>[] getManySave() {
@@ -397,7 +397,7 @@ public class DeployBeanPropertyLists {
list.add(prop);
}
}
return list.toArray(new BeanProperty[list.size()]);
return list.toArray(new BeanProperty[0]);
}
/**
@@ -412,7 +412,7 @@ public class DeployBeanPropertyLists {
list.add(prop);
}
}
return list.toArray(new BeanProperty[list.size()]);
return list.toArray(new BeanProperty[0]);
}
/**
@@ -443,7 +443,7 @@ public class DeployBeanPropertyLists {
}
}
return (BeanPropertyAssocOne[]) list.toArray(new BeanPropertyAssocOne[list.size()]);
return (BeanPropertyAssocOne[]) list.toArray(new BeanPropertyAssocOne[0]);
}
private BeanPropertyAssocMany<?>[] getMany2Many() {
@@ -454,7 +454,7 @@ public class DeployBeanPropertyLists {
}
}
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[0]);
}
private BeanPropertyAssocMany<?>[] getMany(Mode mode) {
@@ -476,7 +476,7 @@ public class DeployBeanPropertyLists {
}
}
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[0]);
}
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -106,7 +106,7 @@ public class DeployTableJoin {
* Return the join columns.
*/
public DeployTableJoinColumn[] columns() {
return columns.toArray(new DeployTableJoinColumn[columns.size()]);
return columns.toArray(new DeployTableJoinColumn[0]);
}
/**
@@ -189,7 +189,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
private void checkForNoConstraint(DeployBeanPropertyAssocOne<?> prop, JoinColumn joinColumn) {
ForeignKey foreignKey = joinColumn.foreignKey();
if (foreignKey != null && foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
if (foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
prop.setForeignKey(new PropertyForeignKey());
}
}
@@ -58,13 +58,12 @@ public class ElPropertyChainBuilder {
* Build the immutable ElGetChain from the build information.
*/
public ElPropertyChain build() {
return new ElPropertyChain(containsMany, embedded, expression, chain.toArray(new ElPropertyValue[chain.size()]));
return new ElPropertyChain(containsMany, embedded, expression, chain.toArray(new ElPropertyValue[0]));
}
/**
* Permits to set whole chain as embedded when the leaf is embedded
* @param embedded
*/
*/
public void setEmbedded(boolean embedded) {
this.embedded = embedded;
}
@@ -352,7 +352,7 @@ public final class BatchControl {
* Return the BatchedBeanHolder's ready for sorting and executing.
*/
private BatchedBeanHolder[] getBeanHolderArray() {
return beanHoldMap.values().toArray(new BatchedBeanHolder[beanHoldMap.size()]);
return beanHoldMap.values().toArray(new BatchedBeanHolder[0]);
}
/**
@@ -114,7 +114,7 @@ public class BatchedPstmtHolder {
// the flush may get called recursively in executeBatch/postExecute.
// which leads that we process stmtMap.values() twice in the loop.
// So we copy the values, that we want to flush and clear it immediately.
BatchedPstmt[] values = stmtMap.values().toArray(new BatchedPstmt[stmtMap.values().size()]);
BatchedPstmt[] values = stmtMap.values().toArray(new BatchedPstmt[0]);
clear();
for (BatchedPstmt bs : values) {
@@ -20,7 +20,7 @@ public class BindableEmbedded implements Bindable {
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
this.embProp = embProp;
this.items = bindList.toArray(new Bindable[bindList.size()]); //this.props = propList.toArray(new BeanProperty[propList.size()]);
this.items = bindList.toArray(new Bindable[0]);
}
@Override
@@ -17,7 +17,7 @@ public class BindableList implements Bindable {
private final Bindable[] items;
public BindableList(List<Bindable> list) {
items = list.toArray(new Bindable[list.size()]);
items = list.toArray(new Bindable[0]);
}
/**
@@ -452,7 +452,7 @@ class CQueryBuilder {
}
}
RawSql rawSql = RawSqlBuilder.resultSet(resultSet, propertyNames.toArray(new String[propertyNames.size()]));
RawSql rawSql = RawSqlBuilder.resultSet(resultSet, propertyNames.toArray(new String[0]));
query.setRawSql(rawSql);
return createRawSqlSqlTree(request, predicates);
@@ -101,7 +101,7 @@ class DefaultDbSqlContext implements DbSqlContext {
return null;
}
return encryptedProps.toArray(new BeanProperty[encryptedProps.size()]);
return encryptedProps.toArray(new BeanProperty[0]);
}
@Override
@@ -719,7 +719,7 @@ public final class SqlTreeBuilder {
extras.add(predProp);
}
}
return extras.toArray(new String[extras.size()]);
return extras.toArray(new String[0]);
}
}
@@ -61,7 +61,7 @@ public class SqlTreeProperties {
}
public STreeProperty[] getProps() {
return propsList.toArray(new STreeProperty[propsList.size()]);
return propsList.toArray(new STreeProperty[0]);
}
boolean isPartialObject() {
@@ -49,7 +49,7 @@ final class DRawSqlColumnsParser {
tmp.add(aSplit.trim());
}
}
split = tmp.toArray(new String[tmp.size()]);
split = tmp.toArray(new String[0]);
}
if (split.length == 0) {
@@ -233,7 +233,7 @@ public class CsvUtilReader {
}
} while (inQuotes);
tokensOnThisLine.add(sb.toString().trim());
return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]);
return tokensOnThisLine.toArray(new String[0]);
}
/**