src/java.base/share/classes/java/nio/X-Buffer.java.template
changeset 48356 29e165bdf669
parent 47216 71c04702a3d5
child 49210 7c795d301dbf
equal deleted inserted replaced
48355:4944950606ef 48356:29e165bdf669
    33 #if[streamableType]
    33 #if[streamableType]
    34 import java.util.Spliterator;
    34 import java.util.Spliterator;
    35 import java.util.stream.StreamSupport;
    35 import java.util.stream.StreamSupport;
    36 import java.util.stream.$Streamtype$Stream;
    36 import java.util.stream.$Streamtype$Stream;
    37 #end[streamableType]
    37 #end[streamableType]
       
    38 
       
    39 import jdk.internal.util.ArraysSupport;
    38 
    40 
    39 /**
    41 /**
    40  * $A$ $type$ buffer.
    42  * $A$ $type$ buffer.
    41  *
    43  *
    42  * <p> This class defines {#if[byte]?six:four} categories of operations upon
    44  * <p> This class defines {#if[byte]?six:four} categories of operations upon
   283 
   285 
   284     // Creates a new buffer with the given mark, position, limit, and capacity
   286     // Creates a new buffer with the given mark, position, limit, and capacity
   285     //
   287     //
   286     $Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
   288     $Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
   287         this(mark, pos, lim, cap, null, 0);
   289         this(mark, pos, lim, cap, null, 0);
       
   290     }
       
   291 
       
   292     @Override
       
   293     Object base() {
       
   294         return hb;
   288     }
   295     }
   289 
   296 
   290 #if[byte]
   297 #if[byte]
   291 
   298 
   292     /**
   299     /**
  1295         if (!(ob instanceof $Type$Buffer))
  1302         if (!(ob instanceof $Type$Buffer))
  1296             return false;
  1303             return false;
  1297         $Type$Buffer that = ($Type$Buffer)ob;
  1304         $Type$Buffer that = ($Type$Buffer)ob;
  1298         if (this.remaining() != that.remaining())
  1305         if (this.remaining() != that.remaining())
  1299             return false;
  1306             return false;
  1300         int p = this.position();
  1307         return BufferMismatch.mismatch(this, this.position(),
  1301         for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
  1308                                        that, that.position(),
  1302             if (!equals(this.get(i), that.get(j)))
  1309                                        this.remaining()) < 0;
  1303                 return false;
       
  1304         return true;
       
  1305     }
       
  1306 
       
  1307     private static boolean equals($type$ x, $type$ y) {
       
  1308 #if[floatingPointType]
       
  1309         return (x == y) || ($Fulltype$.isNaN(x) && $Fulltype$.isNaN(y));
       
  1310 #else[floatingPointType]
       
  1311         return x == y;
       
  1312 #end[floatingPointType]
       
  1313     }
  1310     }
  1314 
  1311 
  1315     /**
  1312     /**
  1316      * Compares this buffer to another.
  1313      * Compares this buffer to another.
  1317      *
  1314      *
  1334      *
  1331      *
  1335      * @return  A negative integer, zero, or a positive integer as this buffer
  1332      * @return  A negative integer, zero, or a positive integer as this buffer
  1336      *          is less than, equal to, or greater than the given buffer
  1333      *          is less than, equal to, or greater than the given buffer
  1337      */
  1334      */
  1338     public int compareTo($Type$Buffer that) {
  1335     public int compareTo($Type$Buffer that) {
  1339         int n = this.position() + Math.min(this.remaining(), that.remaining());
  1336         int i = BufferMismatch.mismatch(this, this.position(),
  1340         for (int i = this.position(), j = that.position(); i < n; i++, j++) {
  1337                                         that, that.position(),
  1341             int cmp = compare(this.get(i), that.get(j));
  1338                                         Math.min(this.remaining(), that.remaining()));
  1342             if (cmp != 0)
  1339         if (i >= 0) {
  1343                 return cmp;
  1340             return compare(this.get(this.position() + i), that.get(this.position() + i));
  1344         }
  1341         }
  1345         return this.remaining() - that.remaining();
  1342         return this.remaining() - that.remaining();
  1346     }
  1343     }
  1347 
  1344 
  1348     private static int compare($type$ x, $type$ y) {
  1345     private static int compare($type$ x, $type$ y) {
  1568      * @return  This buffer's byte order
  1565      * @return  This buffer's byte order
  1569      */
  1566      */
  1570     public abstract ByteOrder order();
  1567     public abstract ByteOrder order();
  1571 
  1568 
  1572 #end[!byte]
  1569 #end[!byte]
       
  1570 
       
  1571 #if[char]
       
  1572     // The order or null if the buffer does not cover a memory region,
       
  1573     // such as StringCharBuffer
       
  1574     abstract ByteOrder charRegionOrder();
       
  1575 #end[char]
  1573 
  1576 
  1574 #if[byte]
  1577 #if[byte]
  1575 
  1578 
  1576     boolean bigEndian                                   // package-private
  1579     boolean bigEndian                                   // package-private
  1577         = true;
  1580         = true;