Skip to content

Commit

Permalink
Fixed Name semantics issue: Added EMPTY_NAME, interpret "" now as one…
Browse files Browse the repository at this point in the history
… component name.
  • Loading branch information
siberski authored and dirkriehle committed Aug 4, 2010
1 parent 73c9b50 commit ab94eed
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 94 deletions.
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Mon Aug 02 10:35:22 CEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
26 changes: 18 additions & 8 deletions src/org/jvalue/names/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ public class Name implements Serializable {
public static final char DEFAULT_DELIMITER_CHAR = '#';
public static final char DEFAULT_ESCAPE_CHAR = '\\';

/**
* The empty name is a name with no components and default delimiter.
*/
public static final Name EMPTY_NAME = new Name();

/**
* Represents name as a single string
*/
protected String name;
protected String name = null;

/**
* Saves number of components for performance reasons
Expand Down Expand Up @@ -86,13 +91,22 @@ public Name(List<String> components) {
* @param escape Escape character to use when parsing string
*/
public Name(String name, char delimiter, char escape) {
assert name != null;

if ((delimiter != getDelimiterChar()) || (escape != getEscapeChar())) {
name = switchDelEscScheme(name, delimiter, escape, getDelimiterChar(), getEscapeChar());
}

this.name = name;
}

/**
* Used for empty no components name.
*/
protected Name() {
this.name = null;
}

/**
*
*/
Expand Down Expand Up @@ -205,18 +219,14 @@ public char getEscapeChar() {
*
*/
public boolean isEmpty() {
return name.equals("");
return name == null; // return name.equals("");
}

/**
*
*/
public Name getContextName() {
assertIsValidIndex(getNoComponents() - 1);
if (getNoComponents() == 1) {
return new Name("");
}

assertIsValidIndex(getNoComponents() - 2);
int endPos = getIndexOfEndOfComponent(getNoComponents() - 2);
return new Name(name.substring(0, endPos));
}
Expand Down Expand Up @@ -355,7 +365,7 @@ protected String switchDelEscScheme(String name, char fromDel, char fromEsc, cha
StringBuilder result = new StringBuilder();
int length = name.length();
if (length != 0) {
for (int end = 0; end < length; end++) {
for (int end = 0; end <= length; end++) {
int startPos = end;
String component = "";
if (startPos < name.length()) {
Expand Down
Loading

0 comments on commit ab94eed

Please sign in to comment.