Skip to content

Commit

Permalink
Remove Boolean classes. use client.unwrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
HoustonPutman committed Jan 8, 2025
1 parent 33be925 commit 7586f77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GetDataBuilderImpl implements GetDataBuilder, BackgroundOperation<S
private Stat responseStat;
private Watching watching;
private Backgrounding backgrounding;
private Boolean decompress;
private boolean decompress;

GetDataBuilderImpl(CuratorFrameworkImpl client) {
this.client = client;
Expand All @@ -54,12 +54,12 @@ public GetDataBuilderImpl(
Stat responseStat,
Watcher watcher,
Backgrounding backgrounding,
Boolean decompress) {
boolean decompress) {
this.client = client;
this.responseStat = responseStat;
this.watching = new Watching(client, watcher);
this.backgrounding = backgrounding;
this.decompress = decompress != null ? decompress : client.compressionEnabled();
this.decompress = decompress;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public interface AsyncTransactionCreateBuilder extends AsyncPathAndBytesable<Cur
* @see #compressed()
* @return this
*/
AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, Boolean compressed);
AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, boolean compressed);

/**
* Specify mode, acl list, compression and ttl
Expand All @@ -97,5 +97,5 @@ public interface AsyncTransactionCreateBuilder extends AsyncPathAndBytesable<Cur
* @return this
*/
AsyncPathAndBytesable<CuratorOp> withOptions(
CreateMode createMode, List<ACL> aclList, Boolean compressed, long ttl);
CreateMode createMode, List<ACL> aclList, boolean compressed, long ttl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,16 @@ public AsyncPathAndBytesable<CuratorOp> withTtl(long ttl) {

@Override
public AsyncPathAndBytesable<CuratorOp> withOptions(
CreateMode createMode, List<ACL> aclList, Boolean compressed) {
CreateMode createMode, List<ACL> aclList, boolean compressed) {
return withOptions(createMode, aclList, compressed, ttl);
}

@Override
public AsyncPathAndBytesable<CuratorOp> withOptions(
CreateMode createMode, List<ACL> aclList, Boolean compressed, long ttl) {
CreateMode createMode, List<ACL> aclList, boolean compressed, long ttl) {
this.createMode = Objects.requireNonNull(createMode, "createMode cannot be null");
this.aclList = aclList;
if (compressed == Boolean.TRUE) {
this.compressed = true;
} else if (compressed == Boolean.FALSE) {
this.compressed = false;
}
this.compressed = compressed;
this.ttl = ttl;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,10 @@ public AsyncStage<Stat> update(T item, int version) {
byte[] bytes = modelSpec.serializer().serialize(item);
AsyncSetDataBuilder dataBuilder = dslClient.setData();
AsyncPathAndBytesable<AsyncStage<Stat>> next;
Boolean isCompressed = isCompressed();
if (isCompressed == Boolean.TRUE) {
if (isCompressed()) {
next = dataBuilder.compressedWithVersion(version);
} else if (isCompressed == Boolean.FALSE) {
next = dataBuilder.uncompressedWithVersion(version);
} else {
next = dataBuilder.withVersion(version);
next = dataBuilder.uncompressedWithVersion(version);
}
return next.forPath(resolveForSet(item), bytes);
} catch (Exception e) {
Expand Down Expand Up @@ -371,14 +368,11 @@ public CuratorOp updateOp(T model) {
@Override
public CuratorOp updateOp(T model, int version) {
AsyncTransactionSetDataBuilder builder = client.transactionOp().setData();
Boolean isCompressed = isCompressed();
AsyncPathAndBytesable<CuratorOp> builder2;
if (isCompressed == Boolean.TRUE) {
if (isCompressed()) {
builder2 = builder.withVersionCompressed(version);
} else if (isCompressed == Boolean.FALSE) {
builder2 = builder.withVersionUncompressed(version);
} else {
builder2 = builder.withVersion(version);
builder2 = builder.withVersionUncompressed(version);
}
return builder2.forPath(resolveForSet(model), modelSpec.serializer().serialize(model));
}
Expand Down Expand Up @@ -414,26 +408,23 @@ public AsyncStage<List<CuratorTransactionResult>> inTransaction(List<CuratorOp>
return client.transaction().forOperations(operations);
}

private Boolean isCompressed() {
private boolean isCompressed() {
if (modelSpec.createOptions().contains(CreateOption.compress)) {
return Boolean.TRUE;
return true;
} else if (modelSpec.createOptions().contains(CreateOption.uncompress)) {
return Boolean.FALSE;
return false;
} else {
return null;
return client.unwrap().compressionEnabled();
}
}

private <U> ModelStage<U> internalRead(Function<ZNode<T>, U> resolver, Stat storingStatIn) {
Stat stat = (storingStatIn != null) ? storingStatIn : new Stat();
AsyncPathable<AsyncStage<byte[]>> next;
Boolean isCompressed = isCompressed();
if (isCompressed == Boolean.TRUE) {
if (isCompressed()) {
next = watchableClient.getData().decompressedStoringStatIn(stat);
} else if (isCompressed == Boolean.FALSE) {
next = watchableClient.getData().undecompressedStoringStatIn(stat);
} else {
next = watchableClient.getData().storingStatIn(stat);
next = watchableClient.getData().undecompressedStoringStatIn(stat);
}
AsyncStage<byte[]> asyncStage = next.forPath(modelSpec.path().fullPath());
ModelStage<U> modelStage = ModelStage.make(asyncStage.event());
Expand Down

0 comments on commit 7586f77

Please sign in to comment.