Ranides Atterwim 10 anni fa
parent
commit
b2effacac9

+ 20 - 0
assira.drafts/pom.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>net.ranides</groupId>
+    <artifactId>assira.drafts</artifactId>
+    <version>1.0</version>
+    <packaging>jar</packaging>
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>assira</artifactId>
+            <version>2.0.0</version>
+        </dependency>
+    </dependencies>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+</project>

+ 57 - 0
assira.drafts/src/main/java/net/ranides/assira/generic/IntPair.java

@@ -0,0 +1,57 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.generic;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Map.Entry;
+import net.ranides.assira.collection.lookups.Lookup.LookupEntry;
+import net.ranides.assira.collection.maps.IntMap.IntEntry;
+import net.ranides.assira.generic.CompareUtils;
+
+public class IntPair implements LookupEntry<Integer>, IntEntry<Integer>, Serializable {
+
+    private static final long serialVersionUID = 2L;
+
+    private final int key;
+	private final int value;
+
+    public IntPair(int key, int value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    @Override
+    public int hashCode() {
+         return key ^ value;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (object instanceof Entry) {
+            Map.Entry other = (Map.Entry)object;
+            return CompareUtils.equals(other.getKey(), key) && CompareUtils.equals(other.getValue(), value);
+        }
+	    return false;
+    }
+
+    @Override
+    public int setValue(int value) {
+        throw new UnsupportedOperationException("Immutable");
+    }
+
+    @Override
+    public int getIntValue() {
+        return value;
+    }
+
+    @Override
+    public int getIntKey() {
+        return key;
+    }
+
+}

+ 68 - 0
assira.drafts/src/main/java/net/ranides/assira/generic/Pair.java

@@ -0,0 +1,68 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.generic;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Map.Entry;
+import net.ranides.assira.generic.CompareUtils;
+
+/**
+ * Immutable implementation of {@link Entry} interface.
+ * @author ranides
+ * @param <K>
+ * @param <V>
+ */
+public class Pair<K,V> implements Entry<K, V>, Serializable {
+
+    private static final long serialVersionUID = 2L;
+
+    private final K key;
+	private final V value;
+
+    public Pair(K key, V value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    @Override
+    public K getKey() {
+        return key;
+    }
+
+    @Override
+    public V getValue() {
+        return value;
+    }
+
+    @Override
+    public V setValue(V value) {
+        throw new UnsupportedOperationException("Immutable pair.");
+    }
+
+    @Override
+    public int hashCode() {
+         return (key   == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (object instanceof Entry) {
+            Map.Entry other = (Map.Entry)object;
+            return CompareUtils.equals(other.getKey(), key) && CompareUtils.equals(other.getValue(), value);
+        }
+	    return false;
+    }
+
+    @Override
+    public String toString() {
+        return key + "=" + value;
+    }
+
+
+
+}

+ 79 - 0
assira.drafts/src/main/java/net/ranides/assira/generic/TElement.java

@@ -0,0 +1,79 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/???
+ */
+package net.ranides.assira.generic;
+
+import net.ranides.assira.collection.HashComparator;
+import net.ranides.assira.generic.IntPair;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class TElement {
+    
+    private final String id;
+    
+    private final int[] hashes;
+    
+    private final int[] values;
+    
+    public TElement(String id, int[] hashes, int[] values) {
+        this.id = id;
+        this.hashes = hashes.clone();
+        this.values = values.clone();
+    }
+    
+    public TElement(String id, IntPair... versions) {
+        this.id = id;
+        this.hashes = new int[]{versions.length};
+        this.values = new int[]{versions.length};
+        for(int i=0; i<versions.length; i++) {
+            hashes[i] = versions[i].getIntKey();
+            values[i] = versions[i].getIntValue();
+        }
+    }
+    
+    @Override
+    public int hashCode() {
+        return Comparator.STD.hashCode(this);
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        return (object instanceof TElement) && Comparator.STD.equals(this, (TElement)object);
+    }
+
+    @Override
+    public String toString() {
+        return id;
+    }
+
+    public static class Comparator implements HashComparator<TElement> {
+        
+        public static final HashComparator<TElement> STD = new Comparator(0);
+    
+        public static final HashComparator<TElement> ALT = new Comparator(1);
+    
+        private final int index;
+
+        public Comparator(int index) {
+            this.index = index;
+        }
+
+        @Override
+        public int hashCode(TElement object) {
+            return object.hashes[index];
+        }
+
+        @Override
+        public int compare(TElement value1, TElement value2) {
+            return value1.values[index] - value2.values[index];
+        }
+        
+    }
+
+}

+ 34 - 0
assira.drafts/src/main/java/net/ranides/assira/generic/TElements.java

@@ -0,0 +1,34 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/???
+ */
+package net.ranides.assira.generic;
+
+import net.ranides.assira.generic.IntPair;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public abstract class TElements {
+    
+    public static final TElement A = new TElement("A",
+        new int[]{3,  7, 17}, 
+        new int[]{4, 55, 44}
+    );
+    public static final TElement B = new TElement("B",
+        pair(3, 4),
+        pair(7, 55),
+        pair(17, 44)
+    );
+    public static final TElement C = new TElement("C",
+        pair(3,4), pair(7,55), pair(17,44)
+    );
+    
+    protected static IntPair pair(int h, int v) {
+        return new IntPair(h, v);
+    }
+    
+}

+ 2 - 2
assira.rules.test/pom.xml

@@ -29,11 +29,11 @@
                     <dependency>
                         <groupId>net.ranides</groupId>
                         <artifactId>assira.rules</artifactId>
-                        <version>1.0-SNAPSHOT</version>
+                        <version>1.2</version>
                     </dependency>
                 </dependencies>
             </plugin>
         </plugins>
     </build>
-	
+    	
 </project>

+ 1 - 1
assira.rules/pom.xml

@@ -4,7 +4,7 @@
     
     <groupId>net.ranides</groupId>
     <artifactId>assira.rules</artifactId>
-    <version>1.1</version>
+    <version>1.2</version>
     <packaging>jar</packaging>
     
     <url>http://ranides.net/projects/assira</url>

+ 1 - 2
assira.rules/src/main/java/net/ranides/assira/rules/TestECB.java

@@ -10,12 +10,11 @@ import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
 import net.sourceforge.pmd.lang.java.ast.JavaNode;
 import net.sourceforge.pmd.lang.java.rule.AbstractStatisticalJavaRule;
 import net.sourceforge.pmd.lang.rule.properties.DoubleProperty;
-import static net.sourceforge.pmd.lang.rule.stat.StatisticalRule.MINIMUM_DESCRIPTOR;
 import net.sourceforge.pmd.stat.DataPoint;
 
 public class TestECB extends AbstractStatisticalJavaRule {
     
-    // DoubleProperty MINIMUM_DESCRIPTOR = new DoubleProperty("minimum", "Minimum reporting threshold", 0d, 100d, null, 2.0f);
+     DoubleProperty MINIMUM_DESCRIPTOR = new DoubleProperty("minimum", "Minimum reporting threshold", 0d, 100d, null, 2.0f);
 
     private final Class<?> nodeClass;
 

+ 5 - 8
assira.rules/src/main/resources/rulesets/java/ranides.test.xml

@@ -10,7 +10,7 @@
 
 	<rule
 		name="TST-ECB"
-		ref="rulesets/basic.xml/EmptyCatchBlock"
+		ref="rulesets/java/empty.xml/EmptyCatchBlock"
 		message="TEST: Must handle exceptions">
 		<priority>2</priority>
 	</rule>
@@ -22,16 +22,13 @@
               class="net.ranides.assira.rules.TestECB"
               externalInfoUrl="${pmd.website.baseurl}/rules/java/empty.html#EmptyCatchBlock">
             <description>
-                class size
+                ecb22
             </description>
             <priority>3</priority>
             <properties>
-                <property name="xpath">
-                    <value>
-                        20
-                    </value>
-                </property>
-                <property name="allowCommentedBlocks" type="Boolean" value="false"/>
+                <!--
+                <property name="minimum" type="Double" value="1.0" min="0.0" max="20.0" description="chuj"/>
+                -->
             </properties>
             
             <example>