test_class.declarator: DOUBLE_TOLERANCE = .0000000001
test_class.modifier: private static final
test_class.original_string: private static final double DOUBLE_TOLERANCE = .0000000001;
test_class.type: double
test_class.var_name: DOUBLE_TOLERANCE
test_class.declarator: dispatcher
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private CommandDispatcher dispatcher;
test_class.type: CommandDispatcher
test_class.var_name: dispatcher
test_class.declarator: geoService
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private GeoService geoService;
test_class.type: GeoService
test_class.var_name: geoService
test_class.declarator: dtoConverter
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private DtoConverterService dtoConverter;
test_class.type: DtoConverterService
test_class.var_name: dtoConverter
test_class.file: command/src/test/java/org/geomajas/command/geometry/MergePolygonCommandTest.java
test_class.identifier: MergePolygonCommandTest
test_case.body: @Test
  	public void testMergePolygon() throws Exception {
  		MergePolygonRequest request = new MergePolygonRequest();
  		GeometryFactory factory = new GeometryFactory();
  		request.setPolygons(new Geometry[] {
  				dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(0, 0)), 10, 10)),
  				dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(5, 5)), 10, 10))});
  		MergePolygonResponse response = (MergePolygonResponse) dispatcher.execute(
  				MergePolygonRequest.COMMAND, request, null, "en");
  		if (response.isError()) {
  			response.getErrors().get(0).printStackTrace();
  		}
  		Assert.assertFalse(response.isError());
  		Assert.assertNotNull(response.getGeometry());
  		// @todo should verify that merge is correct
  	}
test_case.class_method_signature: MergePolygonCommandTest.testMergePolygon()
test_case.full_signature: @Test public void testMergePolygon()
test_case.identifier: testMergePolygon
test_case.invocations: setPolygons toDto createCircle createPoint toDto createCircle createPoint execute isError printStackTrace get getErrors assertFalse isError assertNotNull getGeometry
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMergePolygon()
focal_class.declarator: converter
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private DtoConverterService converter;
focal_class.type: DtoConverterService
focal_class.var_name: converter
focal_class.file: command/src/main/java/org/geomajas/command/geometry/MergePolygonCommand.java
focal_class.identifier: MergePolygonCommand
focal_class.interfaces: implements CommandHasRequest<MergePolygonRequest, MergePolygonResponse>
focal_class.class_method_signature: MergePolygonCommand.getEmptyCommandRequest()
focal_class.full_signature: @Override public MergePolygonRequest getEmptyCommandRequest()
focal_class.identifier: getEmptyCommandRequest
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: MergePolygonRequest
focal_class.signature: MergePolygonRequest getEmptyCommandRequest()
focal_class.class_method_signature: MergePolygonCommand.getEmptyCommandResponse()
focal_class.full_signature: @Override public MergePolygonResponse getEmptyCommandResponse()
focal_class.identifier: getEmptyCommandResponse
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: MergePolygonResponse
focal_class.signature: MergePolygonResponse getEmptyCommandResponse()
focal_class.class_method_signature: MergePolygonCommand.execute(MergePolygonRequest request, MergePolygonResponse response)
focal_class.full_signature: @Override public void execute(MergePolygonRequest request, MergePolygonResponse response)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (MergePolygonRequest request, MergePolygonResponse response)
focal_class.return: void
focal_class.signature: void execute(MergePolygonRequest request, MergePolygonResponse response)
focal_method.body: @Override
  	public void execute(MergePolygonRequest request, MergePolygonResponse response) throws Exception {
  		Polygon[] polygons = new Polygon[request.getPolygons().length];
  		for (int i = 0; i < request.getPolygons().length; i++) {
  			try {
  				polygons[i] = (Polygon) converter.toInternal(request.getPolygons()[i]);
  			} catch (Exception e) {
  				throw new GeomajasException(e, ExceptionCode.MERGE_NO_POLYGON);
  			}
  		}
  		int precision = polygons[0].getPrecisionModel().getMaximumSignificantDigits() - 1;
  		PrecisionModel precisionModel = new PrecisionModel(Math.pow(10.0, precision));
  		GeometryFactory factory = new GeometryFactory(precisionModel, polygons[0].getSRID());
  
  		Geometry temp = factory.createGeometry(polygons[0]);
  		for (int i = 1; i < polygons.length; i++) {
  			Geometry polygon = factory.createGeometry(polygons[i]);
  			temp = temp.union(polygon.buffer(Math.pow(10.0, -(precision - 1))));
  		}
  		if (temp instanceof Polygon) {
  			MultiPolygon mp = factory.createMultiPolygon(new Polygon[] { (Polygon) temp });
  			response.setGeometry(converter.toDto(mp));
  		} else if (temp instanceof MultiPolygon && temp.getNumGeometries() != 0
  				&& (request.isAllowMultiPolygon() || temp.getNumGeometries() == 1)) {
  			response.setGeometry(converter.toDto(temp));
  		} else {
  			throw new GeomajasException(ExceptionCode.MERGE_NO_POLYGON);
  		}
  	}
focal_method.class_method_signature: MergePolygonCommand.execute(MergePolygonRequest request, MergePolygonResponse response)
focal_method.full_signature: @Override public void execute(MergePolygonRequest request, MergePolygonResponse response)
focal_method.identifier: execute
focal_method.invocations: getPolygons getPolygons toInternal getPolygons getMaximumSignificantDigits getPrecisionModel pow getSRID createGeometry createGeometry union buffer pow createMultiPolygon setGeometry toDto getNumGeometries isAllowMultiPolygon getNumGeometries setGeometry toDto
focal_method.modifiers: @Override public
focal_method.parameters: (MergePolygonRequest request, MergePolygonResponse response)
focal_method.return: void
focal_method.signature: void execute(MergePolygonRequest request, MergePolygonResponse response)