if the string is empty after replacement,return creation time.

This commit is contained in:
CCTV-1
2021-03-06 11:16:23 +08:00
parent 68b36b8890
commit a11ab7d007

View File

@@ -19,6 +19,8 @@ package forge.deck;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public abstract class DeckBase implements Serializable, Comparable<DeckBase>, InventoryItem { public abstract class DeckBase implements Serializable, Comparable<DeckBase>, InventoryItem {
private static final long serialVersionUID = -7538150536939660052L; private static final long serialVersionUID = -7538150536939660052L;
@@ -145,9 +147,9 @@ public abstract class DeckBase implements Serializable, Comparable<DeckBase>, In
public final String getBestFileName() { public final String getBestFileName() {
//string operator hard to guarantee filename legal,only replace some not allowed as file names characters //string operator hard to guarantee filename legal,only replace some not allowed as file names characters
final String result = name.replaceAll("[\\/:*?\"<>|]",""); final String result = name.replaceAll("[\\/:*?\"<>|]","");
if (result == "") { if (result.isEmpty()) {
//"getBestFileName" sha1 value final String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm"));
return "bc2b4ac6bf8dd84112c79e4c733b0b5bd8f057b3"; return createTime;
} }
return result; return result;
} }