");
return sb.toString();
}
@Override
- public int compareTo(Resource other) {
- ResourceInformation[] thisResources = this.getResources();
- ResourceInformation[] otherResources = other.getResources();
-
- // compare memory and vcores first(in that order) to preserve
- // existing behaviour
- long diff = this.getMemorySize() - other.getMemorySize();
- if (diff == 0) {
- diff = this.getVirtualCores() - other.getVirtualCores();
- }
- if (diff == 0) {
- diff = thisResources.length - otherResources.length;
- if (diff == 0) {
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
- // For memory and vcores, we can skip the loop as it's already
- // compared.
- if (i < 2) {
- continue;
- }
-
- ResourceInformation entry = thisResources[i];
- ResourceInformation otherEntry = otherResources[i];
- if (entry.getName().equals(otherEntry.getName())) {
- diff = entry.compareTo(otherEntry);
- if (diff != 0) {
- break;
- }
- }
- }
- }
+ public int hashCode() {
+ final int prime = 263167;
+ int result = 939769357;
+ for (ResourceInformation entry : getResources()) {
+ result = prime * result + entry.hashCode();
}
- return Long.compare(diff, 0);
+ return result;
}
}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java
index 3ab7ccd04d3..2a040948d58 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java
@@ -18,6 +18,8 @@
package org.apache.hadoop.yarn.api.records;
+import org.apache.curator.shaded.com.google.common.reflect.ClassPath;
+import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
import org.apache.hadoop.yarn.util.UnitsConversionUtil;
@@ -34,8 +36,8 @@
private long minimumAllocation;
private long maximumAllocation;
- private static final String MEMORY_URI = "memory-mb";
- private static final String VCORES_URI = "vcores";
+ public static final String MEMORY_URI = "memory-mb";
+ public static final String VCORES_URI = "vcores";
public static final ResourceInformation MEMORY_MB =
ResourceInformation.newInstance(MEMORY_URI, "Mi");
@@ -84,6 +86,16 @@ public void setUnits(String rUnits) {
}
/**
+ * Checking if a unit included by KNOWN_UNITS is an expensive operation. This
+ * can be avoided in critical path in RM.
+ * @param rUnits units for the resource
+ */
+ @InterfaceAudience.Private
+ public void setUnitsWithoutValidation(String rUnits) {
+ this.units = rUnits;
+ }
+
+ /**
* Get the resource type.
*
* @return the resource type
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/BaseResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/BaseResource.java
index b5cc4d63e4d..2cbbb4447c1 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/BaseResource.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/BaseResource.java
@@ -18,13 +18,18 @@
package org.apache.hadoop.yarn.api.records.impl;
+import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
+import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
import java.util.Arrays;
+import static org.apache.hadoop.yarn.api.records.ResourceInformation.MEMORY_MB;
+
/**
*
* BaseResource extends Resource to handle base resources such
@@ -54,48 +59,46 @@
*
* @see Resource
*/
-@Public
+@InterfaceAudience.Private
@Unstable
public class BaseResource extends Resource {
private ResourceInformation memoryResInfo;
private ResourceInformation vcoresResInfo;
- protected ResourceInformation[] resources = null;
- protected ResourceInformation[] readOnlyResources = null;
-
- // Number of mandatory resources, this is added to avoid invoke
- // MandatoryResources.values().length, since values() internally will
- // copy array, etc.
- private static final int NUM_MANDATORY_RESOURCES = 2;
-
- protected enum MandatoryResources {
- MEMORY(0), VCORES(1);
-
- private final int id;
-
- MandatoryResources(int id) {
- this.id = id;
- }
-
- public int getId() {
- return this.id;
- }
- }
public BaseResource() {
// Base constructor.
}
public BaseResource(long memory, long vcores) {
- this.memoryResInfo = ResourceInformation.newInstance(MEMORY,
- ResourceInformation.MEMORY_MB.getUnits(), memory);
- this.vcoresResInfo = ResourceInformation.newInstance(VCORES, "", vcores);
+ this.memoryResInfo = BaseResource.newDefaultMemoryInformation(memory);
+ this.vcoresResInfo = BaseResource.newDefaultVCoresInformation(vcores);
resources = new ResourceInformation[NUM_MANDATORY_RESOURCES];
- readOnlyResources = new ResourceInformation[NUM_MANDATORY_RESOURCES];
- resources[MandatoryResources.MEMORY.id] = memoryResInfo;
- resources[MandatoryResources.VCORES.id] = vcoresResInfo;
- readOnlyResources = Arrays.copyOf(resources, resources.length);
+ resources[MEMORY_INDEX] = memoryResInfo;
+ resources[VCORES_INDEX] = vcoresResInfo;
+ }
+
+ public static ResourceInformation newDefaultMemoryInformation(long value) {
+ ResourceInformation ri = new ResourceInformation();
+ ri.setName(ResourceInformation.MEMORY_URI);
+ ri.setValue(value);
+ ri.setResourceType(ResourceTypes.COUNTABLE);
+ ri.setUnitsWithoutValidation(MEMORY_MB.getUnits());
+ ri.setMinimumAllocation(0);
+ ri.setMaximumAllocation(Long.MAX_VALUE);
+ return ri;
+ }
+
+ public static ResourceInformation newDefaultVCoresInformation(long value) {
+ ResourceInformation ri = new ResourceInformation();
+ ri.setName(ResourceInformation.VCORES_URI);
+ ri.setValue(value);
+ ri.setResourceType(ResourceTypes.COUNTABLE);
+ ri.setUnitsWithoutValidation("");
+ ri.setMinimumAllocation(0);
+ ri.setMaximumAllocation(Long.MAX_VALUE);
+ return ri;
}
@Override
@@ -131,7 +134,53 @@ public void setVirtualCores(int vcores) {
}
@Override
- public ResourceInformation[] getResources() {
- return readOnlyResources;
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof Resource)) {
+ return false;
+ }
+ Resource other = (Resource) obj;
+ if (getMemorySize() != other.getMemorySize()
+ || getVirtualCores() != other.getVirtualCores()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int compareTo(Resource other) {
+ // compare memory and vcores first(in that order) to preserve
+ // existing behaviour
+ long diff = this.getMemorySize() - other.getMemorySize();
+ if (diff == 0) {
+ return this.getVirtualCores() - other.getVirtualCores();
+ }
+ return (int) Math.signum(diff);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("");
+ return sb.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 263167;
+
+ // prime * result = 939769357 initially
+ int result = (int) (939769357 + getMemorySize());
+ result = prime * result + getVirtualCores();
+
+ return result;
}
}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java
index ff22dd019c3..853078256ce 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java
@@ -40,7 +40,7 @@
@Private
@Unstable
-public class ResourcePBImpl extends BaseResource {
+public class ResourcePBImpl extends Resource {
private static final Log LOG = LogFactory.getLog(ResourcePBImpl.class);
@@ -95,7 +95,7 @@ public int getMemory() {
@Override
public long getMemorySize() {
// memory should always be present
- ResourceInformation ri = resources[MandatoryResources.MEMORY.getId()];
+ ResourceInformation ri = resources[MEMORY_INDEX];
if (ri.getUnits().isEmpty()) {
return ri.getValue();
@@ -119,7 +119,7 @@ public void setMemorySize(long memory) {
@Override
public int getVirtualCores() {
// vcores should always be present
- return (int) resources[MandatoryResources.VCORES.getId()].getValue();
+ return (int) resources[VCORES_INDEX].getValue();
}
@Override
@@ -156,7 +156,6 @@ private void initResources() {
resources[index].setValue(value);
}
}
- readOnlyResources = Arrays.copyOf(resources, resources.length);
this.setMemorySize(p.getMemory());
this.setVirtualCores(p.getVirtualCores());
}
@@ -212,7 +211,6 @@ private void initResourcesMap() {
}
resources = new ResourceInformation[types.length];
- readOnlyResources = new ResourceInformation[types.length];
for (ResourceInformation entry : types) {
int index = ResourceUtils.getResourceTypeIndex().get(entry.getName());
resources[index] = ResourceInformation.newInstance(entry);
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java
index ffd4fec0ee0..acc3cd3b989 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java
@@ -73,8 +73,7 @@ private int compare(Resource lhs, Resource rhs) {
boolean rhsGreater = false;
int ret = 0;
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation lhsResourceInformation = lhs
.getResourceInformation(i);
ResourceInformation rhsResourceInformation = rhs
@@ -111,10 +110,12 @@ public int compare(Resource clusterResource, Resource lhs, Resource rhs,
// resources and then look for which resource has the biggest
// share overall.
ResourceInformation[] clusterRes = clusterResource.getResources();
+ int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
+
// If array creation shows up as a time sink, these arrays could be cached
// because they're always the same length.
- double[] lhsShares = new double[clusterRes.length];
- double[] rhsShares = new double[clusterRes.length];
+ double[] lhsShares = new double[maxLength];
+ double[] rhsShares = new double[maxLength];
double diff;
try {
@@ -124,7 +125,7 @@ public int compare(Resource clusterResource, Resource lhs, Resource rhs,
calculateShares(clusterRes, lhs, rhs, lhsShares, rhsShares, max);
diff = max[0] - max[1];
- } else if (clusterRes.length == 2) {
+ } else if (maxLength == 2) {
// Special case to handle the common scenario of only CPU and memory
// so that we can optimize for performance
diff = calculateSharesForMandatoryResources(clusterRes, lhs, rhs,
@@ -182,7 +183,7 @@ private void calculateShares(ResourceInformation[] clusterRes, Resource first,
ResourceInformation[] firstRes = first.getResources();
ResourceInformation[] secondRes = second.getResources();
- for (int i = 0; i < clusterRes.length; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
firstShares[i] = calculateShare(clusterRes[i], firstRes[i]);
secondShares[i] = calculateShare(clusterRes[i], secondRes[i]);
}
@@ -215,7 +216,7 @@ private int calculateSharesForMandatoryResources(
int firstSub = 0;
int secondSub = 0;
- for (int i = 0; i < clusterRes.length; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
firstShares[i] = calculateShare(clusterRes[i], firstRes[i]);
secondShares[i] = calculateShare(clusterRes[i], secondRes[i]);
@@ -280,7 +281,7 @@ private void calculateShares(ResourceInformation[] clusterRes, Resource first,
max[0] = 0.0;
max[1] = 0.0;
- for (int i = 0; i < clusterRes.length; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
firstShares[i] = calculateShare(clusterRes[i], firstRes[i]);
secondShares[i] = calculateShare(clusterRes[i], secondRes[i]);
@@ -339,8 +340,7 @@ private double compareShares(double[] lhsShares, double[] rhsShares) {
public long computeAvailableContainers(Resource available,
Resource required) {
long min = Long.MAX_VALUE;
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation availableResource = available
.getResourceInformation(i);
ResourceInformation requiredResource = required.getResourceInformation(i);
@@ -358,11 +358,12 @@ public long computeAvailableContainers(Resource available,
@Override
public float divide(Resource clusterResource,
Resource numerator, Resource denominator) {
+ int nKnownResourceTypes = ResourceUtils.getNumberOfKnownResourceTypes();
ResourceInformation[] clusterRes = clusterResource.getResources();
// We have to provide the calculateShares() method with somewhere to store
// the shares. We don't actually need these shares afterwards.
- double[] numeratorShares = new double[clusterRes.length];
- double[] denominatorShares = new double[clusterRes.length];
+ double[] numeratorShares = new double[nKnownResourceTypes];
+ double[] denominatorShares = new double[nKnownResourceTypes];
// We also have to provide a place for calculateShares() to store the max
// shares so that we can use them.
double[] max = new double[2];
@@ -386,8 +387,7 @@ public boolean isInvalidDivisor(Resource r) {
@Override
public float ratio(Resource a, Resource b) {
float ratio = 0.0f;
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation aResourceInformation = a.getResourceInformation(i);
ResourceInformation bResourceInformation = b.getResourceInformation(i);
long bResourceValue = UnitsConversionUtil.convert(
@@ -407,8 +407,7 @@ public Resource divideAndCeil(Resource numerator, int denominator) {
public Resource divideAndCeil(Resource numerator, long denominator) {
Resource ret = Resource.newInstance(numerator);
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation resourceInformation = ret.getResourceInformation(i);
resourceInformation
.setValue(divideAndCeil(resourceInformation.getValue(), denominator));
@@ -428,8 +427,7 @@ public Resource divideAndCeil(Resource numerator, float denominator) {
public Resource normalize(Resource r, Resource minimumResource,
Resource maximumResource, Resource stepFactor) {
Resource ret = Resource.newInstance(r);
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation rResourceInformation = r.getResourceInformation(i);
ResourceInformation minimumResourceInformation = minimumResource
.getResourceInformation(i);
@@ -474,8 +472,7 @@ public Resource roundDown(Resource r, Resource stepFactor) {
private Resource rounding(Resource r, Resource stepFactor, boolean roundUp) {
Resource ret = Resource.newInstance(r);
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation rResourceInformation = r.getResourceInformation(i);
ResourceInformation stepFactorResourceInformation = stepFactor
.getResourceInformation(i);
@@ -513,8 +510,7 @@ public Resource multiplyAndNormalizeDown(Resource r, double by,
private Resource multiplyAndNormalize(Resource r, double by,
Resource stepFactor, boolean roundUp) {
Resource ret = Resource.newInstance(r);
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation rResourceInformation = r.getResourceInformation(i);
ResourceInformation stepFactorResourceInformation = stepFactor
.getResourceInformation(i);
@@ -542,8 +538,7 @@ private Resource multiplyAndNormalize(Resource r, double by,
@Override
public boolean fitsIn(Resource cluster, Resource smaller, Resource bigger) {
- int maxLength = ResourceUtils.getResourceTypesArray().length;
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
ResourceInformation sResourceInformation = smaller
.getResourceInformation(i);
ResourceInformation bResourceInformation = bigger
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
index 1e2ce155505..b804f2638c6 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
@@ -117,7 +117,6 @@ private void initResourceMap() {
ResourceInformation[] types = ResourceUtils.getResourceTypesArray();
if (types != null) {
resources = new ResourceInformation[types.length];
- readOnlyResources = new ResourceInformation[types.length];
for (int index = 0; index < types.length; index++) {
resources[index] = ResourceInformation.newInstance(types[index]);
resources[index].setValue(resourceValue);
@@ -129,7 +128,6 @@ private void initResourceMap() {
}
}
}
- readOnlyResources = Arrays.copyOf(resources, resources.length);
}
}
@@ -177,8 +175,7 @@ public static Resource clone(Resource res) {
}
public static Resource addTo(Resource lhs, Resource rhs) {
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = rhs.getResourceInformation(i);
ResourceInformation lhsValue = lhs.getResourceInformation(i);
@@ -201,8 +198,7 @@ public static Resource add(Resource lhs, Resource rhs) {
}
public static Resource subtractFrom(Resource lhs, Resource rhs) {
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = rhs.getResourceInformation(i);
ResourceInformation lhsValue = lhs.getResourceInformation(i);
@@ -247,8 +243,7 @@ public static Resource negate(Resource resource) {
}
public static Resource multiplyTo(Resource lhs, double by) {
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation lhsValue = lhs.getResourceInformation(i);
lhs.setResourceValue(i, (long) (lhsValue.getValue() * by));
@@ -270,8 +265,7 @@ public static Resource multiply(Resource lhs, double by) {
*/
public static Resource multiplyAndAddTo(
Resource lhs, Resource rhs, double by) {
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = rhs.getResourceInformation(i);
ResourceInformation lhsValue = lhs.getResourceInformation(i);
@@ -303,8 +297,7 @@ public static Resource multiplyAndNormalizeDown(
public static Resource multiplyAndRoundDown(Resource lhs, double by) {
Resource out = clone(lhs);
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation lhsValue = lhs.getResourceInformation(i);
out.setResourceValue(i, (long) (lhsValue.getValue() * by));
@@ -412,8 +405,7 @@ public static Resource max(
}
public static boolean fitsIn(Resource smaller, Resource bigger) {
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = bigger.getResourceInformation(i);
ResourceInformation lhsValue = smaller.getResourceInformation(i);
@@ -440,8 +432,7 @@ public static boolean fitsIn(ResourceCalculator rc, Resource cluster,
public static Resource componentwiseMin(Resource lhs, Resource rhs) {
Resource ret = createResource(0);
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = rhs.getResourceInformation(i);
ResourceInformation lhsValue = lhs.getResourceInformation(i);
@@ -464,8 +455,7 @@ public static Resource componentwiseMin(Resource lhs, Resource rhs) {
public static Resource componentwiseMax(Resource lhs, Resource rhs) {
Resource ret = createResource(0);
- int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
- for (int i = 0; i < maxLength; i++) {
+ for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) {
try {
ResourceInformation rhsValue = rhs.getResourceInformation(i);
ResourceInformation lhsValue = lhs.getResourceInformation(i);