@Override public int compare(AddressNode an1, AddressNode an2) { Address a1 = an1.getAddress(); Address a2 = an2.getAddress(); int result = ObjectUtils.compare(a1.getCityName(), a2.getCityName()); if (result == 0) { result = ObjectUtils.compare(a1.getPostcode(), a2.getPostcode()); } ; if (result == 0) { result = ObjectUtils.compare(a1.getStreetName(), a2.getStreetName()); } ; if (result == 0) { result = ObjectUtils.compare(a1.getHouseNumber(), a2.getHouseNumber()); } ; return result; }
/** test the construction of the object in the ApplicationContext */ public final void testObjectConstruction() { // get a member from the application context Address address = CoreObjectFactory.getAddress(); assertEquals("City", null, address.getCity()); assertEquals("Country", null, address.getCountry()); assertEquals("PostalCode", null, address.getPostalCode()); assertEquals("StreetName", null, address.getStreetName()); assertEquals("StreetNumber", null, address.getStreetNumber()); }
@Override public String getFormattedAddress() { return address.getStreetName() + ", " + address.getHouseName() + " \n" + address.getCityName().toUpperCase() + " \n" + address.getPostalCode() + " \n" + address.getCountryName().toUpperCase(); }
public static void main(String[] args) { String path = System.getProperty("user.dir") + File.separator + "etc"; File file = new File(path, "employee2.xml"); Digester digester = new Digester(); digester.addRuleSet(new EmployeeRuleSet()); try { Employee employee = (Employee) digester.parse(file); ArrayList offices = employee.getOffices(); Iterator iterator = offices.iterator(); System.out.println("-------------------------------------------------"); while (iterator.hasNext()) { Office office = (Office) iterator.next(); Address address = office.getAddress(); System.out.println(office.getDescription()); System.out.println( "Address : " + address.getStreetNumber() + " " + address.getStreetName()); System.out.println("--------------------------------"); } } catch (Exception e) { e.printStackTrace(); } }
public void write(Parcel parcel) { System.out.println(parcel); /* * We create a FeatureCollection into which we will put each Feature created from a record * in the input csv data file */ DefaultFeatureCollection collection = new DefaultFeatureCollection("internal", TYPE); /* * GeometryFactory will be used to create the geometry attribute of each feature (a Point * object for the location) */ // GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(TYPE); builder.add(parcel.getCadastralNumber()); builder.add(parcel.getState()); builder.add(parcel.getDateCreated()); builder.add(parcel.getArea()); builder.add(parcel.getAreaUnit()); builder.add(parcel.getName()); builder.add(parcel.getLocationInBounds()); Address address = parcel.getAddress(); builder.add(address.getOkato()); builder.add(address.getKladr()); builder.add(address.getRegion()); builder.add(address.getDistrictName()); builder.add(address.getDistrictType()); builder.add(address.getCityName()); builder.add(address.getCityType()); builder.add(address.getLocalityName()); builder.add(address.getLocalityType()); builder.add(address.getStreetName()); builder.add(address.getStreetType()); builder.add(address.getLevel1Value()); builder.add(address.getNote()); builder.add(parcel.getCategory()); builder.add(parcel.getUtilization()); builder.add(parcel.getUtilizationByDoc()); builder.add(parcel.getCadastralCost()); builder.add(parcel.getCadastralUnit()); if (parcel.getEntitySpatial() != null && parcel.getEntitySpatial().getSpatialElements() != null && parcel.getEntitySpatial().getSpatialElements().size() > 0) { // GeometryFactory geometryFactory = new GeometryFactory(); // Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84); // PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints); GeometryBuilder geometryBuilder = new GeometryBuilder(crs); PointArray points = null; // List<Point> points = new ArrayList<>(); for (SpatialElement spatialElement : parcel.getEntitySpatial().getSpatialElements()) { for (SpelementUnit spelementUnit : spatialElement.getSpelementUnits()) { for (Ordinate ordinate : spelementUnit.getOrdinates()) { double longitude = ordinate.getX(); double latitude = ordinate.getY(); int number = ordinate.getOrdNmb(); /* Longitude (= x coord) first ! */ Point point = geometryBuilder.createPoint(new double[] {longitude, latitude}); // Point point = primitiveFactory.createPoint(new double[]{longitude, latitude}); points.add(number, point); } SimpleFeature feature = builder.buildFeature(null); collection.add(feature); } } builder.add(geometryBuilder.createPolygon(geometryBuilder.createSurfaceBoundary(points))); // geometryFactory.createMultiPolygon(new Polygon[]{}); } /* * Write the features to the shapefile */ Transaction transaction = new DefaultTransaction("create"); String typeName = null; try { typeName = newDataStore.getTypeNames()[0]; } catch (IOException e) { e.printStackTrace(); } SimpleFeatureSource featureSource = null; try { featureSource = newDataStore.getFeatureSource(typeName); } catch (IOException e) { e.printStackTrace(); } if (featureSource instanceof SimpleFeatureStore) { SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; featureStore.setTransaction(transaction); try { featureStore.addFeatures(collection); transaction.commit(); } catch (Exception problem) { problem.printStackTrace(); try { transaction.rollback(); } catch (IOException e) { e.printStackTrace(); } } finally { try { transaction.close(); } catch (IOException e) { e.printStackTrace(); } } } else { System.out.println(typeName + " does not support read/write access"); } }