package textbender.a.u.transfer.clipboard; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.io.*; import java.util.*; import textbender.g.io.*; import textbender.g.lang.*; import textbender.o.*; /** Map of index blocks. */ @ThreadSafe class IndexBlockMap implements Serializable { private static final long serialVersionUID = 0L; protected IndexBlockMap() {} /** Constructs an IndexBlockMap from the persistent store. */ static IndexBlockMap create() throws IOException{ return IndexBlockMapW._createUnchecked(); } // ------------------------------------------------------------------------------------ /** Returns the index block within which a particular index falls. * * @return index block for the clip-index; * or null if no block was previously mapped */ IndexBlock getIndexBlock( final long clipIndex ) { final IndexBlock key = new IndexBlock ( clipIndex, /*size unknown*/0, /*sourceDocumentFile unknown*/null ); int b = Collections.binarySearch( list, key ); if( b < 0 ) { b = -(b + 1); // insertion point --b; // block that ought to contain clipIndex if( b < 0 ) return null; } final IndexBlock block = list.get( b ); if( clipIndex >= block.clipIndex0() + block.size() ) return null; return block; } // ` F i l e b a s e `````````````````````````````````````````````````````````````````` static final File PACKAGE_DIRECTORY; static { final StringBuilder b = new StringBuilder(); b.append( System.getProperty( "user.home" )); b.append( File.separatorChar ); if( OperatingSystem.isWindows() ) b.append( "Application Data" ); // Maybe this is standard? Anyway, dot files behave strangely on Windows, so don't use '.var'. else b.append( ".var" ); b.append( File.separatorChar ); b.append( "textbender" ); b.append( File.separatorChar ); b.append( "A.U.TRANSFER.CLIPBOARD" ); // name must remain stable PACKAGE_DIRECTORY = new File( b.toString() ); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// protected final ArrayList list = new ArrayList(); protected static final File PERSISTANT_STORE_FILE = new File ( IndexBlockMap.PACKAGE_DIRECTORY, "iNDEXbLOCKmAP" ); }