Skip to content

Commit

Permalink
Remove useless equals and hashcode on StorageUnitNodeMapper (#28611)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Sep 27, 2023
1 parent abc51b5 commit ff79177
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shardingsphere.infra.metadata.database.resource.unit;

import com.google.common.base.Objects;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
Expand All @@ -33,29 +32,11 @@ public final class StorageUnitNodeMapper {

private final StorageNode storageNode;

private final String catalog;

private final String url;

public StorageUnitNodeMapper(final String name, final StorageNode storageNode, final String url) {
this(name, storageNode, null, url);
}

@Override
public boolean equals(final Object obj) {
if (obj instanceof StorageUnitNodeMapper) {
StorageUnitNodeMapper storageUnitNodeMapper = (StorageUnitNodeMapper) obj;
return storageUnitNodeMapper.name.equalsIgnoreCase(name) && storageUnitNodeMapper.storageNode.equals(storageNode) && isSameCatalog(storageUnitNodeMapper);
}
return false;
}

private boolean isSameCatalog(final StorageUnitNodeMapper storageUnitNodeMapper) {
return null == catalog ? null == storageUnitNodeMapper : catalog.equalsIgnoreCase(storageUnitNodeMapper.getCatalog());
}
private final String catalog;

@Override
public int hashCode() {
return Objects.hashCode(name.toUpperCase(), storageNode.getName().toUpperCase(), null == catalog ? null : catalog.toUpperCase());
public StorageUnitNodeMapper(final String name, final StorageNode storageNode, final String url) {
this(name, storageNode, url, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static String generateStorageNodeName(final String hostname, final int p

private static StorageUnitNodeMapper createStorageUnitNodeMapper(final StorageNode storageNode, final String storageUnitName, final String url, final boolean isInstanceConnectionAvailable) {
return isInstanceConnectionAvailable
? new StorageUnitNodeMapper(storageUnitName, storageNode, new StandardJdbcUrlParser().parse(url).getDatabase(), url)
? new StorageUnitNodeMapper(storageUnitName, storageNode, url, new StandardJdbcUrlParser().parse(url).getDatabase())
: new StorageUnitNodeMapper(storageUnitName, storageNode, url);
}

Expand Down

0 comments on commit ff79177

Please sign in to comment.