190 likes | 313 Views
This lecture covers important concepts in the Java Collections Framework, including the use of synchronized collections to ensure thread safety and the creation of unmodifiable collections that protect data integrity. Methods for sorting, reversing, and shuffling lists are discussed, along with binary search functionality. The lecture also introduces the ITag interface for custom attribute management in collections. With practical examples and applications, this session aims to enhance understanding of collection manipulation in Java.
E N D
Lecture 14 Generic bean renderer & some more information on collections
public static Collection synchronizedCollection(Collection c); public static Set synchronizedSet(Set s); public static List synchronizedList(List list); public static Map synchronizedMap(Map m); public static SortedSet synchronizedSortedSet(SortedSet s); public static SortedMap synchronizedSortedMap(SortedMap m);
Collection c = Collections.synchronizedCollection(myCollection); synchronized(c) { Iterator i = c.iterator(); // Must be in the synchronized block! while (i.hasNext()) foo(i.next()); }
public static Collection unmodifiableCollection(Collection c); public static Set unmodifiableSet(Set s); public static List unmodifiableList(List list); public static Map unmodifiableMap(Map m); public static SortedSet unmodifiableSortedSet(SortedSet s); public static SortedMap unmodifiableSortedMap(SortedMap m);
public static void sort(List list) // All elements must implement Comparable public static void sort(List list, Comparator c) public static int binarySearch(List list, Object key) // All elements must implement Comparable public static int binarySearch(List list, Object key, Comparator c) public static void reverse(List l) public static void shuffle(List list) public static void fill(List list, Object o) // Sets all elements to be given object public static void copy (List dest, List src) public static Object min[max](Collection coll) // All elements must implement Comparable public static Object min[max](Collection coll, Comparator comp)
public interface ITag { public void init( String name ); public String getName(); public Object getAttribute( String name ); public Iterator getAttributes(); public Iterator getAttributeNames(); public Iterator getChildren(); public void addAttribute( String name, Object value ); public Object getObject(); public void build( ITag parent ) throws ParseException; }
<RESOURCE CLASS=edu.nyu.sejava.iskold.eworld.HomogeneousResource> <PROPERTY NAME=Quantity VALUE=25> <PROPERTY NAME=Base VALUE=a> <PROPERTY NAME=Renewable VALUE=true> </RESOURCE>