forked from Merck/Halyard
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Mark Hale
committed
Nov 1, 2023
1 parent
237b138
commit efd28d6
Showing
5 changed files
with
62 additions
and
1 deletion.
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
48 changes: 48 additions & 0 deletions
48
common/src/main/java/com/msd/gin/halyard/vocab/IntegerPairNamespace.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,48 @@ | ||
package com.msd.gin.halyard.vocab; | ||
|
||
import com.msd.gin.halyard.common.AbstractIRIEncodingNamespace; | ||
import com.msd.gin.halyard.common.ValueIO; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class IntegerPairNamespace extends AbstractIRIEncodingNamespace { | ||
private static final long serialVersionUID = 571723932297421854L; | ||
|
||
private final String sep1; | ||
private final String sep2; | ||
|
||
IntegerPairNamespace(String prefix, String ns, String sep1, String sep2) { | ||
super(prefix, ns); | ||
this.sep1 = sep1; | ||
this.sep2 = sep2; | ||
} | ||
|
||
@Override | ||
public ByteBuffer writeBytes(String localName, ByteBuffer b) { | ||
int start1 = sep1.length(); | ||
int end1 = localName.indexOf(sep2, start1); | ||
if (end1 == -1) { | ||
throw new IllegalArgumentException("Unexpected input: "+localName); | ||
} | ||
int start2 = end1 + sep2.length(); | ||
int start = b.position(); | ||
b = ValueIO.ensureCapacity(b, 1); | ||
b.position(start + 1); | ||
b = ValueIO.writeCompressedInteger(localName.substring(start1, end1), b); | ||
int len1 = b.position() - start - 1; | ||
b = ValueIO.writeCompressedInteger(localName.substring(start2), b); | ||
b.put(start, (byte)len1); | ||
return b; | ||
} | ||
|
||
@Override | ||
public String readBytes(ByteBuffer b) { | ||
int len1 = b.get(); | ||
int originalLimit = b.limit(); | ||
b.limit(b.position() + len1); | ||
String first = ValueIO.readCompressedInteger(b); | ||
b.limit(originalLimit); | ||
String second = ValueIO.readCompressedInteger(b); | ||
return sep1 + first + sep2 + second; | ||
} | ||
} |
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