• R/O
  • HTTP
  • SSH
  • HTTPS

stigmata-plugins: Commit

stigmataのpluginのためのリポジトリ.


Commit MetaInfo

Revisionea4f79964242f731c5c4f82e71160aef21bec43b (tree)
Time2014-11-27 19:13:38
AuthorHaruaki Tamada <tamadaf@keca...>
CommiterHaruaki Tamada

Log Message

change kgram format

Change Summary

Incremental Difference

--- a/kgram/src/main/java/jp/sourceforge/stigmata/birthmarks/kgram/KGram.java
+++ b/kgram/src/main/java/jp/sourceforge/stigmata/birthmarks/kgram/KGram.java
@@ -5,8 +5,8 @@ import java.lang.reflect.Array;
55 import java.util.Arrays;
66
77 /**
8- * This class represents k-gram of the some sequence.
9- *
8+ * This class represents k-gram of the some sequence.
9+ *
1010 * @author Haruaki TAMADA
1111 */
1212 public class KGram<T> implements Serializable{
@@ -24,7 +24,7 @@ public class KGram<T> implements Serializable{
2424 }
2525
2626 /**
27- * sets k-value.
27+ * sets k-value.
2828 * @param kvalue the number of elements of this object.
2929 */
3030 public void setKValue(int kvalue){
@@ -44,12 +44,11 @@ public class KGram<T> implements Serializable{
4444 */
4545 @Override
4646 public String toString(){
47- StringBuffer buffer = new StringBuffer("{ ");
47+ StringBuffer buffer = new StringBuffer();
4848 for(int i = 0; i < maxLength; i++){
49- if(i != 0) buffer.append(", ");
49+ if(i != 0) buffer.append(" ");
5050 buffer.append(get(i));
5151 }
52- buffer.append(" }");
5352 return new String(buffer);
5453 }
5554
@@ -93,14 +92,14 @@ public class KGram<T> implements Serializable{
9392
9493 /**
9594 * adds value at last index.
96- *
97- * this object is called with given 2 when following situation,
95+ *
96+ * this object is called with given 2 when following situation,
9897 * <ul>
9998 * <li>{ 1, 3, null, null } -&gt; { 1, 2, 3, null } and return 2<li>
10099 * <li>{ 1, null, 3, null } -&gt; { 1, 2, 3, null } and return 1<li>
101100 * <li>{ 1, 2, 3, 4 } -&gt; { 1, 2, 3, 4 } and return -1<li>
102101 * </ul>
103- *
102+ *
104103 * @param value value for addition.
105104 * @return added index.
106105 */
--- a/kgram/src/main/java/jp/sourceforge/stigmata/birthmarks/kgram/KGramBasedBirthmarkExtractor.java
+++ b/kgram/src/main/java/jp/sourceforge/stigmata/birthmarks/kgram/KGramBasedBirthmarkExtractor.java
@@ -1,5 +1,7 @@
11 package jp.sourceforge.stigmata.birthmarks.kgram;
22
3+import java.util.Iterator;
4+
35 import jp.sourceforge.stigmata.Birthmark;
46 import jp.sourceforge.stigmata.BirthmarkContext;
57 import jp.sourceforge.stigmata.BirthmarkElement;
@@ -7,6 +9,7 @@ import jp.sourceforge.stigmata.ExtractionUnit;
79 import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor;
810 import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor;
911 import jp.sourceforge.stigmata.spi.BirthmarkService;
12+import jp.sourceforge.stigmata.utils.ArrayIterator;
1013
1114 import org.objectweb.asm.ClassWriter;
1215
@@ -24,6 +27,23 @@ public class KGramBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
2427 super();
2528 }
2629
30+ @Override
31+ public Iterator<String> getPropertyKeys(){
32+ return new ArrayIterator<String>(new String[] { "KValue" });
33+ }
34+
35+ @Override
36+ public void setProperty(String key, Object value){
37+ if(key.equalsIgnoreCase("kvalue")){
38+ if(value instanceof Integer){
39+ kvalue = ((Integer)value).intValue();
40+ }
41+ else if(value instanceof String){
42+ kvalue = Integer.parseInt((String)value);
43+ }
44+ }
45+ }
46+
2747 public void setKValue(int kvalue){
2848 this.kvalue = kvalue;
2949 }
@@ -33,9 +53,9 @@ public class KGramBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
3353 }
3454
3555 @Override
36- public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer,
56+ public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer,
3757 Birthmark birthmark, BirthmarkContext context){
38- KGramBasedBirthmarkExtractVisitor extractor =
58+ KGramBasedBirthmarkExtractVisitor extractor =
3959 new KGramBasedBirthmarkExtractVisitor(writer, birthmark, context);
4060 extractor.setKValue(getKValue());
4161 return extractor;
@@ -45,7 +65,7 @@ public class KGramBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
4565 public ExtractionUnit[] getAcceptableUnits(){
4666 return new ExtractionUnit[] {
4767 ExtractionUnit.CLASS, ExtractionUnit.PACKAGE,
48- ExtractionUnit.ARCHIVE,
68+ ExtractionUnit.ARCHIVE,
4969 };
5070 }
5171
@@ -53,15 +73,12 @@ public class KGramBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
5373 @Override
5474 public BirthmarkElement buildElement(String value) {
5575 value = value.trim();
56- if(value.startsWith("{") && value.endsWith("}")){
57- String[] param =
58- value.substring(1, value.length() - 1).split(", *");
59- KGram<Integer> kgram = new KGram<Integer>(param.length);
60- for(int i = 0; i < param.length; i++){
61- kgram.set(i, new Integer(param[i].trim()));
62- }
63- return new KGramBasedBirthmarkElement<Integer>(kgram);
76+ String[] param =
77+ value.substring(1, value.length() - 1).split(" *");
78+ KGram<Integer> kgram = new KGram<Integer>(param.length);
79+ for(int i = 0; i < param.length; i++){
80+ kgram.set(i, new Integer(param[i].trim()));
6481 }
65- return null;
82+ return new KGramBasedBirthmarkElement<Integer>(kgram);
6683 }
6784 }
--- a/kgram/src/test/java/jp/sourceforge/stigmata/birthmarks/kgram/KGramTest.java
+++ b/kgram/src/test/java/jp/sourceforge/stigmata/birthmarks/kgram/KGramTest.java
@@ -5,7 +5,7 @@ import org.junit.Before;
55 import org.junit.Test;
66
77 /**
8- *
8+ *
99 * @author Haruaki Tamada
1010 */
1111 public class KGramTest{
@@ -19,6 +19,15 @@ public class KGramTest{
1919 }
2020
2121 @Test
22+ public void testStringRepresentation(){
23+ KGram<String>[] kgrams = KGramBuilder.getInstance().buildKGram(plainValues, 4);
24+ Assert.assertEquals("a b c d", kgrams[0].toString());
25+ Assert.assertEquals("b c d e", kgrams[1].toString());
26+ Assert.assertEquals("c d e f", kgrams[2].toString());
27+ Assert.assertEquals("d e f g", kgrams[3].toString());
28+ }
29+
30+ @Test
2231 public void checkPlainKGram(){
2332 KGram<String>[] kgrams = KGramBuilder.getInstance().buildKGram(plainValues, 4);
2433 Assert.assertEquals(4, kgrams.length);
--- a/wsp/pom.xml
+++ b/wsp/pom.xml
@@ -8,7 +8,7 @@
88 <parent>
99 <groupId>jp.sourceforge.stigmata</groupId>
1010 <artifactId>stigmata-plugins</artifactId>
11- <version>4.0-SNAPSHOT</version>
11+ <version>4.0</version>
1212 </parent>
1313
1414 <groupId>jp.sourceforge.stigmata.plugins</groupId>
Show on old repository browser