use of com.forstudy.efjava.ch03.item10.Point in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
if (projectId == null) {
System.err.println("Usage: QuickstartSample -DprojectId=YOUR_PROJECT_ID");
return;
}
// Instantiates a client
MetricServiceClient metricServiceClient = MetricServiceClient.create();
// Prepares an individual data point
TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
TypedValue value = TypedValue.newBuilder().setDoubleValue(3.14).build();
Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
List<Point> pointList = new ArrayList<>();
pointList.add(point);
ProjectName name = ProjectName.of(projectId);
// Prepares the metric descriptor
Map<String, String> metricLabels = new HashMap<String, String>();
metricLabels.put("store_id", "Pittsburg");
Metric metric = Metric.newBuilder().setType("custom.googleapis.com/my_metric").putAllLabels(metricLabels).build();
// Prepares the monitored resource descriptor
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put("instance_id", "1234567890123456789");
resourceLabels.put("zone", "us-central1-f");
MonitoredResource resource = MonitoredResource.newBuilder().setType("gce_instance").putAllLabels(resourceLabels).build();
// Prepares the time series request
TimeSeries timeSeries = TimeSeries.newBuilder().setMetric(metric).setResource(resource).addAllPoints(pointList).build();
List<TimeSeries> timeSeriesList = new ArrayList<>();
timeSeriesList.add(timeSeries);
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(name.toString()).addAllTimeSeries(timeSeriesList).build();
// Writes time series data
metricServiceClient.createTimeSeries(request);
System.out.printf("Done writing time series data.%n");
metricServiceClient.close();
}
use of com.forstudy.efjava.ch03.item10.Point in project CoreJava by alekseiiagnenkov.
the class Lab12 method main.
public static void main(String[] args) {
Point point = new Point(0, 1);
long time = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
point.getX();
}
System.out.println("Time:" + (System.currentTimeMillis() - time));
try {
long timeRef = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
point.getClass().getMethod("getX").invoke(point);
}
System.out.println("TimeRef:" + (System.currentTimeMillis() - timeRef));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
use of com.forstudy.efjava.ch03.item10.Point in project CoreJava by alekseiiagnenkov.
the class Lab9 method main.
public static void main(String[] args) {
Point point = new Point(0, 0);
Shape circle = new Circle(new Point(0, 0), 20);
Queue<Integer> queue = new Queue<>();
queue.add(1);
queue.add(2);
queue.add(3);
Queue.Iterator iterator = queue.iterator();
Integer a = 0;
Character[] strings = { '1', '2', '3' };
Object[] objects = { strings, 0, a, point, queue, iterator, circle, staticPoint };
for (Object obj : objects) {
System.out.println(toString(obj));
}
}
use of com.forstudy.efjava.ch03.item10.Point in project cg by nmahoude.
the class Simulation method simulate.
/**
* simulate the move of any player (dir1, dir2 not null)
*
* Pre-requisite : the move is valid only one player will move
*
* GameState is backedup
*
* @return true if the move is valid
*/
public void simulate(Move move, GameState state) {
this.move = move;
this.state = state;
this.agent = state.agents[move.id];
Point target = agent.position.get(move.dir1);
int targetX = agent.x + move.dir1.dx;
int targetY = agent.y + move.dir1.dy;
if (!state.isValid(targetX, targetY)) {
move.dir1Invalid();
return;
}
int occupiedBy = state.occupiedBy(targetX, targetY);
if (occupiedBy == -1) {
move.isPush = false;
computeMove();
return;
} else {
// potential push
if (state.isFriendly(move.id, targetX, targetY)) {
move.dir1Invalid();
return;
}
move.isPush = true;
computePush();
return;
}
}
use of com.forstudy.efjava.ch03.item10.Point in project ddf by codice.
the class KmlToJtsGeometryConverterTest method testConvertPointGeometry.
@Test
public void testConvertPointGeometry() {
InputStream stream = KmlToJtsGeometryConverterTest.class.getResourceAsStream("/kmlPoint.kml");
Kml kml = Kml.unmarshal(stream);
assertThat(kml, notNullValue());
Point kmlPoint = ((Point) ((Placemark) kml.getFeature()).getGeometry());
assertThat(kmlPoint, notNullValue());
org.locationtech.jts.geom.Geometry jtsGeometryPoint = KmlToJtsGeometryConverter.from(kmlPoint);
assertThat(jtsGeometryPoint, instanceOf(org.locationtech.jts.geom.Point.class));
assertSpecificGeometry(kmlPoint, jtsGeometryPoint);
}
Aggregations