com.cloudinary.Coordinates Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudinary-core Show documentation
Show all versions of cloudinary-core Show documentation
Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. Upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your websiteâs graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more. This Java library allows to easily integrate with Cloudinary in Java applications.
The newest version!
package com.cloudinary;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import com.cloudinary.utils.Rectangle;
import com.cloudinary.utils.StringUtils;
public class Coordinates implements Serializable{
Collection coordinates = new ArrayList();
public Coordinates() {
}
public Coordinates(Collection coordinates) {
this.coordinates = coordinates;
}
public Coordinates(int[] rect) {
Collection coordinates = new ArrayList();
if (rect.length != 4) {
throw new IllegalArgumentException("Must supply exactly 4 values for coordinates (x,y,width,height)");
}
coordinates.add(new Rectangle(rect[0], rect[1], rect[2], rect[3]));
this.coordinates = coordinates;
}
public Coordinates(Rectangle rect) {
Collection coordinates = new ArrayList();
coordinates.add(rect);
this.coordinates = coordinates;
}
public Coordinates(String stringCoords) throws IllegalArgumentException {
Collection coordinates = new ArrayList();
for (String stringRect : stringCoords.split("\\|")) {
if (StringUtils.isEmpty(stringRect))
continue;
String[] elements = stringRect.split(",");
if (elements.length != 4) {
throw new IllegalArgumentException(String.format("Must supply exactly 4 values for coordinates (x,y,width,height) %d supplied: %s",
elements.length, stringRect));
}
coordinates.add(new Rectangle(Integer.parseInt(elements[0]), Integer.parseInt(elements[1]), Integer.parseInt(elements[2]), Integer
.parseInt(elements[3])));
}
this.coordinates = coordinates;
}
public static Coordinates parseCoordinates(Object coordinates) throws IllegalArgumentException {
if (coordinates instanceof Coordinates) {
return (Coordinates) coordinates;
} else if (coordinates instanceof int[]) {
return new Coordinates((int[]) coordinates);
} else if (coordinates instanceof Rectangle) {
return new Coordinates((Rectangle) coordinates);
} else {
return new Coordinates(coordinates.toString());
}
}
public void addRect(Rectangle rect) {
this.coordinates.add(rect);
}
public Collection underlaying() {
return this.coordinates;
}
@Override
public String toString() {
ArrayList rects = new ArrayList();
for (Rectangle rect : this.coordinates) {
rects.add(rect.x + "," + rect.y + "," + rect.width + "," + rect.height);
}
return StringUtils.join(rects, "|");
}
}