String (@Nullable String memoryValueA, @Nullable String memoryValueB) { MemoryProperty propertyA = MemoryProperty.valueOf(memoryValueA); MemoryProperty propertyB = MemoryProperty.valueOf(memoryValueB); if (propertyA != null && propertyB != null) { MemoryProperty maxMemoryProperty = propertyA.valueBytes > propertyB.valueBytes ? propertyA : propertyB; return MemoryProperty.of(MemoryProperty.MemoryPropertyType.XMX, maxMemoryProperty.valueBytes).toString(maxMemoryProperty.unit); } return Optional .ofNullable(propertyA).or(() -> Optional.ofNullable(propertyB)) .map(property -> MemoryProperty.of(MemoryProperty.MemoryPropertyType.XMX, property.valueBytes).toString(property.unit)) .orElse(null); }