-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
9 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
62 changes: 62 additions & 0 deletions
62
src/main/java/io/tarantool/driver/protocol/TarantoolRequestSignature.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,62 @@ | ||
package io.tarantool.driver.protocol; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a request signature, uniquely defining the operation and the argument types. | ||
* May include some argument values as well. | ||
* | ||
* @author Alexey Kuzin | ||
*/ | ||
public class TarantoolRequestSignature { | ||
|
||
private List<Object> components = new LinkedList<>(); | ||
private int hashCode = 1; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param initialComponents initial signature components, must be hashable | ||
*/ | ||
public TarantoolRequestSignature(Object... initialComponents) { | ||
for (Object component: initialComponents) { | ||
components.add(component); | ||
hashCode = 31 * hashCode + Objects.hashCode(component); | ||
} | ||
} | ||
|
||
/** | ||
* Add a signature component to the end of the components list | ||
* | ||
* @param component signature component, must be hashable | ||
* @return this signature object instance | ||
*/ | ||
public TarantoolRequestSignature addComponent(Object component) { | ||
components.add(component); | ||
hashCode = 31 * hashCode + Objects.hashCode(component); | ||
return this; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other instanceof TarantoolRequestSignature && | ||
Objects.equals(this.components, ((TarantoolRequestSignature) other).components); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder("["); | ||
for (Object component: components) { | ||
sb.append(String.valueOf(component)).append(","); | ||
} | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
} |
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