- Bounded Type Parameters
- Multiple Bounds
- Java bounds что это
- Bounds
- clone
- equals
- hashCode
- intersect
- intersect
- intersect
- intersect
- closestIntersection
- combine
- combine
- combine
- combine
- transform
- transform
- isEmpty
- set
- Java bounds что это
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Constructor Detail
- Bounds
- Method Detail
- getMinX
- getMinY
- getMinZ
- getWidth
- getHeight
- getDepth
- getMaxX
- getMaxY
- getMaxZ
- isEmpty
- contains
- contains
- contains
- contains
- contains
- contains
- contains
- intersects
- intersects
- intersects
Bounded Type Parameters
There may be times when you want to restrict the types that can be used as type arguments in a parameterized type. For example, a method that operates on numbers might only want to accept instances of Number or its subclasses. This is what bounded type parameters are for.
To declare a bounded type parameter, list the type parameter’s name, followed by the extends keyword, followed by its upper bound, which in this example is Number . Note that, in this context, extends is used in a general sense to mean either «extends» (as in classes) or «implements» (as in interfaces).
public class Box < private T t; public void set(T t) < this.t = t; >public T get() < return t; >public extends Number> void inspect(U u) < System.out.println("T: " + t.getClass().getName()); System.out.println("U: " + u.getClass().getName()); >public static void main(String[] args) < BoxintegerBox = new Box(); integerBox.set(new Integer(10)); integerBox.inspect("some text"); // error: this is still String! > >
By modifying our generic method to include this bounded type parameter, compilation will now fail, since our invocation of inspect still includes a String :
Box.java:21: inspect(U) in Box cannot be applied to (java.lang.String) integerBox.inspect("10"); ^ 1 error
In addition to limiting the types you can use to instantiate a generic type, bounded type parameters allow you to invoke methods defined in the bounds:
public class NaturalNumber < private T n; public NaturalNumber(T n) < this.n = n; >public boolean isEven() < return n.intValue() % 2 == 0; > // . >
The isEven method invokes the intValue method defined in the Integer class through n.
Multiple Bounds
The preceding example illustrates the use of a type parameter with a single bound, but a type parameter can have multiple bounds:
A type variable with multiple bounds is a subtype of all the types listed in the bound. If one of the bounds is a class, it must be specified first. For example:
Class A < /* . */ >interface B < /* . */ >interface C < /* . */ >class D < /* . */ >
If bound A is not specified first, you get a compile-time error:
class D < /* . */ >// compile-time error
Java bounds что это
All Implemented Interfaces: java.lang.Cloneable Direct Known Subclasses: BoundingBox, BoundingPolytope, BoundingSphere public abstract class Bounds extends java.lang.Object implements java.lang.Cloneable
The abstract base class for bounds objects. Bounds objects define a convex, closed volume that is used for various intersection and culling operations.
Constructor Summary | |
Bounds () Constructs a new Bounds object. |
Method Summary | |
abstract java.lang.Object | clone () Makes a copy of a bounds object. |
abstract Bounds | closestIntersection (Bounds[] boundsObjects) Finds closest bounding object that intersects this bounding object. |
abstract void | combine (Bounds boundsObject) Combines this bounding object with a bounding object so that the resulting bounding object encloses the original bounding object and the given bounds object. |
abstract void | combine (Bounds[] boundsObjects) Combines this bounding object with an array of bounding objects so that the resulting bounding object encloses the original bounding object and the given array of bounds object. |
abstract void | combine (Point3d point) Combines this bounding object with a point. |
abstract void | combine (Point3d[] points) Combines this bounding object with an array of points. |
abstract boolean | equals (java.lang.Object bounds) Indicates whether the specified bounds object is equal to this Bounds object. |
abstract int | hashCode () Returns a hash code for this Bounds object based on the data values in this object. |
abstract boolean | intersect (Bounds boundsObject) Test for intersection with another bounds object. |
abstract boolean | intersect (Bounds[] boundsObjects) Test for intersection with another bounds object. |
abstract boolean | intersect (Point3d point) Test for intersection with a point. |
abstract boolean | intersect (Point3d origin, Vector3d direction) Test for intersection with a ray. |
abstract boolean | isEmpty () Tests whether the bounds is empty. |
abstract void | set (Bounds boundsObject) Sets the value of this Bounds object. |
abstract void | transform (Bounds bounds, Transform3D trans) Modifies the bounding object so that it bounds the volume generated by transforming the given bounding object. |
abstract void | transform (Transform3D trans) Transforms this bounding object by the given matrix. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Bounds
clone
public abstract java.lang.Object clone()
Overrides: clone in class java.lang.Object
equals
public abstract boolean equals(java.lang.Object bounds)
Indicates whether the specified bounds object is equal to this Bounds object. They are equal if both the specified bounds object and this Bounds are instances of the same Bounds subclass and all of the data members of bounds are equal to the corresponding data members in this Bounds.
Overrides: equals in class java.lang.Object Parameters: bounds — the object with which the comparison is made. Returns: true if this Bounds object is equal to bounds ; otherwise false Since: Java 3D 1.2
hashCode
public abstract int hashCode()
Returns a hash code for this Bounds object based on the data values in this object. Two different Bounds objects of the same type with identical data values (i.e., Bounds.equals returns true) will return the same hash code. Two Bounds objects with different data members may return the same hash code value, although this is not likely.
Overrides: hashCode in class java.lang.Object Returns: a hash code for this Bounds object. Since: Java 3D 1.2
intersect
public abstract boolean intersect(Point3d origin, Vector3d direction)
Parameters: origin — the starting point of the ray direction — the direction of the ray Returns: true or false indicating if an intersection occured
intersect
Parameters: point — a point defining a position in 3-space Returns: true or false indicating if an intersection occured
intersect
Parameters: boundsObject — another bounds object Returns: true or false indicating if an intersection occurred
intersect
Parameters: boundsObjects — an array of bounding objects Returns: true or false indicating if an intersection occured
closestIntersection
public abstract Bounds closestIntersection(Bounds[] boundsObjects)
Parameters: boundsObjects — an array of bounds objects Returns: closest bounding object
combine
Combines this bounding object with a bounding object so that the resulting bounding object encloses the original bounding object and the given bounds object.
Parameters: boundsObject — another bounds object
combine
Combines this bounding object with an array of bounding objects so that the resulting bounding object encloses the original bounding object and the given array of bounds object.
Parameters: boundsObjects — an array of bounds objects
combine
Parameters: point — a 3d point in space
combine
Parameters: points — an array of 3d points in space
transform
Parameters: trans — the transformation matrix
transform
Modifies the bounding object so that it bounds the volume generated by transforming the given bounding object.
Parameters: bounds — the bounding object to be transformed trans — the transformation matrix
isEmpty
public abstract boolean isEmpty()
Tests whether the bounds is empty. A bounds is empty if it is null (either by construction or as the result of a null intersection) or if its volume is negative. A bounds with a volume of zero is not empty.
Returns: true if the bounds is empty; otherwise, it returns false
set
Parameters: boundsObject — another bounds object.
| |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java bounds что это
The base class for objects that are used to describe the bounds of a node or other scene graph object. One interesting characteristic of a Bounds object is that it may have a negative width, height, or depth. A negative value for any of these indicates that the Bounds are «empty».
Constructor Summary
Modifier | Constructor and Description |
---|---|
protected | Bounds (double minX, double minY, double minZ, double width, double height, double depth) |
Method Summary
Methods inherited from class java.lang.Object
Constructor Detail
Bounds
protected Bounds(double minX, double minY, double minZ, double width, double height, double depth)
Method Detail
getMinX
public final double getMinX()
getMinY
public final double getMinY()
getMinZ
public final double getMinZ()
getWidth
public final double getWidth()
getHeight
public final double getHeight()
getDepth
public final double getDepth()
getMaxX
public final double getMaxX()
getMaxY
public final double getMaxY()
getMaxZ
public final double getMaxZ()
isEmpty
public abstract boolean isEmpty()
contains
contains
contains
public abstract boolean contains(double x, double y)
contains
public abstract boolean contains(double x, double y, double z)
contains
contains
public abstract boolean contains(double x, double y, double w, double h)
contains
public abstract boolean contains(double x, double y, double z, double w, double h, double d)
intersects
intersects
public abstract boolean intersects(double x, double y, double w, double h)
intersects
public abstract boolean intersects(double x, double y, double z, double w, double h, double d)