net.sf.jabb.util.text
Class NameDeduplicator

java.lang.Object
  extended by net.sf.jabb.util.text.NameDeduplicator

public class NameDeduplicator
extends Object

This utility class can rename names by appending numbers to avoid name duplication, it is multi-thread safe.
这个工具类可以通过给名称后面添加数字的方式来为避免重名而自动改名,它是多线程安全的。

Author:
Zhengmao HU (James)

Field Summary
protected  PutOnGetMap<String,Sequencer> nameSequencers
           
protected  String renamePattern
           
 
Constructor Summary
NameDeduplicator()
          Constructs an instance with " (%d)" as the postfix pattern.
创建一个实例,以" (%d)"作为后缀模版。
NameDeduplicator(String postfixPattern)
          Constructs an instance with specified postfix pattern.
创建一个实例,使用指定的后缀模板。
 
Method Summary
 String deduplicate(String name)
          Ensure a unique name, rename if needed.
确保名称不重复,如果有必要就改名。
 long nextId(String name)
          Get the next sequential id for specified name.
取得指定名称的下一个不重复Id值。
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameSequencers

protected PutOnGetMap<String,Sequencer> nameSequencers

renamePattern

protected String renamePattern
Constructor Detail

NameDeduplicator

public NameDeduplicator(String postfixPattern)
Constructs an instance with specified postfix pattern.
创建一个实例,使用指定的后缀模板。

Parameters:
postfixPattern - Patten for the postfix to be appended, for example, " (%d)" or "_%d"
后缀模版,比如" (%d)"或"_%d"。

NameDeduplicator

public NameDeduplicator()
Constructs an instance with " (%d)" as the postfix pattern.
创建一个实例,以" (%d)"作为后缀模版。

Method Detail

deduplicate

public String deduplicate(String name)
Ensure a unique name, rename if needed.
确保名称不重复,如果有必要就改名。

This method is multi-threads safe.

这个方法是多线程安全的。

Parameters:
name - The original name
原名称
Returns:
Same as the original name if or renamed
与原名称相同,或被自动改名

nextId

public long nextId(String name)
Get the next sequential id for specified name.
取得指定名称的下一个不重复Id值。

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,依此类推。 这个方法是多线程安全的。

Parameters:
name - The specified name
指定的名称
Returns:
next sequential id
下一个不重复Id值


Copyright © 2012. All Rights Reserved.