ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # IGNITE-32 WIP: POJOs generation: added equals() and hashCode().
Date Fri, 26 Dec 2014 04:17:22 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 162bed47d -> 5b01f7083


# IGNITE-32 WIP: POJOs generation: added equals() and hashCode().


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5b01f708
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5b01f708
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5b01f708

Branch: refs/heads/ignite-32
Commit: 5b01f7083de62ce0d3e27ebe2e85e1ab356044d0
Parents: 162bed4
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Dec 26 11:17:21 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Dec 26 11:17:21 2014 +0700

----------------------------------------------------------------------
 .../ignite/schema/pojo/PojoCodeGenerator.java   | 77 ++++++++++++++------
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 20 +++--
 2 files changed, 63 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5b01f708/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
index 164c012..33ca6c1 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
@@ -22,23 +22,10 @@ import static org.apache.ignite.schema.util.SchemaUtils.*;
 public class PojoCodeGenerator {
     /** */
     private static final String TAB = "    ";
-
-    /**
-     * @return Current indent constructed from spaces.
-     */
-    private static String indent(int indent) {
-        switch (indent) {
-            case 0: return "";
-            case 1: return TAB;
-            default:
-                StringBuilder sb = new StringBuilder(TAB.length() * indent);
-
-                for (int i = 0; i < indent; i++)
-                    sb.append(TAB);
-
-                return sb.toString();
-        }
-    }
+    /** */
+    private static final String TAB2 = TAB + TAB;
+    /** */
+    private static final String TAB3 = TAB + TAB + TAB;
 
     /**
      * Generate java class code.
@@ -52,14 +39,10 @@ public class PojoCodeGenerator {
         File pkgFolder) throws IOException {
         Collection<String> src = new ArrayList<>(256);
 
-        int indent = 0;
-
         src.add("package " + pkg + ";");
         src.add("");
         src.add("public class " + type + " {");
 
-        indent++;
-
         for (GridCacheQueryTypeDescriptor desc : descs) {
             src.add(TAB + "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
             src.add("");
@@ -74,16 +57,64 @@ public class PojoCodeGenerator {
             src.add("");
 
             src.add(TAB + "public " + fldType + " get" + mtdName + "() {");
-            src.add(TAB + TAB + "return " + fldName + ";");
+            src.add(TAB2 +"return " + fldName + ";");
             src.add(TAB + "}");
 
             src.add("");
 
             src.add(TAB + "public void set" + mtdName + "(" + fldType + " " + fldName + ")
{");
-            src.add(TAB + TAB + "this." + fldName + " = " + fldName + ";");
+            src.add(TAB2 +"this." + fldName + " = " + fldName + ";");
             src.add(TAB + "}");
         }
 
+        src.add("");
+
+        src.add(TAB + "@Override public boolean equals(Object o) {");
+        src.add(TAB2 + "if (this == o)");
+        src.add(TAB3 + "return true;");
+
+        src.add("");
+
+        src.add(TAB2 + "if (o == null || getClass() != o.getClass())");
+        src.add(TAB3 + "return false;");
+
+        src.add("");
+
+        src.add(TAB2 + String.format("%1$s that = (%1$s)o;", type));
+
+        for (GridCacheQueryTypeDescriptor desc : descs) {
+            String fldName = desc.getJavaName();
+
+            src.add("");
+            src.add(TAB2 + String.format("if (%1$s != null ? !%1$s.equals(that.%1$s) : that.%1$s
!= null)", fldName));
+            src.add(TAB3 + "return false;");
+        }
+
+        src.add("");
+        src.add(TAB2 + "return true;");
+        src.add(TAB + "}");
+
+        src.add("");
+
+        src.add(TAB + "@Override public int hashCode() {");
+
+        Iterator<GridCacheQueryTypeDescriptor> it = descs.iterator();
+
+        GridCacheQueryTypeDescriptor first = it.next();
+
+        src.add(TAB2 + String.format("int result = %1$s != null ? %1$s.hashCode() : 0;",
first.getJavaName()));
+
+        while(it.hasNext()) {
+            String fldName = it.next().getJavaName();
+
+            src.add("");
+            src.add(TAB2 + String.format("result = 31 * result + (%1$s != null ? %1$s.hashCode()
: 0);", fldName));
+        }
+
+        src.add("");
+        src.add(TAB2 + "return result;");
+        src.add(TAB + "}");
+
         try (Writer writer = new BufferedWriter(new FileWriter(new File(pkgFolder, type +
".java")))) {
             for (String line : src)
                 writer.write(line + '\n');

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5b01f708/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
index a3279f9..84ac4f4 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
@@ -197,22 +197,20 @@ public class SchemaLoadApp extends Application {
             List<GridCacheQueryTypeMetadata> all = new ArrayList<>();
 
             for (TreeItem<String> schemeItem : rootItem.getChildren()) {
-                if (((CheckBoxTreeItem)schemeItem).isSelected()) {
-                    for (TreeItem<String> tblItem : schemeItem.getChildren()) {
-                        if (((CheckBoxTreeItem)tblItem).isSelected()) {
-                            GridCacheQueryTypeMetadata meta = schemas.get(schemeItem.getValue())
-                                .get(tblItem.getValue());
+                for (TreeItem<String> tblItem : schemeItem.getChildren()) {
+                    if (((CheckBoxTreeItem)tblItem).isSelected()) {
+                        GridCacheQueryTypeMetadata meta = schemas.get(schemeItem.getValue())
+                            .get(tblItem.getValue());
 
-                            all.add(meta);
+                        all.add(meta);
 
-                            XmlTransformer transformer = new XmlTransformer(4);
+                        XmlTransformer transformer = new XmlTransformer(4);
 
-                            Result res = new StreamResult(new File(destFolder, meta.getType()
+ ".xml"));
+                        Result res = new StreamResult(new File(destFolder, meta.getType()
+ ".xml"));
 
-                            transformer.transform(pkg, meta, res);
+                        transformer.transform(pkg, meta, res);
 
-                            PojoCodeGenerator.generate(meta, outFolder, pkg);
-                        }
+                        PojoCodeGenerator.generate(meta, outFolder, pkg);
                     }
                 }
             }


Mime
View raw message