public class NameDeduplicator extends Object
Modifier and Type | Field and Description |
---|---|
protected PutIfAbsentMap<String,Sequencer> |
nameSequencers |
protected String |
renamePattern |
Constructor and Description |
---|
NameDeduplicator()
Constructs an instance with
" (%d)" as the postfix pattern.创建一个实例,以" (%d) "作为后缀模版。 |
NameDeduplicator(String postfixPattern)
Constructs an instance with specified postfix pattern.
创建一个实例,使用指定的后缀模板。 |
Modifier and Type | Method and Description |
---|---|
String |
deduplicate(String name)
Ensure a unique name, rename if needed.
确保名称不重复,如果有必要就改名。 |
long |
nextId(String name)
Get the next sequential id for specified name.
取得指定名称的下一个不重复Id值。 |
protected PutIfAbsentMap<String,Sequencer> nameSequencers
protected String renamePattern
public NameDeduplicator(String postfixPattern)
postfixPattern
- Patten for the postfix to be appended,
for example, " (%d)"
or "_%d"
(%d)
"或"_%d
"。public NameDeduplicator()
" (%d)"
as the postfix pattern. (%d)
"作为后缀模版。public String deduplicate(String name)
This method is multi-threads safe.
这个方法是多线程安全的。
name
- The original namepublic long nextId(String name)
For a specified name, the first time of invocation will return 0, the second time return 1, the third time return 2, so on and so forth. This method is multi-threads safe.
对于同一个名称,第一次调用返回的是0,第二次是1,第三次是2,依此类推。 这个方法是多线程安全的。
name
- The specified nameCopyright © 2014. All Rights Reserved.