mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CS-19072: got rid of unneeded type casting when apply pagination to different resources
This commit is contained in:
parent
42a861e590
commit
89017a7d7b
@ -4487,18 +4487,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now apply pagination
|
// Now apply pagination
|
||||||
List<?> wPagination = StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(), cmd.getPageSizeVal());
|
List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>(wPagination, offerings.size());
|
||||||
Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>((List<NetworkOffering>) wPagination, offerings.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends NetworkOffering>, Integer>(supportedOfferings, supportedOfferings.size());
|
return new Pair<List<? extends NetworkOffering>, Integer>(supportedOfferings, supportedOfferings.size());
|
||||||
} else {
|
} else {
|
||||||
List<?> wPagination = StringUtils.applyPagination(offerings, cmd.getStartIndex(), cmd.getPageSizeVal());
|
List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(offerings, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>(wPagination, offerings.size());
|
||||||
Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>((List<NetworkOffering>) wPagination, offerings.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends NetworkOffering>, Integer>(offerings, offerings.size());
|
return new Pair<List<? extends NetworkOffering>, Integer>(offerings, offerings.size());
|
||||||
|
|||||||
@ -1623,10 +1623,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Now apply pagination
|
//Now apply pagination
|
||||||
List<?> wPagination = StringUtils.applyPagination(networksToReturn, cmd.getStartIndex(), cmd.getPageSizeVal());
|
List<? extends Network> wPagination = StringUtils.applyPagination(networksToReturn, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends Network>, Integer> listWPagination = new Pair<List<? extends Network>, Integer>(wPagination, networksToReturn.size());
|
||||||
Pair<List<? extends Network>, Integer> listWPagination = new Pair<List<? extends Network>, Integer>((List<NetworkVO>) wPagination, networksToReturn.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -671,18 +671,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<?> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
|
List<? extends VpcOffering> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>(wPagination, supportedOfferings.size());
|
||||||
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>((List<VpcOffering>) wPagination, supportedOfferings.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends VpcOffering>, Integer>(supportedOfferings, supportedOfferings.size());
|
return new Pair<List<? extends VpcOffering>, Integer>(supportedOfferings, supportedOfferings.size());
|
||||||
} else {
|
} else {
|
||||||
List<?> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
|
List<? extends VpcOffering> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>(wPagination, offerings.size());
|
||||||
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>((List<VpcOffering>) wPagination, offerings.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends VpcOffering>, Integer>(offerings, offerings.size());
|
return new Pair<List<? extends VpcOffering>, Integer>(offerings, offerings.size());
|
||||||
@ -1128,18 +1126,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<?> wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal);
|
List<? extends Vpc> wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal);
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>(wPagination, supportedVpcs.size());
|
||||||
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>((List<Vpc>) wPagination, supportedVpcs.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends Vpc>, Integer>(supportedVpcs, supportedVpcs.size());
|
return new Pair<List<? extends Vpc>, Integer>(supportedVpcs, supportedVpcs.size());
|
||||||
} else {
|
} else {
|
||||||
List<?> wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal);
|
List<? extends Vpc> wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal);
|
||||||
if (wPagination != null) {
|
if (wPagination != null) {
|
||||||
@SuppressWarnings("unchecked")
|
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>(wPagination, vpcs.size());
|
||||||
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>((List<Vpc>) wPagination, vpcs.size());
|
|
||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
return new Pair<List<? extends Vpc>, Integer>(vpcs, vpcs.size());
|
return new Pair<List<? extends Vpc>, Integer>(vpcs, vpcs.size());
|
||||||
|
|||||||
@ -269,16 +269,16 @@ public class StringUtils {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<?> applyPagination(List<?> originalList, Long startIndex, Long pageSizeVal) {
|
public static <T> List<T> applyPagination(List<T> originalList, Long startIndex, Long pageSizeVal) {
|
||||||
// Most likely pageSize will never exceed int value, and we need integer to partition the listToReturn
|
// Most likely pageSize will never exceed int value, and we need integer to partition the listToReturn
|
||||||
boolean applyPagination = startIndex != null && pageSizeVal != null
|
boolean applyPagination = startIndex != null && pageSizeVal != null
|
||||||
&& startIndex <= Integer.MAX_VALUE && startIndex >= Integer.MIN_VALUE && pageSizeVal <= Integer.MAX_VALUE
|
&& startIndex <= Integer.MAX_VALUE && startIndex >= Integer.MIN_VALUE && pageSizeVal <= Integer.MAX_VALUE
|
||||||
&& pageSizeVal >= Integer.MIN_VALUE;
|
&& pageSizeVal >= Integer.MIN_VALUE;
|
||||||
List<?> listWPagination = null;
|
List<T> listWPagination = null;
|
||||||
if (applyPagination) {
|
if (applyPagination) {
|
||||||
listWPagination = new ArrayList<>();
|
listWPagination = new ArrayList<>();
|
||||||
int index = startIndex.intValue() == 0 ? 0 : startIndex.intValue() / pageSizeVal.intValue();
|
int index = startIndex.intValue() == 0 ? 0 : startIndex.intValue() / pageSizeVal.intValue();
|
||||||
List<List<?>> partitions = StringUtils.partitionList(originalList, pageSizeVal.intValue());
|
List<List<T>> partitions = StringUtils.partitionList(originalList, pageSizeVal.intValue());
|
||||||
if (index < partitions.size()) {
|
if (index < partitions.size()) {
|
||||||
listWPagination = partitions.get(index);
|
listWPagination = partitions.get(index);
|
||||||
}
|
}
|
||||||
@ -286,8 +286,8 @@ public class StringUtils {
|
|||||||
return listWPagination;
|
return listWPagination;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<List<?>> partitionList(List<?> originalList, int chunkSize) {
|
private static <T> List<List<T>> partitionList(List<T> originalList, int chunkSize) {
|
||||||
List<List<?>> listOfChunks = new ArrayList<List<?>>();
|
List<List<T>> listOfChunks = new ArrayList<List<T>>();
|
||||||
for (int i = 0; i < originalList.size() / chunkSize; i++) {
|
for (int i = 0; i < originalList.size() / chunkSize; i++) {
|
||||||
listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize));
|
listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user