Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless equals and hashcode on StorageUnitNodeMapper #28611

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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