package edu.uw.apl.tupelo.model;

import java.util.regex.Pattern;

/**
   A ManagedDiskDescriptor (bad name but what is better?) is essentially a pair:

   1 volume id - a string

   2 session id

   so captures 'what' and 'when'

   
   When embedded in a filesystem directory within e.g. a
   FilesystemStore, an MDM becomes

   /path/to/store/.../VID/SESSIONID/...

   and subdirs like 'data' and 'attrs' then follow.

   Similarly, when embedded in a http url or amqp message, an MDM becomes

   ../VID/SESSIONID/...

   The ordering of the two members in the formatted descriptors
   follows that of increasing entropy: vol id very stable (should
   never change!), session id more dynamic (since disk contents are a
   function of time)
*/

public class ManagedDiskDescriptor implements java.io.Serializable {

	public ManagedDiskDescriptor( String diskID, Session s ) {
		this.diskID = diskID;
		this.session = s;
	}

	public boolean equals( Object o ) {
		if( this == o )
			return true;
		if( !( o instanceof ManagedDiskDescriptor ) )
			return false;
		ManagedDiskDescriptor that = (ManagedDiskDescriptor)o;
		return this.diskID.equals( that.diskID ) &&
			this.session.equals( that.session );
	}
	
	// maintain the general contract for equal Objects, though Map usage unlikely
	public int hashCode() {
		return diskID.hashCode() + session.hashCode();
	}

	public String getDiskID() {
		return diskID;
	}
	
	public Session getSession() {
		return session;
	}

	// useful only for debug, NEVER as a real filesystem path, name or url part..
	public String toString() {
		return "(" + getDiskID() + "," +
			getSession().toString() + ")" ;
	}
	
	private final String diskID;
	private final Session session;

	static public final Pattern DISKIDREGEX = Pattern.compile
		( "[A-Za-z0-9_:\\-\\. ]+" );

}

// eof

@@ -27,16 +27,45 @@
 model;%0A%0A
+import java.util.Comparator;%0A
 import j
@@ -1828,16 +1828,655 @@
 %5D+%22 );%0A%0A
+%09/*%0A%09  For a 'sensible' sort ordering that 'looks good' when displaying%0A%09  a list of ManagedDiskDescriptors, do lexocographic sort on WHAT%0A%09  (the disk id) followed by time order sort on WHEN (the session)%0A%0A%09*/%0A%09%0A%09static public final Comparator%3CManagedDiskDescriptor%3E%0A%09%09DEFAULTCOMPARATOR = new Comparator%3CManagedDiskDescriptor%3E() %7B%0A%09%09@Override%0A%09%09public int compare( ManagedDiskDescriptor o1,%0A%09%09%09%09%09%09%09ManagedDiskDescriptor o2 ) %7B%0A%09%09%09int i = o1.getDiskID().compareTo( o2.getDiskID() );%0A%09%09%09if( i != 0 )%0A%09%09%09%09return i;%0A%09%09%09return o1.getSession().compareTo( o2.getSession() );%0A%09%09%7D%0A%09%7D;%0A%0A%09static final long serialVersionUID = 2833866706524676569L;%0A%0A
 %7D%0A%0A// eo

Add default comparator for sensible sort order