Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add equals and hashCode to ModifySplitBrainResolver and ModifySplitBrainResolverResponse; add package-info.java; Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
- Loading branch information
Stefan Maute
committed
May 3, 2022
1 parent
fa019f0
commit e02e044
Showing
5 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,18 @@ | |
*/ | ||
package org.eclipse.ditto.base.service.cluster; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.eclipse.ditto.base.model.common.HttpStatus; | ||
import org.eclipse.ditto.base.model.headers.DittoHeaders; | ||
import org.eclipse.ditto.base.model.json.FieldType; | ||
import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; | ||
import org.eclipse.ditto.base.model.json.JsonSchemaVersion; | ||
import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; | ||
import org.eclipse.ditto.base.model.signals.commands.CommandResponseJsonDeserializer; | ||
import org.eclipse.ditto.json.JsonField; | ||
import org.eclipse.ditto.json.JsonFieldDefinition; | ||
import org.eclipse.ditto.json.JsonObject; | ||
import org.eclipse.ditto.json.JsonObjectBuilder; | ||
import org.eclipse.ditto.json.JsonPointer; | ||
|
@@ -31,9 +32,6 @@ | |
public final class ModifySplitBrainResolverResponse | ||
extends AbstractCommandResponse<ModifySplitBrainResolverResponse> { | ||
|
||
private static final JsonFieldDefinition<Boolean> ENABLED = | ||
JsonFieldDefinition.ofBoolean("enabled", FieldType.REGULAR, JsonSchemaVersion.V_2); | ||
|
||
static final String PREFIX = "ditto.sbr:"; | ||
static final String NAME = "modifyResponse"; | ||
public static final String TYPE = PREFIX + NAME; | ||
|
@@ -42,7 +40,7 @@ public final class ModifySplitBrainResolverResponse | |
CommandResponseJsonDeserializer.newInstance(TYPE, | ||
context -> { | ||
final JsonObject jsonObject = context.getJsonObject(); | ||
final boolean enabled = jsonObject.getValue(ENABLED).orElseThrow(); | ||
final boolean enabled = jsonObject.getValue(ModifySplitBrainResolver.ENABLED_FIELD_KEY).orElseThrow(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Yannic92
Contributor
|
||
return new ModifySplitBrainResolverResponse(context.getDittoHeaders(), enabled); | ||
}); | ||
|
||
|
@@ -70,7 +68,7 @@ public static ModifySplitBrainResolverResponse fromJson(final JsonObject jsonObj | |
@Override | ||
protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, | ||
final Predicate<JsonField> predicate) { | ||
jsonObjectBuilder.set(ENABLED, enabled, schemaVersion.and(predicate)); | ||
jsonObjectBuilder.set(ModifySplitBrainResolver.ENABLED_FIELD_KEY, enabled, schemaVersion.and(predicate)); | ||
} | ||
|
||
@Override | ||
|
@@ -88,4 +86,34 @@ public ModifySplitBrainResolverResponse setDittoHeaders(final DittoHeaders ditto | |
return new ModifySplitBrainResolverResponse(dittoHeaders, enabled); | ||
} | ||
|
||
@Override | ||
protected boolean canEqual(@Nullable final Object other) { | ||
return other instanceof ModifySplitBrainResolverResponse; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) return false; | ||
final ModifySplitBrainResolverResponse that = (ModifySplitBrainResolverResponse) o; | ||
return enabled == that.enabled; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), enabled); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [" + | ||
"enabled=" + enabled + | ||
"]"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
base/service/src/main/java/org/eclipse/ditto/base/service/cluster/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
@org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault | ||
package org.eclipse.ditto.base.service.cluster; |
I don't like the reuse of fields of another signal that are named equally more or less by accident