Path segment in java

Path segment in java

The PathIterator interface provides the mechanism for objects that implement the Shape interface to return the geometry of their boundary by allowing a caller to retrieve the path of that boundary a segment at a time. This interface allows these objects to retrieve the path of their boundary a segment at a time by using 1st through 3rd order Bézier curves, which are lines and quadratic or cubic Bézier splines. Multiple subpaths can be expressed by using a «MOVETO» segment to create a discontinuity in the geometry to move from the end of one subpath to the beginning of the next. Each subpath can be closed manually by ending the last segment in the subpath on the same coordinate as the beginning «MOVETO» segment for that subpath or by using a «CLOSE» segment to append a line segment from the last point back to the first. Be aware that manually closing an outline as opposed to using a «CLOSE» segment to close the path might result in different line style decorations being used at the end points of the subpath. For example, the BasicStroke object uses a line «JOIN» decoration to connect the first and last points if a «CLOSE» segment is encountered, whereas simply ending the path on the same coordinate as the beginning coordinate results in line «CAP» decorations being used at the ends.

Field Summary

The segment type constant that specifies that the preceding subpath should be closed by appending a line segment back to the point corresponding to the most recent SEG_MOVETO.

The segment type constant for the set of 3 points that specify a cubic parametric curve to be drawn from the most recently specified point.

The segment type constant for a point that specifies the end point of a line to be drawn from the most recently specified point.

The segment type constant for the pair of points that specify a quadratic parametric curve to be drawn from the most recently specified point.

Method Summary

Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.

Field Detail

WIND_EVEN_ODD

@Native static final int WIND_EVEN_ODD

The winding rule constant for specifying an even-odd rule for determining the interior of a path. The even-odd rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments an odd number of times.

Читайте также:  Html css default text color

WIND_NON_ZERO

@Native static final int WIND_NON_ZERO

The winding rule constant for specifying a non-zero rule for determining the interior of a path. The non-zero rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments a different number of times in the counter-clockwise direction than the clockwise direction.

SEG_MOVETO

@Native static final int SEG_MOVETO

SEG_LINETO

@Native static final int SEG_LINETO

The segment type constant for a point that specifies the end point of a line to be drawn from the most recently specified point.

SEG_QUADTO

@Native static final int SEG_QUADTO

The segment type constant for the pair of points that specify a quadratic parametric curve to be drawn from the most recently specified point. The curve is interpolated by solving the parametric control equation in the range (t=[0..1]) using the most recently specified (current) point (CP), the first control point (P1), and the final interpolated control point (P2). The parametric control equation for this curve is:

P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2 0 

SEG_CUBICTO

@Native static final int SEG_CUBICTO

The segment type constant for the set of 3 points that specify a cubic parametric curve to be drawn from the most recently specified point. The curve is interpolated by solving the parametric control equation in the range (t=[0..1]) using the most recently specified (current) point (CP), the first control point (P1), the second control point (P2), and the final interpolated control point (P3). The parametric control equation for this curve is:

P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3 0 

SEG_CLOSE

@Native static final int SEG_CLOSE

The segment type constant that specifies that the preceding subpath should be closed by appending a line segment back to the point corresponding to the most recent SEG_MOVETO.

Method Detail

getWindingRule

isDone

next

Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.

currentSegment

int currentSegment(float[] coords)

Returns the coordinates and type of the current path segment in the iteration. The return value is the path-segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A float array of length 6 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a pair of float x,y coordinates. SEG_MOVETO and SEG_LINETO types returns one point, SEG_QUADTO returns two points, SEG_CUBICTO returns 3 points and SEG_CLOSE does not return any points.

currentSegment

int currentSegment(double[] coords)

Returns the coordinates and type of the current path segment in the iteration. The return value is the path-segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A double array of length 6 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a pair of double x,y coordinates. SEG_MOVETO and SEG_LINETO types returns one point, SEG_QUADTO returns two points, SEG_CUBICTO returns 3 points and SEG_CLOSE does not return any points.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

Path segment in java

Represents a URI path segment and any associated matrix parameters. When an instance of this type is injected with PathParam , the value of the annotation identifies which path segment is selected and the presence of an Encoded annotation will result in an instance that supplies the path and matrix parameter values in URI encoded form.

See Also: UriInfo#getPathSegments , PathParam

Method Summary
MultivaluedMap getMatrixParameters ()
Get a map of the matrix parameters associated with the path segment.
java.lang.String getPath ()
Get the path segment.

getPath


getMatrixParameters

Get a map of the matrix parameters associated with the path segment. The map keys are the names of the matrix parameters with any percent-escaped octets decoded.

Returns: the map of matrix parameters See Also: Matrix URIs

Overview Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature

Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.

Generated on 10-February-2011 12:41

Источник

How to obtain the last path segment of a uri in Java?

When working with URIs in Java, it is often necessary to extract various parts of the URI for further processing. One common task is to obtain the last path segment of a URI, which is the portion of the URI that comes after the last '/' character in the path. This can be useful for parsing the filename or other information from the path of a URI.

Method 1: Using the URI class

To obtain the last path segment of a URI in Java using the URI class, you can follow these steps:

  1. Create a new URI instance with the URI string.
  2. Get the path of the URI using the getPath() method.
  3. Split the path into segments using the split() method with "/" as the delimiter.
  4. Get the last segment of the path by accessing the last element of the resulting array.
import java.net.URI; public class Main  public static void main(String[] args)  String uriStr = "https://example.com/path/to/last-segment"; URI uri = URI.create(uriStr); String path = uri.getPath(); String[] segments = path.split("/"); String lastSegment = segments[segments.length - 1]; System.out.println(lastSegment); // Output: last-segment > >

In this example, we first create a new URI instance with the URI string "https://example.com/path/to/last-segment". Then, we get the path of the URI using the getPath() method, which returns "/path/to/last-segment". We split this path into segments using the split() method with "/" as the delimiter, which returns an array containing ["", "path", "to", "last-segment"]. Finally, we get the last segment of the path by accessing the last element of the resulting array, which is "last-segment".

Method 2: Using the String class

To obtain the last path segment of a URI using the String class in Java, you can follow these steps:

String uriString = "http://example.com/path/to/my/file.txt";
URI uri = URI.create(uriString); String path = uri.getPath();
String[] segments = path.split("/");
String lastSegment = segments[segments.length - 1];

Putting it all together, the code would look like this:

String uriString = "http://example.com/path/to/my/file.txt"; URI uri = URI.create(uriString); String path = uri.getPath(); String[] segments = path.split("/"); String lastSegment = segments[segments.length - 1]; System.out.println(lastSegment); // Output: file.txt

This code first creates a string representing the URI, then uses the URI class to parse it and obtain the path. The path is then split into segments using the forward slash as the delimiter. Finally, the last segment is obtained by accessing the last element of the segments array. The output of this code is the last path segment of the URI, which in this case is "file.txt".

Method 3: Using the Apache Commons URIUtils class

To obtain the last path segment of a URI in Java using the Apache Commons URIUtils class, you can follow these steps:

import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIUtils;
URI uri = new URI("https://example.com/path/to/some/resource");
String host = URIUtils.extractHost(uri).getHostName();
ListString> pathSegments = new URIBuilder(uri).getPathSegments();
String lastPathSegment = pathSegments.get(pathSegments.size() - 1);

Here's the complete code example:

import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIUtils; import java.net.URI; import java.net.URISyntaxException; import java.util.List; public class Main  public static void main(String[] args) throws URISyntaxException  URI uri = new URI("https://example.com/path/to/some/resource"); String host = URIUtils.extractHost(uri).getHostName(); ListString> pathSegments = new URIBuilder(uri).getPathSegments(); String lastPathSegment = pathSegments.get(pathSegments.size() - 1); System.out.println("Host: " + host); System.out.println("Last Path Segment: " + lastPathSegment); > >
Host: example.com Last Path Segment: resource

That's it! This is how you can obtain the last path segment of a URI in Java using the Apache Commons URIUtils class.

Источник

Оцените статью