1.SparseArrays
Sparsearrays is the mapping of Integer to Objects, which can be referenced by HashMap. Its purpose is to save memory and memory more efficiently, because it avoids the automatic boxing of keys, and its structure does not depend on each of the entry-set. It is a binary search to find out, so it is not suitable for key a lot of cases, probably in the case of hundreds of elements, slower than the speed of HashMap 50% below.
Similarly there are Sparsebooleanarray,sparseintarray,sparselongarray, which are mapping integer to Boolean,int Long, respectively.
2.Arrayset Arraymap
The same as the above, the number is not a case of HashMap
3.Atomicfile
A copy is saved locally while the file is being written, and can be recovered from the backup file if the write fails.
4.AttributeSet (interface), Xmlpullattributes (Class), Bridgexmlpullattributes (Class)
AttributeSet is just an interface for parsing XML, subclass Resources.Theme.obtainStyledAttributes ();
can also
Xmlpullparser parser == xml.asattributeset (parser);
View Code
5.Base64,base64inputstream,base64outputstream
3 8-bit bytes (3*8=24) are converted to 4 6-bit bytes (4*6=24), followed by 6 two in front of 0 bits, forming a 8-bit byte form. For network transport, encryption and decryption.
6.Containerhelpers
Arraymap, such as the use of binary search is the containerhelpers.binarysearch of the goods, no other role
7.Displaymetrics
Used to get screen pixel density, low=120,mid=160,high=240 ...
Displaymetrics metrics = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metrics);
8.Fastimmutablearrayset
Reusing iterator, if you want to traverse hundreds of times, is 2.5 times times more efficient than hashset.
9.Foatmath
Basically no (inefficient), something like the math operation.
Ten.Jsonreader,jsonwriter
JSON parsing, usage
PublicList<message> Readjsonstream (InputStream in)throwsIOException {Jsonreader reader=NewJsonreader (NewInputStreamReader (In, "UTF-8")); Try { returnReadmessagesarray (reader); } finally{reader.close (); } } PublicList<message> Readmessagesarray (Jsonreader Reader)throwsIOException {List<Message> messages =NewArraylist<message>(); Reader.beginarray (); while(Reader.hasnext ()) {Messages.add (Readmessage (reader)); } reader.endarray (); returnmessages; } PublicMessage readmessage (Jsonreader Reader)throwsIOException {Longid =-1; String text=NULL; User User=NULL; List<Double> Geo =NULL; Reader.beginobject (); while(Reader.hasnext ()) {String name=Reader.nextname (); if(Name.equals ("id") ) {ID=Reader.nextlong (); } Else if(Name.equals ("text") ) {text=reader.nextstring (); } Else if(Name.equals ("Geo") && reader.peek ()! =jsontoken.null) {Geo=Readdoublesarray (reader); } Else if(Name.equals ("User") ) {User=Readuser (reader); } Else{reader.skipvalue (); }} reader.endobject (); return NewMessage (ID, text, user, GEO); } PublicList<double> Readdoublesarray (Jsonreader Reader)throwsIOException {List<Double> doubles =NewArraylist<double>(); Reader.beginarray (); while(Reader.hasnext ()) {Doubles.add (reader.nextdouble ()); } reader.endarray (); returndoubles; } PublicUser Readuser (Jsonreader Reader)throwsIOException {String username=NULL; intFollowerscount =-1; Reader.beginobject (); while(Reader.hasnext ()) {String name=Reader.nextname (); if(Name.equals ("name") ) {username=reader.nextstring (); } Else if(Name.equals ("Followers_count") ) {Followerscount=Reader.nextint (); } Else{reader.skipvalue (); }} reader.endobject (); return NewUser (username, followerscount); }View Code
* Public voidWritejsonstream (OutputStream out, list<message> messages)throwsIOException {* Jsonwriter writer =NewJsonwriter (NewOutputStreamWriter (out, "UTF-8")); * Writer.setindent (""); *Writemessagesarray (writer, messages);*writer.close ();* } * * Public voidWritemessagesarray (jsonwriter writer, list<message> messages)throwsIOException {*Writer.beginarray ();* for(Message message:messages) {*Writemessage (writer, message);* } *Writer.endarray ();* } * * Public voidWritemessage (jsonwriter writer, message message)throwsIOException {*Writer.beginobject ();* WRITER.NAME ("id")). Value (Message.getid ()); * Writer.name ("text")). Value (Message.gettext ()); *if(Message.getgeo ()! =NULL) { * Writer.name ("Geo"); *Writedoublesarray (writer, Message.getgeo ());* }Else { * Writer.name ("Geo"). Nullvalue (); * } * Writer.name ("user")); *Writeuser (writer, Message.getuser ());*Writer.endobject ();* } * * Public voidWriteuser (jsonwriter writer, user user)throwsIOException {*Writer.beginobject ();* Writer.name ("name")). Value (User.getname ()); * Writer.name ("Followers_count"). Value (User.getfollowerscount ()); *Writer.endobject ();* } * * Public voidWritedoublesarray (jsonwriter writer, list<double> doubles)throwsIOException {*Writer.beginarray ();* for(Double value:doubles) {*Writer.value (value);* } *Writer.endarray ();* }View Code
LruCache .
With Linkedhashmap<k,v>, the most recently used element is moved to the top of the queue using a strong reference, so elements that are not used frequently are moved out. Because the weak reference collection time is uncertain, LRUCache is better as a picture cache.
* int// 4MiB * new lrucache<string, bitmap>* protectedint* return* * }}
View Code
Patterns .
Write regular expressions for commonly used ip,domain,email, etc.
timeutils .
Get time Zone
.XML
XML parsing
Some common classes in Android/util