-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/tronprotocol/java-tron i…
…nto develop
- Loading branch information
Showing
11 changed files
with
128 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,50 @@ | ||
package org.tron.common.utils; | ||
|
||
import java.util.Optional; | ||
import org.tron.core.db.AbstractRevokingStore.Dialog; | ||
|
||
import java.util.Optional; | ||
public final class DialogOptional { | ||
|
||
public class DialogOptional<T extends Dialog> { | ||
private static final DialogOptional<?> EMPTY = new DialogOptional<>(); | ||
private static final DialogOptional INSTANCE = OptionalEnum.INSTANCE.getInstance(); | ||
|
||
private Optional<T> value; | ||
private Optional<Dialog> value; | ||
|
||
private DialogOptional() { | ||
this.value = Optional.empty(); | ||
} | ||
|
||
public static <T extends Dialog> DialogOptional<T> empty() { | ||
@SuppressWarnings("unchecked") | ||
DialogOptional<T> t = (DialogOptional<T>) EMPTY; | ||
return t; | ||
public synchronized DialogOptional setValue(Dialog value) { | ||
if (!this.value.isPresent()) { | ||
this.value = Optional.of(value); | ||
} | ||
return this; | ||
} | ||
|
||
private DialogOptional(T value) { | ||
this.value = Optional.of(value); | ||
public synchronized boolean valid() { | ||
return value.isPresent(); | ||
} | ||
|
||
public static <T extends Dialog> DialogOptional<T> of(T value) { | ||
return new DialogOptional<>(value); | ||
public synchronized void reset() { | ||
value.ifPresent(Dialog::destroy); | ||
value = Optional.empty(); | ||
} | ||
|
||
public static <T extends Dialog> DialogOptional<T> ofNullable(T value) { | ||
return value == null ? empty() : of(value); | ||
public static DialogOptional instance() { | ||
return INSTANCE; | ||
} | ||
|
||
public boolean valid() { | ||
return value.isPresent(); | ||
} | ||
private enum OptionalEnum { | ||
INSTANCE; | ||
|
||
public void reset() { | ||
value.ifPresent(Dialog::destroy); | ||
value = Optional.empty(); | ||
private DialogOptional instance; | ||
|
||
OptionalEnum() { | ||
instance = new DialogOptional(); | ||
} | ||
|
||
private DialogOptional getInstance() { | ||
return instance; | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -149,5 +149,6 @@ public static void destroy() { | |
} else { | ||
logger.info("Release resources failure."); | ||
} | ||
dbManager.destory(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -126,5 +126,6 @@ public static void destroy() { | |
} else { | ||
logger.info("Release resources failure."); | ||
} | ||
dbManager.destory(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -209,5 +209,6 @@ public static void destroy() { | |
} else { | ||
logger.info("Release resources failure."); | ||
} | ||
dbManager.destory(); | ||
} | ||
} |
Empty file.
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