Skip to content

Commit

Permalink
Merge branch 'master' into optimize_startup_script
Browse files Browse the repository at this point in the history
  • Loading branch information
Aias00 authored Jan 18, 2025
2 parents 107d26a + 6907654 commit 8c88540
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package org.apache.shenyu.registry.api.config;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;
import java.util.Properties;

/**
Expand Down Expand Up @@ -127,7 +130,7 @@ public void setEnabled(final boolean enabled) {

@Override
public boolean equals(final Object obj) {
if (obj == null) {
if (Objects.isNull(obj)) {
return false;
}
RegisterConfig registerConfig = (RegisterConfig) obj;
Expand All @@ -137,18 +140,20 @@ public boolean equals(final Object obj) {
if (!this.getServerLists().equals(registerConfig.getServerLists())) {
return false;
}
if (this.getProps() == null && registerConfig.getProps() == null) {
Properties properties = this.getProps();
Properties registerConfigProps = registerConfig.getProps();
if (Objects.isNull(properties) && Objects.isNull(registerConfigProps)) {
return true;
}
if (this.getProps() == null || registerConfig.getProps() == null) {
if (Objects.isNull(properties) || Objects.isNull(registerConfigProps)) {
return false;
}
if (this.getProps().entrySet().size() != registerConfig.getProps().entrySet().size()) {
if (properties.entrySet().size() != registerConfigProps.entrySet().size()) {
return false;
}
for (Map.Entry<Object, Object> entry : this.getProps().entrySet()) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object newValue = entry.getValue();
Object oldValue = registerConfig.getProps().get(entry.getKey());
Object oldValue = registerConfigProps.get(entry.getKey());
if (!newValue.equals(oldValue)) {
return false;
}
Expand All @@ -158,13 +163,18 @@ public boolean equals(final Object obj) {

@Override
public int hashCode() {
int result = getRegisterType() != null ? getRegisterType().hashCode() : 0;
result = 31 * result + (getServerLists() != null ? getServerLists().hashCode() : 0);
String registerTypeStr = getRegisterType();
int result = StringUtils.isNotEmpty(registerTypeStr) ? registerTypeStr.hashCode() : 0;
String serverListsStr = getServerLists();
result = 31 * result + (StringUtils.isNotEmpty(serverListsStr) ? serverListsStr.hashCode() : 0);

if (getProps() != null) {
for (Map.Entry<Object, Object> entry : getProps().entrySet()) {
result = 31 * result + (entry.getKey() != null ? entry.getKey().hashCode() : 0);
result = 31 * result + (entry.getValue() != null ? entry.getValue().hashCode() : 0);
Properties properties = getProps();
if (Objects.nonNull(properties)) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object entryKey = entry.getKey();
result = 31 * result + (Objects.nonNull(entryKey) ? entryKey.hashCode() : 0);
Object entryValue = entry.getValue();
result = 31 * result + (Objects.nonNull(entryValue) ? entryValue.hashCode() : 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public boolean equals(final Object o) {
return Boolean.TRUE;
}

if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return Boolean.FALSE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
Expand All @@ -46,10 +47,10 @@ public KubernetesClient(final KubernetesConfig kubernetesConfig) {
*/
public List<KubernetesInstance> selectInstances(final String serviceId) {
List<KubernetesInstance> response = Collections.emptyList();
KubernetesInstance[] responseBody = (KubernetesInstance[]) this.rest.getForEntity(this.kubernetesConfig.getDiscoveryServerUrl() + "/apps/" + serviceId,
KubernetesInstance[] responseBody = this.rest.getForEntity(this.kubernetesConfig.getDiscoveryServerUrl() + "/apps/" + serviceId,
KubernetesInstance[].class, new Object[0]).getBody();
if (responseBody != null && responseBody.length > 0) {
response = (List) Arrays.stream(responseBody).filter(this::matchNamespaces).collect(Collectors.toList());
if (Objects.nonNull(responseBody) && responseBody.length > 0) {
response = Arrays.stream(responseBody).filter(this::matchNamespaces).collect(Collectors.toList());
}

return response;
Expand Down

0 comments on commit 8c88540

Please sign in to comment.