Skip to content

Commit 0a922a3

Browse files
Artem LabazinArtem Labazin
authored andcommitted
Redesigned Bytes.put(index, byte) logic
1 parent 7177551 commit 0a922a3

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Add more tests.
1313
- Add `JavaDoc`.
1414

15+
## [1.3.2](https://github.com/appulse-projects/utils-java/releases/tag/1.3.2) - 2018-02-14
16+
17+
### Changed
18+
19+
- Redesigned `Bytes.put(index, byte)` logic, now it moves `limit`.
20+
1521
## [1.3.1](https://github.com/appulse-projects/utils-java/releases/tag/1.3.1) - 2018-02-09
1622

1723
Minor release with unsigned numbers support.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
<groupId>io.appulse</groupId>
2626
<artifactId>utils-java</artifactId>
27-
<version>1.3.1</version>
27+
<version>1.3.2</version>
2828
<packaging>jar</packaging>
2929

3030
<properties>
@@ -62,7 +62,7 @@ limitations under the License.
6262
<url>https://github.com/appulse-projects/utils-java</url>
6363
<connection>scm:git:https://github.com/appulse-projects/utils-java.git</connection>
6464
<developerConnection>scm:git:https://github.com/appulse-projects/utils-java.git</developerConnection>
65-
<tag>1.3.1</tag>
65+
<tag>1.3.2</tag>
6666
</scm>
6767

6868
<distributionManagement>

src/main/java/io/appulse/utils/Bytes.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ public Bytes put (byte value) {
8686
}
8787

8888
public Bytes put (int index, byte value) {
89-
buffer.put(index, value);
89+
if (index < limit) {
90+
buffer.put(index, value);
91+
} else {
92+
put(value);
93+
}
9094
return this;
9195
}
9296

@@ -100,7 +104,7 @@ public Bytes put (@NonNull byte[] bytes) {
100104
public Bytes put (int index, @NonNull byte[] bytes) {
101105
checkCapacity(index, bytes.length);
102106
IntStream.range(index, index + bytes.length).forEach(it -> {
103-
buffer.put(it, bytes[it - index]);
107+
put(it, bytes[it - index]);
104108
});
105109
return this;
106110
}

src/test/java/io/appulse/utils/BytesTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,15 @@ public void limit () {
103103
bytes.put4B(4);
104104
assertThat(bytes.limit()).isEqualTo(4);
105105

106-
Bytes wrapped = Bytes.wrap(new byte[] { 1 });
107-
assertThat(wrapped.limit()).isEqualTo(1);
106+
Bytes wrapped = Bytes.wrap(new byte[] { 1, 0 });
107+
assertThat(wrapped.array()).isEqualTo(new byte[] { 1, 0 });
108+
assertThat(wrapped.limit()).isEqualTo(2);
109+
110+
wrapped.position(wrapped.limit());
111+
wrapped.put(1, new byte[] { 2, 3 });
112+
assertThat(wrapped.array()).isEqualTo(new byte[] { 1, 2, 3 });
113+
assertThat(wrapped.limit()).isEqualTo(3);
114+
assertThat(wrapped.position()).isEqualTo(3);
108115
}
109116

110117
@Test

0 commit comments

Comments
 (0)