Commits

Jerry Lee committed f120553

add init files

  • Participants

Comments (0)

Files changed (9)

+syntax: glob
+
+*.o
+*.lo
+*.la
+*.al
+.libs
+*.so
+*.a
+*.pyc
+*.pyo
+*.class
+*.iml
+.project
+.classpath
+.settings
+.idea
+target
+.springBeans
+
+
+syntax: regexp
+
+.*\.so.[0-9]*
+the demo code of inner class tips and usage
+<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>com.oldratlee</groupId>
+	<artifactId>inner-class-demo</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>${project.artifactId}</name>
+	<description>${project.artifactId}</description>
+	<url>https://bitbucket.org/oldrat/inner-class-demo</url>
+	<inceptionYear>2012</inceptionYear>
+	<licenses>
+		<license>
+			<name>Apache 2</name>
+			<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+			<distribution>repo</distribution>
+			<comments>A business-friendly OSS license</comments>
+		</license>
+	</licenses>
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+	<dependencies>
+		<!-- logging -->
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.1.1</version>
+			<scope>compile</scope>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.16</version>
+			<scope>compile</scope>
+			<exclusions>
+				<exclusion>
+					<artifactId>mail</artifactId>
+					<groupId>javax.mail</groupId>
+				</exclusion>
+				<exclusion>
+					<artifactId>jms</artifactId>
+					<groupId>javax.jms</groupId>
+				</exclusion>
+				<exclusion>
+					<artifactId>jmxtools</artifactId>
+					<groupId>com.sun.jdmk</groupId>
+				</exclusion>
+				<exclusion>
+					<artifactId>jmxri</artifactId>
+					<groupId>com.sun.jmx</groupId>
+				</exclusion>
+			</exclusions>
+			<optional>true</optional>
+		</dependency>
+		<!-- Testing frameworks and related dependencies -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.10</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.easymock</groupId>
+			<artifactId>easymock</artifactId>
+			<version>3.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.easymock</groupId>
+			<artifactId>easymockclassextension</artifactId>
+			<version>3.1</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<scm>
+		<url>https://bitbucket.org/oldrat/inner-class-demo</url>
+		<connection>scm:hg:https://oldrat@bitbucket.org/oldrat/inner-class-demo</connection>
+	</scm>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+					<encoding>UTF-8</encoding>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<developers>
+		<developer>
+			<name>Jerry Lee</name>
+			<id>oldratlee</id>
+			<email>oldratlee(AT)gmail(DOT)com</email>
+			<roles>
+				<role>Developer</role>
+			</roles>
+			<timezone>+8</timezone>
+		</developer>
+	</developers>
+</project>

src/test/java/com/oldratlee/innerclass/serialization/FooA.java

+package com.oldratlee.innerclass.serialization;
+
+public class FooA {
+    private int attrib;
+    private static int staticAttrib;
+
+    public class Inner1 {
+        private int a1;
+
+        public int method1() {
+            return attrib;
+        }
+    }
+
+    public static class StaticInner2 {
+        private int sa1;
+
+        public int method2() {
+            return staticAttrib;
+        }
+    }
+
+    public int method() {
+        int a = new Inner1().a1;
+        a += new StaticInner2().sa1;
+        return a;
+    }
+}

src/test/java/com/oldratlee/innerclass/serialization/FooB.java

+package com.oldratlee.innerclass.serialization;
+
+public class FooB {
+    private int foo;
+    private int age;
+    
+    public class Inner {
+        private int foo;
+        
+        public int method() {
+            return foo + FooB.this.foo + age;
+        }
+    }
+}

src/test/java/com/oldratlee/innerclass/serialization/InnnerClassSerialization_FailTest.java

+package com.oldratlee.innerclass.serialization;
+import org.junit.Test;
+
+import java.io.Serializable;
+
+public class InnnerClassSerialization_FailTest {
+    interface GetDataInterface extends Serializable {
+        public Object getData();
+    }
+
+    GetDataInterface attributeData = new GetDataInterface() {
+           private static final long serialVersionUID = 1L;
+           public Object getData() {
+               return null;
+           }
+       };
+
+    public class InnerClassSerialize implements Serializable {
+        private static final long serialVersionUID = 1L;
+    }
+    
+    @Test
+    public void testSerializable_Attribute_AnonymousClass() throws Exception {
+        Util.writeObject(attributeData);
+    }
+    
+    @Test
+    public void testSerializable_LocalVar_AnonymousClass() throws Exception {
+        GetDataInterface local = new GetDataInterface() {
+            private static final long serialVersionUID = 1L;
+            public Object getData() {
+                return null;
+            }
+        };
+        
+        Util.writeObject(local);
+    }
+
+    @Test
+    public void testSerializable_InnerClass() throws Exception {
+        InnerClassSerialize data = new InnerClassSerialize();
+        Util.writeObject(data);
+    }
+}

src/test/java/com/oldratlee/innerclass/serialization/StaticClassSerialization_JUnit3_Test.java

+package com.oldratlee.innerclass.serialization;
+
+import junit.framework.TestCase;
+
+import java.io.Serializable;
+
+public class StaticClassSerialization_JUnit3_Test extends TestCase {
+    
+    interface GetDataInterface extends Serializable {
+        public Object getData();
+    }
+
+    static GetDataInterface getData = new GetDataInterface() {
+        private static final long serialVersionUID = 1L;
+
+        public Object getData() {
+            return null;
+        }
+    };
+    
+    public static class ClassImplSerialize implements Serializable {
+        private static final long serialVersionUID = 88940079192401092L;
+    }
+    
+    public void testSerializable_Attribute_StaticAnonymousClass() throws Exception {
+        Util.writeObject(getData);
+    }
+
+    public static void testSerializable_LocalVar_StaticAnonymousClass() throws Exception {
+        GetDataInterface local = new GetDataInterface() {
+            private static final long serialVersionUID = 1L;
+            public Object getData() {
+                return null;
+            }
+        };
+        
+        Util.writeObject(local);
+    }
+    
+    public void testSerializable_StaticInnerClass() throws Exception {
+        ClassImplSerialize data = new ClassImplSerialize();
+        Util.writeObject(data);
+    }
+}

src/test/java/com/oldratlee/innerclass/serialization/StaticInnerClassSerializationTest.java

+package com.oldratlee.innerclass.serialization;
+
+import org.junit.Test;
+
+import java.io.Serializable;
+
+public class StaticInnerClassSerializationTest {
+
+    interface GetDataInterface extends Serializable {
+        public Object getData();
+    }
+
+    static GetDataInterface getData = new GetDataInterface() {
+        private static final long serialVersionUID = 1L;
+
+        public Object getData() {
+            return null;
+        }
+    };
+
+    public static class ClassImplSerialize implements Serializable {
+        private static final long serialVersionUID = 88940079192401092L;
+    }
+
+    @Test
+    public void testSerializable_Attribute_StaticAnonymousClass() throws Exception {
+        Util.writeObject(getData);
+    }
+
+    @Test
+    public void testSerializable_StaticInnerClass() throws Exception {
+        ClassImplSerialize data = new ClassImplSerialize();
+        Util.writeObject(data);
+    }
+}

src/test/java/com/oldratlee/innerclass/serialization/Util.java

+package com.oldratlee.innerclass.serialization;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+public class Util {
+    public static <T> void writeObject(T data) throws IOException {
+        ObjectOutputStream out = null;
+        try {
+            out = new ObjectOutputStream(new ByteArrayOutputStream());
+            out.writeObject(data);
+        } finally {
+            if (null != out) {
+                try {
+                    out.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
+}