aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Bergeron2013-12-03 04:20:12 (EST)
committerMatthew Khouzam2013-12-04 09:25:02 (EST)
commit4fe61a7ad7bfafc4a14029d22608a7270a07456e (patch)
treeebc5f4160379aa962c5c3260cb01a20e611954e1
parent051438e9f95def2b6d7cb742c25cda2866339f93 (diff)
downloadorg.eclipse.linuxtools-4fe61a7ad7bfafc4a14029d22608a7270a07456e.zip
org.eclipse.linuxtools-4fe61a7ad7bfafc4a14029d22608a7270a07456e.tar.gz
org.eclipse.linuxtools-4fe61a7ad7bfafc4a14029d22608a7270a07456e.tar.bz2
ctf: Hide internal functionalities of StringDefinition.refs/changes/35/19235/3
The StringDefinition should not expose its internal data structures. The StringBuffer is a temporary buffer used by read. Nothing outside the 'read' method should ever play with this object. Change-Id: I2edda57f9208f4d1a56a3aa619545f803ea4278d Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com> Reviewed-on: https://git.eclipse.org/r/19235 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java29
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java46
4 files changed, 29 insertions, 50 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java
index aebbc4d..379dee4 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java
@@ -105,7 +105,7 @@ public class CTFEventFieldTest {
public void testParseField_simple3() {
StringDefinition fieldDef = new StringDefinition(
new StringDeclaration(), null, fieldName);
- fieldDef.setString(new StringBuilder("Hello World"));
+ fieldDef.setValue("Hello World");
String other = "\"Hello World\"";
assertNotNull(fieldDef);
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
index 8044e72..cb07c76 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
@@ -111,7 +111,7 @@ public class ArrayDefinitionTest {
String content = "test" + i;
defs[i] = new StringDefinition(
new StringDeclaration(Encoding.UTF8), null, content);
- defs[i].setString(new StringBuilder(content));
+ defs[i].setValue(content);
}
return defs;
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java
index aa89061..2d263ec 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.ctf.core.tests.types;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
@@ -63,29 +64,28 @@ public class StringDefinitionTest {
*/
@Test
public void testGetDeclaration() {
- fixture.setString(new StringBuilder());
StringDeclaration result = fixture.getDeclaration();
assertNotNull(result);
}
/**
- * Run the StringBuilder getString() method test.
+ * Run the String getValue() method test.
*/
@Test
- public void testGetString() {
- fixture.setString(new StringBuilder());
- StringBuilder result = fixture.getString();
+ public void testGetValue() {
+ String result = fixture.getValue();
assertNotNull(result);
}
/**
- * Run the String getValue() method test.
+ * Run the String setValue() method test.
*/
@Test
- public void testGetValue() {
- fixture.setString(new StringBuilder());
+ public void testSetValue() {
+ fixture.setValue("dummy");
String result = fixture.getValue();
assertNotNull(result);
+ assertEquals("dummy", result);
}
/**
@@ -94,7 +94,6 @@ public class StringDefinitionTest {
*/
@Test
public void testRead() throws CTFReaderException {
- fixture.setString(new StringBuilder());
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
fixture.read(input);
}
@@ -104,27 +103,15 @@ public class StringDefinitionTest {
*/
@Test
public void testSetDeclaration() {
- fixture.setString(new StringBuilder());
StringDeclaration declaration = new StringDeclaration();
fixture.setDeclaration(declaration);
}
/**
- * Run the void setString(StringBuilder) method test.
- */
- @Test
- public void testSetString() {
- fixture.setString(new StringBuilder());
- StringBuilder string = new StringBuilder();
- fixture.setString(string);
- }
-
- /**
* Run the String toString() method test.
*/
@Test
public void testToString() {
- fixture.setString(new StringBuilder());
String result = fixture.toString();
assertNotNull(result);
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java
index 6ed3c0c..ff27e84 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java
@@ -32,9 +32,9 @@ public class StringDefinition extends Definition {
// Attributes
// ------------------------------------------------------------------------
- private StringDeclaration declaration;
+ private StringDeclaration fDeclaration;
- private StringBuilder string;
+ private String fString;
// ------------------------------------------------------------------------
// Constructors
@@ -54,9 +54,9 @@ public class StringDefinition extends Definition {
IDefinitionScope definitionScope, String fieldName) {
super(definitionScope, fieldName);
- this.declaration = declaration;
+ fDeclaration = declaration;
- string = new StringBuilder();
+ fString = ""; //$NON-NLS-1$
}
// ------------------------------------------------------------------------
@@ -65,7 +65,7 @@ public class StringDefinition extends Definition {
@Override
public StringDeclaration getDeclaration() {
- return declaration;
+ return fDeclaration;
}
/**
@@ -75,35 +75,25 @@ public class StringDefinition extends Definition {
* the declaration
*/
public void setDeclaration(StringDeclaration declaration) {
- this.declaration = declaration;
+ fDeclaration = declaration;
}
/**
- * Gets the string
- *
- * @return the stringbuilder
- */
- public StringBuilder getString() {
- return string;
- }
-
- /**
- * Sets a stringbuilder for the definition
+ * Gets the string (value)
*
- * @param string
- * the stringbuilder
+ * @return the string
*/
- public void setString(StringBuilder string) {
- this.string = string;
+ public String getValue() {
+ return fString;
}
/**
- * Gets the string (value)
+ * Sets the string (value)
*
- * @return the string
+ * @param str the string
*/
- public String getValue() {
- return string.toString();
+ public void setValue(String str) {
+ fString = str;
}
// ------------------------------------------------------------------------
@@ -113,13 +103,15 @@ public class StringDefinition extends Definition {
@Override
public void read(BitBuffer input) throws CTFReaderException {
/* Offset the buffer position wrt the current alignment */
- alignRead(input, this.declaration);
- string.setLength(0);
+ alignRead(input, fDeclaration);
+
+ StringBuilder sb = new StringBuilder();
char c = (char) input.get(8, false);
while (c != 0) {
- string.append(c);
+ sb.append(c);
c = (char) input.get(8, false);
}
+ fString = sb.toString();
}
@Override