Created
March 6, 2014 09:57
-
-
Save Vox1oot/9386469 to your computer and use it in GitHub Desktop.
com.javarush.test.level17.lesson10.home05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level17.lesson10.home05; | |
/* Лишняя синхронизация | |
synchronized существенно замедляет программу, поэтому убери избыточность synchronized внутри методов | |
*/ | |
public class Solution { | |
char[] value; | |
int count; | |
public Solution append(CharSequence s) { | |
if (s == null) { | |
s = "null"; | |
} | |
if (s instanceof String) { | |
return this.append((String) s); | |
} | |
if (s instanceof Solution) { | |
return this.appendThis((Solution) s); | |
} | |
return this.append(s); | |
} | |
public synchronized Solution appendThis(Solution s) { | |
//do something here.... | |
return this; | |
} | |
private static final java.io.ObjectStreamField[] serialPersistentFields = | |
{ | |
new java.io.ObjectStreamField("value", char[].class), | |
new java.io.ObjectStreamField("count", Integer.TYPE), | |
new java.io.ObjectStreamField("shared", Boolean.TYPE), | |
}; | |
private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { | |
java.io.ObjectOutputStream.PutField fields = s.putFields(); | |
fields.put("value", value); | |
fields.put("count", count); | |
fields.put("shared", false); | |
s.writeFields(); | |
} | |
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { | |
java.io.ObjectInputStream.GetField fields = s.readFields(); | |
value = (char[]) fields.get("value", null); | |
count = fields.get("count", 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
в коде упущен pswm, понятное дело что он сам по себе очевиден, но всё такие листинг должен быть полным