===================================================================== Found a 204 line (728 tokens) duplication in the following files: Starting at line 39 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/ImageLoader.java Starting at line 39 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/ImageLoader.java class ImageLoader implements Runnable { /** The logger for the rendering module. */ private static final Logger LOGGER = Logger.getLogger("org.geotools.rendering"); /** The images managed by the loader */ private static Map images = new HashMap(); /** A canvas used as the image observer on the tracker */ private static Canvas obs = new Canvas(); /** Used to track the images loading status */ private static MediaTracker tracker = new MediaTracker(obs); /** Currently loading image */ private static int imageID = 1; /** A maximum time to wait for the image to load */ private static long timeout = 10000; /** Location of the loading image */ private URL location; /** Still waiting for the image? */ private boolean waiting = true; /** * Returns the timeout for aborting an image loading sequence * * @return the timeout in milliseconds */ public static long getTimeout() { return timeout; } /** * Sets the maximum time to wait for getting an external image. Set it to -1 to wait * undefinitely * * @param newTimeout the new timeout value in milliseconds */ public static void setTimeout(long newTimeout) { timeout = newTimeout; } /** * Add an image to be loaded by the ImageLoader * * @param location the image location * @param interactive if true the methods returns immediatly, otherwise waits for the image to * be loaded */ private void add(URL location, boolean interactive) { int imgId = imageID; this.location = location; LOGGER.finest("adding image, interactive? " + interactive); Thread t = new Thread(this); t.start(); if (interactive) { LOGGER.finest("fast return"); return; } else { waiting = true; long elapsed = 0; final long step = 500; while (waiting && (elapsed < timeout || timeout < 0)) { LOGGER.finest("waiting..." + waiting); try { Thread.sleep(step); elapsed += step; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Waiting for image " + location + ", elapsed " + elapsed + " milliseconds"); } } catch (InterruptedException e) { LOGGER.warning(e.toString()); } } if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest(imgId + " complete?: " + (isFlagUp(imgId, MediaTracker.COMPLETE))); LOGGER.finest(imgId + " abort?: " + (isFlagUp(imgId, MediaTracker.ABORTED))); LOGGER.finest(imgId + " error?: " + (isFlagUp(imgId, MediaTracker.ERRORED))); LOGGER.finest(imgId + " loading?: " + (isFlagUp(imgId, MediaTracker.LOADING))); LOGGER.finest(imgId + "slow return " + waiting); } return; } } /** * Checks the state of the current tracker against a flag * * @param id the image id * @param flag the flag to be checked * * @return true if the flag is up */ private boolean isFlagUp(int id, int flag) { return (tracker.statusID(id, true) & flag) == flag; } /** * Fetch a buffered image from the loader, if interactive is false then the loader will wait * for the image to be available before returning, used by printers and file output * renderers. If interactive is true and the image is ready then return, if image is not ready * start loading it and return null. The renderer is responsible for finding an alternative * to use. * * @param location the url of the image to be fetched * @param interactive boolean to signal if the loader should wait for the image to be ready. * * @return the buffered image or null */ public BufferedImage get(URL location, boolean interactive) { if (images.containsKey(location)) { LOGGER.finest("found it"); return (BufferedImage) images.get(location); } else { if (!interactive) { images.put(location, null); } LOGGER.finest("adding " + location); add(location, interactive); return (BufferedImage) images.get(location); } } /** * Runs the loading thread */ public void run() { int myID = 0; Image img = null; try { img = Toolkit.getDefaultToolkit().createImage(location); myID = imageID++; tracker.addImage(img, myID); } catch (Exception e) { LOGGER.warning("Exception fetching image from " + location + "\n" + e); images.remove(location); waiting = false; return; } try { while ((tracker.statusID(myID, true) & MediaTracker.LOADING) != 0) { tracker.waitForID(myID, 500); LOGGER.finest(myID + "loading - waiting...."); } } catch (InterruptedException ie) { LOGGER.warning(ie.toString()); } int state = tracker.statusID(myID, true); if (state == MediaTracker.ERRORED) { LOGGER.finer("" + myID + " Error loading"); // images.remove(location); waiting = false; return; } if ((state & MediaTracker.COMPLETE) == MediaTracker.COMPLETE) { LOGGER.finest("" + myID + "completed load"); int iw = img.getWidth(obs); int ih = img.getHeight(obs); BufferedImage bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); big.drawImage(img, 0, 0, obs); images.put(location, bi); waiting = false; return; } LOGGER.finer("" + myID + " whoops - some other outcome " + state); waiting = false; return; } /** * Resets the image cache */ public void reset() { images.clear(); } } ===================================================================== Found a 107 line (463 tokens) duplication in the following files: Starting at line 44 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/attributes/RangeFeatureValidationTest.java Starting at line 44 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/attributes/NullZeroValidationTest.java public NullZeroValidationTest(String arg0) { super(arg0); } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { GeometryFactory gf = new GeometryFactory(); test = new RangeValidation(); super.setUp(); type = DataUtilities.createType(getName()+".road", "id:0,*geom:LineString,name:String"); Coordinate[] coords = new Coordinate[]{ new Coordinate(1, 1), new Coordinate( 2, 2), new Coordinate (4, 2), new Coordinate (5, 1)}; feature = type.create(new Object[] { new Integer(1), gf.createLineString(coords), "r1", }, "road.rd1" ); results = new RoadValidationResults(); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { test = null; super.tearDown(); } public void testRangeFeatureValidation() throws Exception { test.setPath("id"); assertTrue(test.validate(feature, type, results)); assertEquals(0,results.failedFeatures.size()); test.setMin(5); assertTrue(!test.validate(feature, type, results)); assertEquals(1,results.failedFeatures.size()); } public void testValidate() { //test.validate(feature, type, results); } public void testSetName() { test.setName("foo"); assertEquals("foo", test.getName()); } public void testGetName() { test.setName("bork"); assertEquals("bork", test.getName()); } public void testSetDescription() { test.setDescription("foo"); assertEquals("foo", test.getDescription()); } public void testGetDescription() { test.setDescription("bork"); assertEquals("bork", test.getDescription()); } public void testGetPriority() { //TODO Implement getPriority(). } public void testGetMax() { test.setMax(100); assertEquals(100, test.getMax()); } public void testGetMin() { test.setMin(10); assertEquals(10, test.getMin()); } public void testGetPath() { test.setPath("path"); assertEquals("path", test.getPath()); } public void testSetMax() { test.setMax(500); assertEquals(500, test.getMax()); } public void testSetMin() { test.setMin(5); assertEquals(5, test.getMin()); } public void testSetPath() { test.setPath("path2"); assertEquals("path2", test.getPath()); } } ===================================================================== Found a 58 line (427 tokens) duplication in the following files: Starting at line 50 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/Java2DMark.java Starting at line 37 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/Java2DMark.java static Shape X; static { cross = new GeneralPath(GeneralPath.WIND_EVEN_ODD); cross.moveTo(0.5f, 0.125f); cross.lineTo(0.125f, 0.125f); cross.lineTo(0.125f, 0.5f); cross.lineTo(-0.125f, 0.5f); cross.lineTo(-0.125f, 0.125f); cross.lineTo(-0.5f, 0.125f); cross.lineTo(-0.5f, -0.125f); cross.lineTo(-0.125f, -0.125f); cross.lineTo(-0.125f, -0.5f); cross.lineTo(0.125f, -0.5f); cross.lineTo(0.125f, -0.125f); cross.lineTo(0.5f, -0.125f); cross.lineTo(0.5f, 0.125f); AffineTransform at = new AffineTransform(); at.rotate(Math.PI / 4.0); X = cross.createTransformedShape(at); star = new GeneralPath(GeneralPath.WIND_EVEN_ODD); star.moveTo(0.191f, 0.0f); star.lineTo(0.25f, 0.344f); star.lineTo(0.0f, 0.588f); star.lineTo(0.346f, 0.638f); star.lineTo(0.5f, 0.951f); star.lineTo(0.654f, 0.638f); star.lineTo(1.0f, 0.588f); // max = 7.887 star.lineTo(0.75f, 0.344f); star.lineTo(0.89f, 0f); star.lineTo(0.5f, 0.162f); star.lineTo(0.191f, 0.0f); at = new AffineTransform(); at.translate(-.5, -.5); star.transform(at); triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD); triangle.moveTo(0f, 1f); triangle.lineTo(0.866f, -.5f); triangle.lineTo(-0.866f, -.5f); triangle.lineTo(0f, 1f); at = new AffineTransform(); at.translate(0, -.25); at.scale(.5, .5); triangle.transform(at); arrow = new GeneralPath(GeneralPath.WIND_EVEN_ODD); arrow.moveTo(0f, -.5f); arrow.lineTo(.5f, 0f); arrow.lineTo(0f, .5f); arrow.lineTo(0f, .1f); arrow.lineTo(-.5f, .1f); arrow.lineTo(-.5f, -.1f); arrow.lineTo(0f, -.1f); arrow.lineTo(0f, -.5f); } ===================================================================== Found a 50 line (403 tokens) duplication in the following files: Starting at line 35 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/FilterTransformer.java Starting at line 60 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/XMLEncoder.java private static Map comparisions = new HashMap(); /** Map of spatial types to sql representation */ private static Map spatial = new HashMap(); /** Map of logical types to sql representation */ private static Map logical = new HashMap(); /** Map of expression types to sql representation */ private static Map expressions = new HashMap(); static { comparisions.put(new Integer(AbstractFilter.COMPARE_EQUALS), "PropertyIsEqualTo"); comparisions.put(new Integer(AbstractFilter.COMPARE_GREATER_THAN), "PropertyIsGreaterThan"); comparisions.put(new Integer(AbstractFilter.COMPARE_GREATER_THAN_EQUAL), "PropertyIsGreaterThanOrEqualTo"); comparisions.put(new Integer(AbstractFilter.COMPARE_LESS_THAN), "PropertyIsLessThan"); comparisions.put(new Integer(AbstractFilter.COMPARE_LESS_THAN_EQUAL), "PropertyIsLessThanOrEqualTo"); comparisions.put(new Integer(AbstractFilter.LIKE), "PropertyIsLike"); comparisions.put(new Integer(AbstractFilter.NULL), "PropertyIsNull"); comparisions.put(new Integer(AbstractFilter.BETWEEN), "PropertyIsBetween"); expressions.put(new Integer(DefaultExpression.MATH_ADD), "Add"); expressions.put(new Integer(DefaultExpression.MATH_DIVIDE), "Div"); expressions.put(new Integer(DefaultExpression.MATH_MULTIPLY), "Mul"); expressions.put(new Integer(DefaultExpression.MATH_SUBTRACT), "Sub"); expressions.put(new Integer(DefaultExpression.FUNCTION), "Function"); //more to come spatial.put(new Integer(AbstractFilter.GEOMETRY_EQUALS), "Equals"); spatial.put(new Integer(AbstractFilter.GEOMETRY_DISJOINT), "Disjoint"); spatial.put(new Integer(AbstractFilter.GEOMETRY_INTERSECTS), "Intersects"); spatial.put(new Integer(AbstractFilter.GEOMETRY_TOUCHES), "Touches"); spatial.put(new Integer(AbstractFilter.GEOMETRY_CROSSES), "Crosses"); spatial.put(new Integer(AbstractFilter.GEOMETRY_WITHIN), "Within"); spatial.put(new Integer(AbstractFilter.GEOMETRY_CONTAINS), "Contains"); spatial.put(new Integer(AbstractFilter.GEOMETRY_OVERLAPS), "Overlaps"); spatial.put(new Integer(AbstractFilter.GEOMETRY_BEYOND), "Beyond"); spatial.put(new Integer(AbstractFilter.GEOMETRY_BBOX), "BBOX"); logical.put(new Integer(AbstractFilter.LOGIC_AND), "And"); logical.put(new Integer(AbstractFilter.LOGIC_OR), "Or"); logical.put(new Integer(AbstractFilter.LOGIC_NOT), "Not"); } ===================================================================== Found a 79 line (397 tokens) duplication in the following files: Starting at line 66 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/filter/SQLEncoderPostgisTest.java Starting at line 53 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/FilterTestSupport.java } protected void setUp() throws SchemaException, IllegalAttributeException { if (setup) { return; } else { prepareFeatures(); } setup = true; } protected void prepareFeatures() throws SchemaException, IllegalAttributeException { //_log.getLoggerRepository().setThreshold(Level.INFO); // Create the schema attributes LOGGER.finer("creating flat feature..."); AttributeType geometryAttribute = attFactory.newAttributeType("testGeometry", LineString.class); LOGGER.finer("created geometry attribute"); AttributeType booleanAttribute = attFactory.newAttributeType("testBoolean", Boolean.class); LOGGER.finer("created boolean attribute"); AttributeType charAttribute = attFactory.newAttributeType("testCharacter", Character.class); AttributeType byteAttribute = attFactory.newAttributeType("testByte", Byte.class); AttributeType shortAttribute = attFactory.newAttributeType("testShort", Short.class); AttributeType intAttribute = attFactory.newAttributeType("testInteger", Integer.class); AttributeType longAttribute = attFactory.newAttributeType("testLong", Long.class); AttributeType floatAttribute = attFactory.newAttributeType("testFloat", Float.class); AttributeType doubleAttribute = attFactory.newAttributeType("testDouble", Double.class); AttributeType stringAttribute = attFactory.newAttributeType("testString", String.class); AttributeType[] types = { geometryAttribute, booleanAttribute, charAttribute, byteAttribute, shortAttribute, intAttribute, longAttribute, floatAttribute, doubleAttribute, stringAttribute }; // Builds the schema testSchema = FeatureTypeFactory.newFeatureType(types,"testSchema"); GeometryFactory geomFac = new GeometryFactory(); // Creates coordinates for the linestring Coordinate[] coords = new Coordinate[3]; coords[0] = new Coordinate(1, 2); coords[1] = new Coordinate(3, 4); coords[2] = new Coordinate(5, 6); // Builds the test feature Object[] attributes = new Object[10]; attributes[0] = geomFac.createLineString(coords); attributes[1] = new Boolean(true); attributes[2] = new Character('t'); attributes[3] = new Byte("10"); attributes[4] = new Short("101"); attributes[5] = new Integer(1002); attributes[6] = new Long(10003); attributes[7] = new Float(10000.4); attributes[8] = new Double(100000.5); attributes[9] = "test string data"; // Creates the feature itself testFeature = testSchema.create(attributes); LOGGER.finer("...flat feature created"); //_log.getLoggerRepository().setThreshold(Level.DEBUG); } ===================================================================== Found a 60 line (367 tokens) duplication in the following files: Starting at line 63 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/MathTest.java Starting at line 61 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/AttributeTest.java }, "test"); Feature[] f = new Feature[3]; f[0] = schema.create(new Object[] { new Integer(12), new GeometryCollection(null, null, -1), "first" }); f[1] = schema.create(new Object[] { new Integer(3), new GeometryCollection(null, null, -1), "second" }); f[2] = schema.create(new Object[] { new Integer(15), new GeometryCollection(null, null, -1), "third" }); return f; } public void testTypeMissmatch() throws Exception { Feature[] f = sampleFeatures(); //the following are intentionaly backwards AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); boolean pass = false; Object value = null; value = e1.getValue(f[0]); if (value instanceof Integer) { pass = true; } assertTrue("String expresion returned an Integer", pass); pass = false; value = e2.getValue(f[0]); if (value instanceof String) { pass = true; } assertTrue("Integer expresion returned a String", pass); } public void testSetupAndExtraction() throws Exception { //this should move out to a more configurable system run from scripts //but we can start with a set of hard coded tests Feature[] f = sampleFeatures(); AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); assertEquals(12d, ((Integer) e1.getValue(f[0])).doubleValue(), 0); assertEquals(3d, ((Integer) e1.getValue(f[1])).doubleValue(), 0); assertEquals(15d, ((Integer) e1.getValue(f[2])).doubleValue(), 0); assertEquals("first", (String) e2.getValue(f[0])); assertEquals("second", (String) e2.getValue(f[1])); } } ===================================================================== Found a 53 line (342 tokens) duplication in the following files: Starting at line 2438 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 296 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/j2d/SLDRenderedGeometries.java double[] first = new double[2]; double[] previous = new double[2]; type = pi.currentSegment(coords); first[0] = coords[0]; first[1] = coords[1]; previous[0] = coords[0]; previous[1] = coords[1]; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("starting at " + first[0] + "," + first[1]); } pi.next(); while (!pi.isDone()) { type = pi.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: // nothing to do? if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("moving to " + coords[0] + "," + coords[1]); } break; case PathIterator.SEG_CLOSE: // draw back to first from previous coords[0] = first[0]; coords[1] = first[1]; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("closing from " + previous[0] + "," + previous[1] + " to " + coords[0] + "," + coords[1]); } // no break here - fall through to next section case PathIterator.SEG_LINETO: // draw from previous to coords if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("drawing from " + previous[0] + "," + previous[1] + " to " + coords[0] + "," + coords[1]); } double dx = coords[0] - previous[0]; double dy = coords[1] - previous[1]; double len = Math.sqrt((dx * dx) + (dy * dy)); // - imageWidth; double theta = Math.atan2(dx, dy); dx = (Math.sin(theta) * imageSize); ===================================================================== Found a 100 line (337 tokens) duplication in the following files: Starting at line 95 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/CrossesIntegrity.java Starting at line 96 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/OverlapsIntegrity.java public OverlapsIntegrity() { super(); usedIDs = new HashSet(); //TODO: remove me later, memory inefficient } /* (non-Javadoc) * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { LOGGER.finer("Starting test "+getName()+" ("+getClass().getName()+")" ); String typeRef1 = getGeomTypeRefA(); LOGGER.finer( typeRef1 +": looking up FeatureSource " ); FeatureSource geomSource1 = (FeatureSource) layers.get( typeRef1 ); LOGGER.finer( typeRef1 +": found "+ geomSource1.getSchema().getTypeName() ); String typeRef2 = getGeomTypeRefB(); if (typeRef2 == EMPTY || typeRef1.equals(typeRef2)) return validateSingleLayer(geomSource1, isExpected(), results, envelope); else { LOGGER.finer( typeRef2 +": looking up FeatureSource " ); FeatureSource geomSource2 = (FeatureSource) layers.get( typeRef2 ); LOGGER.finer( typeRef2 +": found "+ geomSource2.getSchema().getTypeName() ); return validateMultipleLayers(geomSource1, geomSource2, isExpected(), results, envelope); } } /** * validateMultipleLayers Purpose:
*

* This validation tests for a geometry overlaps another geometry. * Uses JTS' Geometry.overlaps(Geometry) and Geometry.contains(Geometry)method. * The DE-9IM intersection matrix for overlaps is: * T*T***T** (for two points or two surfaces) * 1*T***T** (for two curves) * Contains DE-9IM intersection matrix is T*F**F***. *

* * Description:
*

* The function filters the FeatureSources using the given bounding box. * It creates iterators over both filtered FeatureSources. It calls overlaps() and contains()using the * geometries in the FeatureSource layers. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. This geometry is the one that is tested for overlaping with the other * @param featureSourceB - the FeatureSource to pull the other geometries from - these geometries will be those that may overlap the first geometry * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the overlaps() and contains() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateMultipleLayers( FeatureSource featureSourceA, FeatureSource featureSourceB, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResultsA = featureSourceA.getFeatures(filter); FeatureResults featureResultsB = featureSourceB.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResultsA.reader(); if (fr1 == null) return success; while (fr1.hasNext()) { Feature f1 = fr1.next(); Geometry g1 = f1.getDefaultGeometry(); fr2 = featureResultsB.reader(); while (fr2 != null && fr2.hasNext()) { Feature f2 = fr2.next(); Geometry g2 = f2.getDefaultGeometry(); ===================================================================== Found a 97 line (335 tokens) duplication in the following files: Starting at line 56 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/DisjointIntegrity.java Starting at line 58 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/ContainsIntegrity.java Starting at line 64 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/WithinIntegrity.java Starting at line 66 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/TouchesIntegrity.java Starting at line 58 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/IntersectsIntegrity.java public IntersectsIntegrity() { super(); } /* (non-Javadoc) * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { LOGGER.finer("Starting test "+getName()+" ("+getClass().getName()+")" ); String typeRef1 = getGeomTypeRefA(); LOGGER.finer( typeRef1 +": looking up FeatureSource " ); FeatureSource geomSource1 = (FeatureSource) layers.get( typeRef1 ); LOGGER.finer( typeRef1 +": found "+ geomSource1.getSchema().getTypeName() ); String typeRef2 = getGeomTypeRefB(); if (typeRef2 == EMPTY || typeRef1.equals(typeRef2)) return validateSingleLayer(geomSource1, isExpected(), results, envelope); else { LOGGER.finer( typeRef2 +": looking up FeatureSource " ); FeatureSource geomSource2 = (FeatureSource) layers.get( typeRef2 ); LOGGER.finer( typeRef2 +": found "+ geomSource2.getSchema().getTypeName() ); return validateMultipleLayers(geomSource1, geomSource2, isExpected(), results, envelope); } } /** * validateMultipleLayers Purpose:
*

* This validation tests for a geometry crosses another geometry. * Uses JTS' Geometry.crosses(Geometry) method. * *

* * Description:
*

* The function filters the FeatureSources using the given bounding box. * It creates iterators over both filtered FeatureSources. It calls intersects() using the * geometries in the FeatureSource layers. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. This geometry is the one that is tested for intersecting with the other * @param featureSourceB - the FeatureSource to pull the other geometries from - these geometries will be those that may intersect the first geometry * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the intersects() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateMultipleLayers( FeatureSource featureSourceA, FeatureSource featureSourceB, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResultsA = featureSourceA.getFeatures(filter); FeatureResults featureResultsB = featureSourceB.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResultsA.reader(); if (fr1 == null) return false; while (fr1.hasNext()) { Feature f1 = fr1.next(); Geometry g1 = f1.getDefaultGeometry(); fr2 = featureResultsB.reader(); while (fr2 != null && fr2.hasNext()) { Feature f2 = fr2.next(); Geometry g2 = f2.getDefaultGeometry(); if(g1.intersects(g2) != expected ) ===================================================================== Found a 104 line (329 tokens) duplication in the following files: Starting at line 59 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/DisjointIntegrity.java Starting at line 88 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/RelateIntegrity.java } /* (non-Javadoc) * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { LOGGER.finer("Starting test "+getName()+" ("+getClass().getName()+")" ); String typeRef1 = getGeomTypeRefA(); LOGGER.finer( typeRef1 +": looking up FeatureSource " ); FeatureSource geomSource1 = (FeatureSource) layers.get( typeRef1 ); LOGGER.finer( typeRef1 +": found "+ geomSource1.getSchema().getTypeName() ); String typeRef2 = getGeomTypeRefB(); if (typeRef2 == EMPTY || typeRef1.equals(typeRef2)) return validateSingleLayer(geomSource1, isExpected(), results, envelope); else { LOGGER.finer( typeRef2 +": looking up FeatureSource " ); FeatureSource geomSource2 = (FeatureSource) layers.get( typeRef2 ); LOGGER.finer( typeRef2 +": found "+ geomSource2.getSchema().getTypeName() ); return validateMultipleLayers(geomSource1, geomSource2, isExpected(), results, envelope); } } /** * validateMultipleLayers Purpose:
*

* This validation tests for a geometry crosses another geometry. * Uses JTS' Geometry.crosses(Geometry) method. * *

* * Description:
*

* The function filters the FeatureSources using the given bounding box. * It creates iterators over both filtered FeatureSources. It calls relate() using the * geometries in the FeatureSource layers. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * * The following is taken from JTS documentation for Geometry.relate(): * "Returns true if the elements in the DE-9IM intersection matrix for the two Geometrys match the elements in intersectionPattern , which may be: * 0 * 1 * 2 * T ( = 0, 1 or 2) * F ( = -1) * * ( = -1, 0, 1 or 2) * For more information on the DE-9IM, see the OpenGIS Simple Features Specification." * * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. * @param featureSourceB - the FeatureSource to pull the other geometries from * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the intersects() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateMultipleLayers( FeatureSource featureSourceA, FeatureSource featureSourceB, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResultsA = featureSourceA.getFeatures(filter); FeatureResults featureResultsB = featureSourceB.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResultsA.reader(); if (fr1 == null) return false; while (fr1.hasNext()) { Feature f1 = fr1.next(); Geometry g1 = f1.getDefaultGeometry(); fr2 = featureResultsB.reader(); while (fr2 != null && fr2.hasNext()) { Feature f2 = fr2.next(); Geometry g2 = f2.getDefaultGeometry(); if(g1.relate(g2, de9im) != expected) ===================================================================== Found a 36 line (316 tokens) duplication in the following files: Starting at line 434 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderStyleTest.java Starting at line 344 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderingGridCoverageTest.java final double scalex = width / dataWidth; final double scaley = height / dataHeigth; java.net.URL base = getClass().getResource("rs-testData/"); AffineTransform at = new AffineTransform(); at.translate(0, height); at.scale(scalex, -scaley); if (INTERACTIVE) { java.awt.Frame frame = new java.awt.Frame("Mark test (" + renderer.getClass().getName()); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { e.getWindow().dispose(); } }); java.awt.Panel p = new java.awt.Panel(); frame.add(p); frame.setSize(width, height); frame.setLocation(0, 0); frame.setVisible(true); renderer.paint((Graphics2D) p.getGraphics(), p.getBounds(), at); Thread.sleep(5000); frame.dispose(); } java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB); java.awt.Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(java.awt.Color.white); g.fillRect(0, 0, width, height); renderer.paint(g, new java.awt.Rectangle(0, 0, width, height), at); java.io.File file = new java.io.File(base.getPath(), ===================================================================== Found a 77 line (301 tokens) duplication in the following files: Starting at line 200 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/util/WeakValueHashMap.java Starting at line 151 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/util/WeakHashSet.java public WeakHashSet() { table = new Entry[MIN_CAPACITY]; threshold = Math.round(table.length*LOAD_FACTOR); lastRehashTime = System.currentTimeMillis(); } /** * Invoked by {@link Entry} when an element has been collected * by the garbage collector. This method will remove the weak reference * from {@link #table}. */ private synchronized void removeEntry(final Entry toRemove) { assert valid() : count; final int i = toRemove.index; // Index 'i' may not be valid if the reference 'toRemove' // has been already removed in a previous rehash. if (i < table.length) { Entry prev = null; Entry e = table[i]; while (e != null) { if (e == toRemove) { if (prev != null) { prev.next = e.next; } else { table[i] = e.next; } count--; assert valid(); // If the number of elements has dimunished // significatively, rehash the table. if (count <= threshold/4) { rehash(false); } // We must not continue the loop, since // variable 'e' is no longer valid. return; } prev = e; e = e.next; } } assert valid(); /* * If we reach this point, its mean that reference 'toRemove' has not * been found. This situation may occurs if 'toRemove' has already been * removed in a previous run of {@link #rehash}. */ } /** * Rehash {@link #table}. * * @param augmentation true if this method is invoked * for augmenting {@link #table}, or false if * it is invoked for making the table smaller. */ private void rehash(final boolean augmentation) { assert Thread.holdsLock(this); assert valid(); final long currentTime = System.currentTimeMillis(); final int capacity = Math.max(Math.round(count/(LOAD_FACTOR/2)), count+MIN_CAPACITY); if (augmentation ? (capacity<=table.length) : (capacity>=table.length || currentTime-lastRehashTimevalidateMultipleLayers Purpose:
*

* This validation tests for a geometry crosses another geometry. * Uses JTS' Geometry.crosses(Geometry) method. * The DE-9IM intersection matrix for crosses is * T*T****** (for a point and a curve, a point and an area or a line and an area) * 0******** (for two curves) *

* * Description:
*

* The function filters the FeatureSources using the given bounding box. * It creates iterators over both filtered FeatureSources. It calls overlaps() and contains()using the * geometries in the FeatureSource layers. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. This geometry is the one that is tested for overlaping with the other * @param featureSourceB - the FeatureSource to pull the other geometries from - these geometries will be those that may overlap the first geometry * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the overlaps() and contains() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateMultipleLayers( FeatureSource featureSourceA, FeatureSource featureSourceB, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResultsA = featureSourceA.getFeatures(filter); FeatureResults featureResultsB = featureSourceB.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResultsA.reader(); if (fr1 == null) return success; ===================================================================== Found a 80 line (265 tokens) duplication in the following files: Starting at line 67 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineNoSelfOverlappingValidation.java Starting at line 68 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineNoSelfIntersectValidation.java } /** * Override getPriority. * *

* Sets the priority level of this validation. This is set by the * programmer and is a measure of the expense of this plugin *

* * @return A made up priority for this validation. * * @see org.geotools.validation.Validation#getPriority() */ public int getPriority() { return PRIORITY_COMPLEX; } /** * Override validate. * *

* Tests to see if a geometry intersects itself. It does not detect if a * segment of a LineString doubles back on itself for one segment, then * terminates. A different validation is needed to test overlapping. Uses * JTS' intersect routine. *

* * @param feature The Feature to be validated. * @param type The FeatureTypeInfo of the feature. * @param results The storage for error messages. * * @return True if the feature does not self intersect. * * @see org.geotools.validation.FeatureValidation#validate(org.geotools.feature.Feature, * org.geotools.feature.FeatureTypeInfo, * org.geotools.validation.ValidationResults) */ public boolean validate(Feature feature, FeatureType type, ValidationResults results) { LOGGER.setLevel(Level.ALL); LineString line = null; try { line = getDefaultLineString( feature ); } catch( ClassCastException unLine ){ results.error(feature,"Geometry is required to be a LineString"); System.out.println( feature.getID()+" name: "+getName() ); System.out.println( feature.getID()+" ref: "+getTypeRef() ); System.out.println( feature.getID()+" ref: "+getTypeRefs() ); } if (line == null) { // Ignore null geometry (user can check with nullZero ) return true; } if (line.getNumPoints() < 2) { results.warning(feature,"LineString contains too few points"); return false; } GeometryFactory gf = new GeometryFactory(); int numPoints = line.getNumPoints(); // break up the LineString into line segments LineString[] segments = new LineString[numPoints - 1]; for (int i = 0; i < (numPoints - 1); i++) { Coordinate[] coords = new Coordinate[] { line.getCoordinateN(i), line.getCoordinateN(i + 1) }; segments[i] = gf.createLineString(coords); } // intersect all of the line segments with each other for (int i = 0; i < segments.length; i++) // for each line segment { for (int j = 0; j < segments.length; j++) // intersect with every other line segment { if ((i != j) && ((i - 1) != j) && ((i + 1) != j)) // if they aren't the same segment ===================================================================== Found a 84 line (263 tokens) duplication in the following files: Starting at line 88 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/RelateIntegrity.java Starting at line 99 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/CrossesIntegrity.java } /* (non-Javadoc) * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { LOGGER.finer("Starting test "+getName()+" ("+getClass().getName()+")" ); String typeRef1 = getGeomTypeRefA(); LOGGER.finer( typeRef1 +": looking up FeatureSource " ); FeatureSource geomSource1 = (FeatureSource) layers.get( typeRef1 ); LOGGER.finer( typeRef1 +": found "+ geomSource1.getSchema().getTypeName() ); String typeRef2 = getGeomTypeRefB(); if (typeRef2 == EMPTY || typeRef1.equals(typeRef2)) return validateSingleLayer(geomSource1, isExpected(), results, envelope); else { LOGGER.finer( typeRef2 +": looking up FeatureSource " ); FeatureSource geomSource2 = (FeatureSource) layers.get( typeRef2 ); LOGGER.finer( typeRef2 +": found "+ geomSource2.getSchema().getTypeName() ); return validateMultipleLayers(geomSource1, geomSource2, isExpected(), results, envelope); } } /** * validateMultipleLayers Purpose:
*

* This validation tests for a geometry crosses another geometry. * Uses JTS' Geometry.crosses(Geometry) method. * The DE-9IM intersection matrix for crosses is * T*T****** (for a point and a curve, a point and an area or a line and an area) * 0******** (for two curves) *

* * Description:
*

* The function filters the FeatureSources using the given bounding box. * It creates iterators over both filtered FeatureSources. It calls overlaps() and contains()using the * geometries in the FeatureSource layers. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. This geometry is the one that is tested for overlaping with the other * @param featureSourceB - the FeatureSource to pull the other geometries from - these geometries will be those that may overlap the first geometry * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the overlaps() and contains() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateMultipleLayers( FeatureSource featureSourceA, FeatureSource featureSourceB, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResultsA = featureSourceA.getFeatures(filter); FeatureResults featureResultsB = featureSourceB.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResultsA.reader(); if (fr1 == null) return success; ===================================================================== Found a 41 line (262 tokens) duplication in the following files: Starting at line 330 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/TextStyleTest.java Starting at line 291 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/DefaultMarkTest.java Raster data = image.getData(); Raster data2 = image2.getData(); int[] pixel1 = null; int[] pixel2 = null; boolean isBlack = false; for (int x = 0; x < data.getWidth(); x++) { for (int y = 0; y < data.getHeight(); y++) { pixel1 = data.getPixel(x, y, pixel1); pixel2 = data2.getPixel(x, y, pixel2); if ((notBlack(pixel1)) && (notBlack(pixel2))) { //Since text is black and fonts are not stable across platforms, ignore pixels where at least one is black. for (int band = 0; band < data2.getNumBands(); band++) { assertEquals("mismatch in image comparison at (x: " + x + " y: " + y + " band: " + band + ")", pixel1[band], pixel2[band]); } } } } } private boolean notBlack(int[] pixel) { boolean isBlack = true; int x = 0; while (isBlack && (x < pixel.length)) { isBlack = (pixel[x] == 0); x++; } return !(isBlack); } private Point makeSamplePoint(final com.vividsolutions.jts.geom.GeometryFactory geomFac, double x, double y) { com.vividsolutions.jts.geom.Coordinate c = new com.vividsolutions.jts.geom.Coordinate(x, y); Point point = geomFac.createPoint(c); return point; } ===================================================================== Found a 59 line (257 tokens) duplication in the following files: Starting at line 57 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointCoveredByPolygonBoundaryValidation.java Starting at line 57 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointCoveredByPolygonValidation.java public PointCoveredByPolygonValidation() { super(); } /** * Ensure Point is covered by the Polygon. * *

* * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * * @return True if no features intersect. If they do then the validation * failed. * * @throws Exception DOCUMENT ME! * * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, * org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { FeatureSource pointSource = (FeatureSource) layers.get(getPointTypeRef()); FeatureSource polySource = (FeatureSource) layers.get(getRestrictedPolygonTypeRef()); Object[] polys = polySource.getFeatures().collection().toArray(); Object[] points = pointSource.getFeatures().collection().toArray(); if (!envelope.contains(polySource.getBounds())) { results.error((Feature) polys[0], "Point Feature Source is not contained within the Envelope provided."); return false; } if (!envelope.contains(pointSource.getBounds())) { results.error((Feature) points[0], "Line Feature Source is not contained within the Envelope provided."); return false; } for (int i = 0; i < points.length; i++) { Feature tmp = (Feature) points[i]; Geometry gt = tmp.getDefaultGeometry(); if (gt instanceof Polygon) { Polygon ls = (Polygon) gt; boolean r = false; for (int j = 0; j < polys.length && !r; j++) { Feature tmp2 = (Feature) polys[j]; Geometry gt2 = tmp2.getDefaultGeometry(); if (gt2 instanceof Point) { Point pt = (Point) gt2; if(!ls.contains(pt)){ ===================================================================== Found a 59 line (255 tokens) duplication in the following files: Starting at line 56 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointInsidePolygonValidation.java Starting at line 57 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointCoveredByPolygonBoundaryValidation.java public PointCoveredByPolygonBoundaryValidation() { super(); } /** * Ensure Point is covered by the Polygon Boundary. * *

* * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * * @return True if no features intersect. If they do then the validation * failed. * * @throws Exception DOCUMENT ME! * * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, * org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { FeatureSource pointSource = (FeatureSource) layers.get(getPointTypeRef()); FeatureSource polySource = (FeatureSource) layers.get(getRestrictedPolygonTypeRef()); Object[] polys = polySource.getFeatures().collection().toArray(); Object[] points = pointSource.getFeatures().collection().toArray(); if (!envelope.contains(polySource.getBounds())) { results.error((Feature) polys[0], "Point Feature Source is not contained within the Envelope provided."); return false; } if (!envelope.contains(pointSource.getBounds())) { results.error((Feature) points[0], "Line Feature Source is not contained within the Envelope provided."); return false; } for (int i = 0; i < points.length; i++) { Feature tmp = (Feature) points[i]; Geometry gt = tmp.getDefaultGeometry(); if (gt instanceof Polygon) { Polygon ls = (Polygon) gt; boolean r = false; for (int j = 0; j < polys.length && !r; j++) { Feature tmp2 = (Feature) polys[j]; Geometry gt2 = tmp2.getDefaultGeometry(); if (gt2 instanceof Point) { Point pt = (Point) gt2; if(!ls.getBoundary().contains(pt)){ ===================================================================== Found a 34 line (244 tokens) duplication in the following files: Starting at line 185 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 122 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java private static final Canvas obs = new Canvas(); static { //static block to populate the lookups joinLookup.put("miter", new Integer(BasicStroke.JOIN_MITER)); joinLookup.put("bevel", new Integer(BasicStroke.JOIN_BEVEL)); joinLookup.put("round", new Integer(BasicStroke.JOIN_ROUND)); capLookup.put("butt", new Integer(BasicStroke.CAP_BUTT)); capLookup.put("round", new Integer(BasicStroke.CAP_ROUND)); capLookup.put("square", new Integer(BasicStroke.CAP_SQUARE)); fontStyleLookup.put("normal", new Integer(java.awt.Font.PLAIN)); fontStyleLookup.put("italic", new Integer(java.awt.Font.ITALIC)); fontStyleLookup.put("oblique", new Integer(java.awt.Font.ITALIC)); fontStyleLookup.put("bold", new Integer(java.awt.Font.BOLD)); /** * A list of wellknownshapes that we know about: square, circle, triangle, star, cross, x. * Note arrow is an implementation specific mark. */ wellKnownMarks.add("Square"); wellKnownMarks.add("Triangle"); wellKnownMarks.add("Cross"); wellKnownMarks.add("Circle"); wellKnownMarks.add("Star"); wellKnownMarks.add("X"); wellKnownMarks.add("Arrow"); wellKnownMarks.add("square"); wellKnownMarks.add("triangle"); wellKnownMarks.add("cross"); wellKnownMarks.add("circle"); wellKnownMarks.add("star"); wellKnownMarks.add("x"); wellKnownMarks.add("arrow"); ===================================================================== Found a 39 line (232 tokens) duplication in the following files: Starting at line 390 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderingGridCoverageTest.java Starting at line 285 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/DefaultMarkTest.java "DefaultMarkTest_" + renderer.getClass().getName().replace('.', '_') + ".png"); RenderedImage image2 = (RenderedImage) JAI.create("fileload", file2.toString()); assertNotNull("Failed to load exemplar image", image2); Raster data = image.getData(); Raster data2 = image2.getData(); int[] pixel1 = null; int[] pixel2 = null; boolean isBlack = false; for (int x = 0; x < data.getWidth(); x++) { for (int y = 0; y < data.getHeight(); y++) { pixel1 = data.getPixel(x, y, pixel1); pixel2 = data2.getPixel(x, y, pixel2); if ((notBlack(pixel1)) && (notBlack(pixel2))) { //Since text is black and fonts are not stable across platforms, ignore pixels where at least one is black. for (int band = 0; band < data2.getNumBands(); band++) { assertEquals("mismatch in image comparison at (x: " + x + " y: " + y + " band: " + band + ")", pixel1[band], pixel2[band]); } } } } } private boolean notBlack(int[] pixel) { boolean isBlack = true; int x = 0; while (isBlack && (x < pixel.length)) { isBlack = (pixel[x] == 0); x++; } return !(isBlack); } ===================================================================== Found a 38 line (231 tokens) duplication in the following files: Starting at line 70 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/DOMParserTest.java Starting at line 81 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/ParserTest.java } public void setUp() throws SchemaException, IllegalAttributeException { super.setUp(); FeatureTypeFactory feaTypeFactory = FeatureTypeFactory.createTemplate(testSchema); AttributeType doubleAttribute2 = attFactory.newAttributeType("testZeroDouble", Double.class); feaTypeFactory.addType(doubleAttribute2); testSchema = feaTypeFactory.getFeatureType(); GeometryFactory geomFac = new GeometryFactory(); // Creates coordinates for the linestring Coordinate[] coords = new Coordinate[3]; coords[0] = new Coordinate(1, 2); coords[1] = new Coordinate(3, 4); coords[2] = new Coordinate(5, 6); // Builds the test feature Object[] attributes = new Object[11]; attributes[0] = geomFac.createLineString(coords); attributes[1] = new Boolean(true); attributes[2] = new Character('t'); attributes[3] = new Byte("10"); attributes[4] = new Short("101"); attributes[5] = new Integer(1002); attributes[6] = new Long(10003); attributes[7] = new Float(10000.4); attributes[8] = new Double(100000.5); attributes[9] = "test string data"; attributes[10] = new Double(0.0); // Creates the feature itself testFeature = testSchema.create(attributes); } public void test1() throws Exception { ===================================================================== Found a 54 line (228 tokens) duplication in the following files: Starting at line 55 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PolygonNotCoveredByPolygonValidation.java Starting at line 55 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PolygonCoveredByPolygonValidation.java public PolygonCoveredByPolygonValidation() { super(); } /** * Ensure Polygon is covered by the Polygon. * *

* * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * * @return True if no features intersect. If they do then the validation * failed. * * @throws Exception DOCUMENT ME! * * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, * org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { FeatureSource polySource1 = (FeatureSource) layers.get(getPolygonTypeRef()); FeatureSource polySource2 = (FeatureSource) layers.get(getRestrictedPolygonTypeRef()); Object[] poly1 = polySource1.getFeatures().collection().toArray(); Object[] poly2 = polySource2.getFeatures().collection().toArray(); if (!envelope.contains(polySource1.getBounds())) { results.error((Feature) poly1[0], "Polygon Feature Source is not contained within the Envelope provided."); return false; } if (!envelope.contains(polySource2.getBounds())) { results.error((Feature) poly1[0], "Restricted Polygon Feature Source is not contained within the Envelope provided."); return false; } for (int i = 0; i < poly2.length; i++) { Feature tmp = (Feature) poly2[i]; Geometry gt = tmp.getDefaultGeometry(); for (int j = 0; j < poly1.length; j++) { Feature tmp2 = (Feature) poly1[j]; Geometry gt2 = tmp2.getDefaultGeometry(); if (gt2.within(gt)) { return true; ===================================================================== Found a 85 line (227 tokens) duplication in the following files: Starting at line 154 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/DisjointIntegrity.java Starting at line 156 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/ContainsIntegrity.java Starting at line 163 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/WithinIntegrity.java Starting at line 193 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/RelateIntegrity.java Starting at line 165 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/TouchesIntegrity.java Starting at line 156 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/IntersectsIntegrity.java results.error( f1, f1.getDefaultGeometry().getGeometryType()+" "+getGeomTypeRefA()+" intersects "+getGeomTypeRefB()+"("+f2.getID()+"), Result was not "+expected ); success = false; } } } }finally { /** Close the connections too the feature readers*/ try { fr1.close(); if (fr2 != null) fr2.close(); } catch (IOException e4) { e4.printStackTrace(); throw e4; } } return success; } /** * validateSingleLayer Purpose:
*

* This validation tests for a geometry that intersects with itself. * Uses JTS' Geometry.intersects(Geometry) method. *

* * Description:
*

* The function filters the FeatureSource using the given bounding box. * It creates iterators over the filtered FeatureSource. It calls intersects() using the * geometries in the FeatureSource layer. Tests the results of the method call against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the intersects() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateSingleLayer(FeatureSource featureSourceA, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; FilterFactory ff = FilterFactory.createFilterFactory(); Filter filter = null; filter = (Filter) ff.createBBoxExpression(bBox); FeatureResults featureResults = featureSourceA.getFeatures(filter); FeatureReader fr1 = null; FeatureReader fr2 = null; try { fr1 = featureResults.reader(); if (fr1 == null) return false; while (fr1.hasNext()) { Feature f1 = fr1.next(); Geometry g1 = f1.getDefaultGeometry(); fr2 = featureResults.reader(); while (fr2 != null && fr2.hasNext()) { Feature f2 = fr2.next(); Geometry g2 = f2.getDefaultGeometry(); if (!f1.getID().equals(f2.getID())) // if they are the same feature, move onto the next one { if(g1.intersects(g2) != expected ) ===================================================================== Found a 56 line (218 tokens) duplication in the following files: Starting at line 179 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/mysql/src/org/geotools/data/mysql/MySQLDataStore.java Starting at line 506 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataStore.java if (Character.isLetter(ch) || (ch == '_')) { sql.append("'"); sql.append(fid); sql.append("'"); } else if (Character.isDigit(ch)) { try { long number = Long.parseLong(fid); sql.append(number); } catch (NumberFormatException badNumber) { sql.append(fid); } } else { sql.append(fid); } sql.append(", "); } for (int j = 0; j < attributes.length; j++) { if (types[j].isGeometry()) { String geomName = types[j].getName(); int srid = ftInfo.getSRID(geomName); String geoText = getGeometryText((Geometry) attributes[j], srid); sql.append(geoText); //String geoText = geometryWriter.write((Geometry) attributes[j]); //sql.append("GeometryFromText('" + geoText + "', " + srid + ")"); } else { attrValue = addQuotes(attributes[j]); sql.append(attrValue); } if (j < (attributes.length - 1)) { sql.append(", "); } } sql.append(");"); return sql.toString(); } /** * Adds quotes to an object for storage in postgis. The object should be a * string or a number. To perform an insert strings need quotes around * them, and numbers work fine with quotes, so this method can be called * on unknown objects. * * @param value The object to add quotes to. * * @return a string representation of the object with quotes. */ private String addQuotes(Object value) { String retString; if (value != null) { ===================================================================== Found a 48 line (213 tokens) duplication in the following files: Starting at line 62 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineIntersectsLineWithNodeValidation.java Starting at line 60 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineEndPointCoveredByLineValidation.java public LineEndPointCoveredByLineValidation() { super(); } /** * Ensure Line End Point is covered by the Line. * *

* * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * * @return True if no features intersect. If they do then the validation * failed. * * @throws Exception DOCUMENT ME! * * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, * org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { boolean r = true; FeatureSource fsLine = (FeatureSource) layers.get(getLineTypeRef()); FeatureResults frLine = fsLine.getFeatures(); FeatureCollection fcLine = frLine.collection(); FeatureIterator fLine = fcLine.features(); FeatureSource fsRLine = (FeatureSource) layers.get(getRestrictedLineTypeRef()); FeatureResults frRLine = fsRLine.getFeatures(); FeatureCollection fcRLine = frRLine.collection(); while(fLine.hasNext()){ Feature line = fLine.next(); FeatureIterator fRLine = fcRLine.features(); Geometry lineGeom = line.getDefaultGeometry(); if(envelope.contains(lineGeom.getEnvelopeInternal())){ // check for valid comparison if(LineString.class.isAssignableFrom(lineGeom.getClass())){ while(fRLine.hasNext()){ Feature rLine = fRLine.next(); Geometry rLineGeom = rLine.getDefaultGeometry(); if(envelope.contains(rLineGeom.getEnvelopeInternal())){ if(LineString.class.isAssignableFrom(rLineGeom.getClass())){ ===================================================================== Found a 100 line (211 tokens) duplication in the following files: Starting at line 49 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/resources/gcs/Resources.java Starting at line 49 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/rsc/Resources.java public class Resources extends ResourceBundle { /** * Construct a resource bundle using english language. * This is the default when no resource are available * in user language. */ public Resources() { super(// Set 'true' in front of language to use as default. false ? Resources_fr.FILEPATH : true ? Resources_en.FILEPATH : null); } /** * Construct a resource bundle * using the specified UTF8 file. */ Resources(final String filepath) { super(filepath); } /** * Returns resources in the given locale. * * @param local The locale, or null for the default locale. * @return Resources in the given locale. * @throws MissingResourceException if resources can't be found. */ public static Resources getResources(Locale locale) throws MissingResourceException { if (locale==null) { locale = Locale.getDefault(); } return (Resources) getBundle(Resources.class.getName(), locale); /* * We rely on cache capability of {@link java.util.ResourceBundle}. */ } /** * Gets a string for the given key from this resource bundle or one of its * parents. * * @param key The key for the desired string. * @return The string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key) throws MissingResourceException { return getResources(null).getString(key); } /** * Gets a string for the given key are replace all occurence of "{0}" * with values of arg0. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0) throws MissingResourceException { return getResources(null).getString(key, arg0); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0, final Object arg1) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1, etc. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @param arg2 Value to substitute to "{2}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0, final Object arg1, final Object arg2) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1, arg2); } ===================================================================== Found a 29 line (209 tokens) duplication in the following files: Starting at line 96 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/ShapefileDataStore.java Starting at line 77 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/ShapefileDataSource.java public ShapefileDataSource(URL url) throws java.net.MalformedURLException { String filename = null; if (url == null) { throw new NullPointerException("Null URL for ShapefileDataSource"); } try { filename = java.net.URLDecoder.decode(url.toString(),"US-ASCII"); } catch (java.io.UnsupportedEncodingException use) { throw new java.net.MalformedURLException( "Unable to decode " + url + " cause " + use.getMessage() ); } String shpext = ".shp"; String dbfext = ".dbf"; String shxext = ".shx"; if(filename.endsWith(shpext) || filename.endsWith(dbfext) || filename.endsWith(shxext)) { filename = filename.substring(0, filename.length() - 4); } else if(filename.endsWith(".SHP") || filename.endsWith(".DBF") || filename.endsWith(".SHX")) { filename = filename.substring(0, filename.length() - 4); shpext = ".SHP"; dbfext = ".DBF"; shxext = ".SHX"; } shpURL = new URL(filename + shpext); dbfURL = new URL(filename + dbfext); shxURL = new URL(filename + shxext); ===================================================================== Found a 43 line (207 tokens) duplication in the following files: Starting at line 62 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineCoveredByPolygonBoundaryValidation.java Starting at line 81 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineCoveredByPolygonValidation.java } /** * Check that lineTypeRef is convered by polygonTypeRef. * *

* Detailed description... *

* * @param layers Map of FeatureSource by "dataStoreID:typeName" * @param envelope The bounding box that encloses the unvalidated data * @param results Used to coallate results information * * @return true if all the features pass this test. * * @throws Exception DOCUMENT ME! */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { boolean r = true; FeatureSource fsLine = (FeatureSource) layers.get(getLineTypeRef()); FeatureResults frLine = fsLine.getFeatures(); FeatureCollection fcLine = frLine.collection(); FeatureIterator fLine = fcLine.features(); FeatureSource fsPoly = (FeatureSource) layers.get(getRestrictedPolygonTypeRef()); FeatureResults frPoly = fsPoly.getFeatures(); FeatureCollection fcPoly = frPoly.collection(); while(fLine.hasNext()){ Feature line = fLine.next(); FeatureIterator fPoly = fcPoly.features(); Geometry lineGeom = line.getDefaultGeometry(); if(envelope.contains(lineGeom.getEnvelopeInternal())){ // check for valid comparison if(LineString.class.isAssignableFrom(lineGeom.getClass())){ while(fPoly.hasNext()){ Feature poly = fPoly.next(); Geometry polyGeom = poly.getDefaultGeometry(); if(envelope.contains(polyGeom.getEnvelopeInternal())){ if(Polygon.class.isAssignableFrom(polyGeom.getClass())){ ===================================================================== Found a 42 line (207 tokens) duplication in the following files: Starting at line 492 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataSource.java Starting at line 661 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java throws IOException { //one to one relationship for now, so typeName is not used. //String tableName = query.getTypeName(); tableName = this.tableName; boolean useLimit = (unpacker.getUnSupported() == null); Filter filter = unpacker.getSupported(); LOGGER.fine("Filter in making sql is " + filter); StringBuffer sqlStatement = new StringBuffer("SELECT "); sqlStatement.append(fidColumn); AttributeType[] attributeTypes = getAttTypes(query); int numAttributes = attributeTypes.length; LOGGER.finer("making sql for " + numAttributes + " attributes"); for (int i = 0; i < numAttributes; i++) { String curAttName = attributeTypes[i].getName(); if (Geometry.class.isAssignableFrom(attributeTypes[i].getType())) { sqlStatement.append(", AsText(force_2d(\"" + curAttName + "\"))"); //REVISIT, see getIdColumn note. } else if (fidColumn.equals(curAttName)) { //do nothing, already covered by fid } else { sqlStatement.append(", \"" + curAttName + "\""); } } String where = ""; if (filter != null) { try { where = encoder.encode(filter); } catch (SQLEncoderException sqle) { String message = "Encoder error" + sqle.getMessage(); LOGGER.warning(message); throw new DataSourceException(message, sqle); } } ===================================================================== Found a 44 line (205 tokens) duplication in the following files: Starting at line 147 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ParseException.java Starting at line 40 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/TokenMgrError.java protected static final String addEscapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } ===================================================================== Found a 98 line (202 tokens) duplication in the following files: Starting at line 49 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gui/src/org/geotools/resources/gui/Resources.java Starting at line 49 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/resources/renderer/Resources.java public class Resources extends ResourceBundle { /** * Construct a resource bundle using english language. * This is the default when no resource are available * in user language. */ public Resources() { super(Resources_en.FILEPATH); } /** * Construct a resource bundle * using the specified UTF8 file. */ Resources(final String filepath) { super(filepath); } /** * Returns resources in the given locale. * * @param local The locale, or null for the default locale. * @return Resources in the given locale. * @throws MissingResourceException if resources can't be found. */ public static Resources getResources(Locale locale) throws MissingResourceException { if (locale==null) { locale = Locale.getDefault(); } return (Resources) getBundle(Resources.class.getName(), locale); /* * We rely on cache capability of {@link java.util.ResourceBundle}. */ } /** * Gets a string for the given key from this resource bundle or one of its * parents. * * @param key The key for the desired string. * @return The string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key) throws MissingResourceException { return getResources(null).getString(key); } /** * Gets a string for the given key are replace all occurence of "{0}" * with values of arg0. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0) throws MissingResourceException { return getResources(null).getString(key, arg0); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0, final Object arg1) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1, etc. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @param arg2 Value to substitute to "{2}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0, final Object arg1, final Object arg2) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1, arg2); } } ===================================================================== Found a 33 line (201 tokens) duplication in the following files: Starting at line 396 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderingGridCoverageTest.java Starting at line 330 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/TextStyleTest.java Raster data = image1.getData(); Raster data2 = image2.getData(); int[] pixel1 = null; int[] pixel2 = null; boolean isBlack = false; for (int x = 0; x < data.getWidth(); x++) { for (int y = 0; y < data.getHeight(); y++) { pixel1 = data.getPixel(x, y, pixel1); pixel2 = data2.getPixel(x, y, pixel2); if ((notBlack(pixel1)) && (notBlack(pixel2))) { //Since text is black and fonts are not stable across platforms, ignore pixels where at least one is black. for (int band = 0; band < data2.getNumBands(); band++) { assertEquals("mismatch in image comparison at (x: " + x + " y: " + y + " band: " + band + ")", pixel1[band], pixel2[band]); } } } } } private boolean notBlack(int[] pixel) { boolean isBlack = true; int x = 0; while (isBlack && (x < pixel.length)) { isBlack = (pixel[x] == 0); x++; } return !(isBlack); } ===================================================================== Found a 50 line (198 tokens) duplication in the following files: Starting at line 56 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointCoveredByLineValidation.java Starting at line 57 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PointCoveredByEndPointOfLineValidation.java public PointCoveredByEndPointOfLineValidation() { super(); } /** * Ensure Point is covered by a Line end point. * *

* * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * * @return True if no features intersect. If they do then the validation * failed. * * @throws Exception DOCUMENT ME! * * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, * org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { FeatureSource lineSource = (FeatureSource) layers.get(getRestrictedLineTypeRef()); FeatureSource pointSource = (FeatureSource) layers.get(getPointTypeRef()); Object[] points = pointSource.getFeatures().collection().toArray(); Object[] lines = lineSource.getFeatures().collection().toArray(); if (!envelope.contains(pointSource.getBounds())) { results.error((Feature) points[0], "Point Feature Source is not contained within the Envelope provided."); return false; } if (!envelope.contains(lineSource.getBounds())) { results.error((Feature) lines[0], "Line Feature Source is not contained within the Envelope provided."); return false; } for (int i = 0; i < lines.length; i++) { Feature tmp = (Feature) lines[i]; Geometry gt = tmp.getDefaultGeometry(); if (gt instanceof LineString) { LineString ls = (LineString) gt; ===================================================================== Found a 28 line (197 tokens) duplication in the following files: Starting at line 200 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/DOMParserTest.java Starting at line 234 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/DOMParserTest.java public Filter parseDocumentFirst(String uri) throws Exception { Filter filter = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(uri); LOGGER.fine("parsing " + uri); // first grab a filter node NodeList nodes = dom.getElementsByTagName("Filter"); for (int j = 0; j < nodes.getLength(); j++) { Element filterNode = (Element) nodes.item(j); NodeList list = filterNode.getChildNodes(); Node child = null; for (int i = 0; i < list.getLength(); i++) { child = list.item(i); if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) { continue; } filter = FilterDOMParser.parseFilter(child); assertNotNull("Null filter returned", filter); LOGGER.finer("filter: " + filter.getClass().toString()); LOGGER.fine("parsed: " + filter.toString()); LOGGER.finer("result " + filter.contains(testFeature)); ===================================================================== Found a 40 line (192 tokens) duplication in the following files: Starting at line 446 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java Starting at line 667 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java } catch (WMSException wmsexp) { doException(wmsexp.getCode(), wmsexp.getMessage(), request, response, exceptions); return; } catch (Exception exp) { doException(null, "Unknown exception : " + exp + " : " + exp.getStackTrace()[0] + exp.getMessage(), request, response, exceptions); return; } // Write the response response.setContentType(format); OutputStream out = response.getOutputStream(); // avoid caching in browser response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); try { formatImageOutputStream(format, image, out); } catch (Exception exp) { exp.printStackTrace(); LOGGER.severe( "Unable to complete image generation after response started : " + exp + exp.getMessage()); if (exp instanceof SecurityException) { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + " JAI may not have 'write' and 'delete' permissions in temp folder"); } else { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + "Check JAI configuration"); } }//finally{ ===================================================================== Found a 44 line (188 tokens) duplication in the following files: Starting at line 644 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/NumberParser.java Starting at line 702 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/NumberParser.java low = (b < m ); high = (b+m > tens ); if ( q >= 10 ){ // bummer, dude throw new RuntimeException( "Assertion botch: excessivly large digit "+q); } else if ( (q == 0) && ! high ){ // oops. Usually ignore leading zero. decExp--; } else { digits[ndigit++] = (char)('0' + q); } /* * HACK! Java spec sez that we always have at least * one digit after the . in either F- or E-form output. * Thus we will need more than one digit if we're using * E-form */ if ( decExp <= -3 || decExp >= 8 ){ high = low = false; } while( ! low && ! high ){ q = (int) ( b / s ); b = 10 * ( b % s ); m *= 10; if ( q >= 10 ){ // bummer, dude throw new RuntimeException( "Assertion botch: excessivly large digit "+q); } if ( m > 0L ){ low = (b < m ); high = (b+m > tens ); } else { // hack -- m might overflow! // in this case, it is certainly > b, // which won't // and b+m > tens, too, since that has overflowed // either! low = true; high = true; } digits[ndigit++] = (char)('0' + q); } lowDigitDifference = (b<<1) - tens; } ===================================================================== Found a 32 line (186 tokens) duplication in the following files: Starting at line 328 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataStoreTest.java Starting at line 217 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataSourceTest.java FeatureCollection fc = s.getFeatures(); FeatureIterator fci = fc.features(); // verify while (fci.hasNext()) { Feature f = fci.next(); Geometry fromShape = f.getDefaultGeometry(); if (fromShape instanceof GeometryCollection) { if ( ! (geom instanceof GeometryCollection) ) { fromShape = ((GeometryCollection)fromShape).getGeometryN(0); } } try { Coordinate[] c1 = geom.getCoordinates(); Coordinate[] c2 = fromShape.getCoordinates(); for (int cc = 0, ccc = c1.length; cc < ccc; cc++) { //System.out.println(c1[cc] + "," + c2[cc]); if (d3) assertTrue(c1[cc].equals3D(c2[cc])); else assertTrue(c1[cc].equals2D(c2[cc])); } } catch (Throwable t) { fail("Bogus : " + Arrays.asList(geom.getCoordinates()) + " : " + Arrays.asList(fromShape.getCoordinates())); } } tmpFile.delete(); } ===================================================================== Found a 91 line (186 tokens) duplication in the following files: Starting at line 56 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gui/src/org/geotools/resources/gui/Resources.java Starting at line 59 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/rsc/Resources.java null); } /** * Construct a resource bundle * using the specified UTF8 file. */ Resources(final String filepath) { super(filepath); } /** * Returns resources in the given locale. * * @param local The locale, or null for the default locale. * @return Resources in the given locale. * @throws MissingResourceException if resources can't be found. */ public static Resources getResources(Locale locale) throws MissingResourceException { if (locale==null) { locale = Locale.getDefault(); } return (Resources) getBundle(Resources.class.getName(), locale); /* * We rely on cache capability of {@link java.util.ResourceBundle}. */ } /** * Gets a string for the given key from this resource bundle or one of its * parents. * * @param key The key for the desired string. * @return The string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key) throws MissingResourceException { return getResources(null).getString(key); } /** * Gets a string for the given key are replace all occurence of "{0}" * with values of arg0. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0) throws MissingResourceException { return getResources(null).getString(key, arg0); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be * found. */ public static String format(final int key, final Object arg0, final Object arg1) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1, etc. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @param arg2 Value to substitute to "{2}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0, final Object arg1, final Object arg2) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1, arg2); } } ===================================================================== Found a 14 line (186 tokens) duplication in the following files: Starting at line 96 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/tests/unit/org/geotools/renderer/lite/LiteShapeTest.java Starting at line 549 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderStyleTest.java private Polygon makeSamplePolygon(final GeometryFactory geomFac, double xoff, double yoff) { Coordinate[] polygonCoordinates = new Coordinate[10]; polygonCoordinates[0] = new Coordinate(70 + xoff, 70 + yoff); polygonCoordinates[1] = new Coordinate(60 + xoff, 90 + yoff); polygonCoordinates[2] = new Coordinate(60 + xoff, 110 + yoff); polygonCoordinates[3] = new Coordinate(70 + xoff, 120 + yoff); polygonCoordinates[4] = new Coordinate(90 + xoff, 110 + yoff); polygonCoordinates[5] = new Coordinate(110 + xoff, 120 + yoff); polygonCoordinates[6] = new Coordinate(130 + xoff, 110 + yoff); polygonCoordinates[7] = new Coordinate(130 + xoff, 90 + yoff); polygonCoordinates[8] = new Coordinate(110 + xoff, 70 + yoff); polygonCoordinates[9] = new Coordinate(70 + xoff, 70 + yoff); try { ===================================================================== Found a 92 line (185 tokens) duplication in the following files: Starting at line 56 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gui/src/org/geotools/resources/gui/Resources.java Starting at line 59 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/resources/gcs/Resources.java null); } /** * Construct a resource bundle * using the specified UTF8 file. */ Resources(final String filepath) { super(filepath); } /** * Returns resources in the given locale. * * @param local The locale, or null for the default locale. * @return Resources in the given locale. * @throws MissingResourceException if resources can't be found. */ public static Resources getResources(Locale locale) throws MissingResourceException { if (locale==null) { locale = Locale.getDefault(); } return (Resources) getBundle(Resources.class.getName(), locale); /* * We rely on cache capability of {@link java.util.ResourceBundle}. */ } /** * Gets a string for the given key from this resource bundle or one of its parents. * * @param key The key for the desired string. * @return The string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key) throws MissingResourceException { return getResources(null).getString(key); } /** * Gets a string for the given key are replace all occurence of "{0}" * with values of arg0. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0) throws MissingResourceException { return getResources(null).getString(key, arg0); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0, final Object arg1) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1); } /** * Gets a string for the given key are replace all occurence of "{0}", * "{1}", with values of arg0, arg1, etc. * * @param key The key for the desired string. * @param arg0 Value to substitute to "{0}". * @param arg1 Value to substitute to "{1}". * @param arg2 Value to substitute to "{2}". * @return The formatted string for the given key. * @throws MissingResourceException If no object for the given key can be found. */ public static String format(final int key, final Object arg0, final Object arg1, final Object arg2) throws MissingResourceException { return getResources(null).getString(key, arg0, arg1, arg2); } ===================================================================== Found a 39 line (177 tokens) duplication in the following files: Starting at line 79 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gmldatasource/src/org/geotools/gml/TestParser.java Starting at line 46 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/LakesValidationTest.java LakesTestHandler contentHandler = new LakesTestHandler(); GMLFilterGeometry geometryFilter = new GMLFilterGeometry(contentHandler); GMLFilterDocument documentFilter = new GMLFilterDocument(geometryFilter); XMLReader parser = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser"); parser.setContentHandler(documentFilter); parser.parse(uri); } catch (IOException e) { System.out.println("Error reading uri: " + uri); } catch (SAXException e) { System.out.println("Error in parsing: " + e.getMessage()); } } public static void parseFeatures(String uri) { System.out.println("Parsing the flat feature collection in this GML " + "resource:" + uri); try { GMLDataSource data = new GMLDataSource(uri); FeatureCollection featureCollection = data.getFeatures(Query.ALL); Iterator i = featureCollection.iterator(); while (i.hasNext()) { System.out.println("Parsed feature is ... " + i.next()); } } catch (DataSourceException e) { System.out.println( "TestParser->parseFeatures DataSourceException: " + e.toString()); } //parsedFeatures. // chains all the appropriate filters together (in correct order) // and initiates parsing } } ===================================================================== Found a 20 line (168 tokens) duplication in the following files: Starting at line 78 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/tests/unit/org/geotools/renderer/lite/LiteShapeTest.java Starting at line 530 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderStyleTest.java return !(isBlack); } private LineString makeSampleLineString(final GeometryFactory geomFac, double xoff, double yoff) { Coordinate[] linestringCoordinates = new Coordinate[8]; linestringCoordinates[0] = new Coordinate(50.0d + xoff, 50.0d + yoff); linestringCoordinates[1] = new Coordinate(60.0d + xoff, 50.0d + yoff); linestringCoordinates[2] = new Coordinate(60.0d + xoff, 60.0d + yoff); linestringCoordinates[3] = new Coordinate(70.0d + xoff, 60.0d + yoff); linestringCoordinates[4] = new Coordinate(70.0d + xoff, 70.0d + yoff); linestringCoordinates[5] = new Coordinate(80.0d + xoff, 70.0d + yoff); linestringCoordinates[6] = new Coordinate(80.0d + xoff, 80.0d + yoff); linestringCoordinates[7] = new Coordinate(130.0d + xoff, 300.0d + yoff); LineString line = geomFac.createLineString(linestringCoordinates); return line; } private Polygon makeSamplePolygon(final GeometryFactory geomFac, double xoff, double yoff) { ===================================================================== Found a 24 line (165 tokens) duplication in the following files: Starting at line 1544 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 1612 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java float radius = ((Number) halo.getRadius().getValue(feature)).floatValue(); Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y); Point2D graphicCentre = new java.awt.geom.Point2D.Double(); temp.transform(mapCentre, graphicCentre); labelAT.translate(graphicCentre.getX(), graphicCentre.getY()); if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("rotation " + rotation); } double shearY = temp.getShearY(); double scaleY = temp.getScaleY(); double scaleX = temp.getScaleX(); double originalRotation = Math.atan(shearY / scaleY); if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("originalRotation " + originalRotation); } labelAT.rotate(rotation - originalRotation); double xToyRatio = Math.abs(scaleX / scaleY); labelAT.scale(xToyRatio, 1.0 / xToyRatio); ===================================================================== Found a 22 line (165 tokens) duplication in the following files: Starting at line 1378 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 1409 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java String reqStyle = (String) fonts[k].getFontStyle().getValue(feature); if (fontStyleLookup.containsKey(reqStyle)) { styleCode = ((Integer) fontStyleLookup.get(reqStyle)) .intValue(); } else { styleCode = java.awt.Font.PLAIN; } String reqWeight = (String) fonts[k].getFontWeight().getValue(feature); if (reqWeight.equalsIgnoreCase("Bold")) { styleCode = styleCode | java.awt.Font.BOLD; } if ((fonts[k].getFontSize() == null) || (fonts[k].getFontSize().getValue(feature) == null)) { size = 10; } else { size = ((Number) fonts[k].getFontSize().getValue(feature)) .intValue(); } ===================================================================== Found a 41 line (163 tokens) duplication in the following files: Starting at line 254 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataStoreTest.java Starting at line 155 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataSourceTest.java tmpFile.delete(); } public void testGeometriesWriting() throws Exception { String[] wktResources = new String[] { "point", "multipoint", "line", "multiline", "polygon", "multipolygon" }; PrecisionModel pm = new PrecisionModel(); for (int i = 0; i < wktResources.length; i++) { Geometry geom = readGeometry(wktResources[i]); String testName = wktResources[i]; try { runWriteReadTest(geom,false); make3D(geom); testName += "3d"; runWriteReadTest(geom,true); } catch (Throwable e) { throw new Exception("Error in " + testName,e); } } } private void make3D(Geometry g) { Coordinate[] c = g.getCoordinates(); for (int i = 0, ii = c.length; i < ii; i++) { c[i].z = 42 + i; } } private void runWriteReadTest(Geometry geom,boolean d3) throws Exception { ===================================================================== Found a 24 line (160 tokens) duplication in the following files: Starting at line 103 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/tests/unit/org/geotools/renderer/lite/Rendering2DTest.java Starting at line 97 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/tests/unit/org/geotools/renderer/LegendImageGeneratorTest.java StyleFactory sFac = StyleFactory.createStyleFactory(); //The following is complex, and should be built from //an SLD document and not by hand PointSymbolizer pointsym = sFac.createPointSymbolizer(); pointsym.setGraphic(sFac.getDefaultGraphic()); LineSymbolizer linesym = sFac.createLineSymbolizer(); Stroke myStroke = sFac.getDefaultStroke(); myStroke.setColor(filterFactory.createLiteralExpression("#0000ff")); myStroke.setWidth(filterFactory.createLiteralExpression(new Integer(5))); LOGGER.info("got new Stroke " + myStroke); linesym.setStroke(myStroke); PolygonSymbolizer polysym = sFac.createPolygonSymbolizer(); Fill myFill = sFac.getDefaultFill(); myFill.setColor(filterFactory.createLiteralExpression("#ff0000")); polysym.setFill(myFill); polysym.setStroke(sFac.getDefaultStroke()); Rule rule = sFac.createRule(); rule.setSymbolizers(new Symbolizer[] { polysym }); FeatureTypeStyle fts = sFac.createFeatureTypeStyle(new Rule[] { rule }); ===================================================================== Found a 45 line (160 tokens) duplication in the following files: Starting at line 113 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/Java2DMark.java Starting at line 94 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/Java2DMark.java } public static Shape getWellKnownMark(String wellKnownName) { LOGGER.finer("fetching mark of name " + wellKnownName); if (wellKnownName.equalsIgnoreCase("cross")) { LOGGER.finer("returning cross"); return cross; } if (wellKnownName.equalsIgnoreCase("circle")) { LOGGER.finer("returning circle"); return new java.awt.geom.Ellipse2D.Double(-.5, -.5, 1., 1.); } if (wellKnownName.equalsIgnoreCase("triangle")) { LOGGER.finer("returning triangle"); return triangle; } if (wellKnownName.equalsIgnoreCase("X")) { LOGGER.finer("returning X"); return X; } if (wellKnownName.equalsIgnoreCase("star")) { LOGGER.finer("returning star"); return star; } if (wellKnownName.equalsIgnoreCase("arrow")) { LOGGER.finer("returning arrow"); return arrow; } // failing that return a square? LOGGER.finer("returning square"); return new Rectangle2D.Double(-.5, -.5, 1., 1.); ===================================================================== Found a 20 line (151 tokens) duplication in the following files: Starting at line 63 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataStoreTest.java Starting at line 61 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/tests/unit/org/geotools/data/shapefile/ShapefileDataSourceTest.java assertEquals("Number of Attributes",253,types.length); } public void testEnvelope() throws Exception { FeatureCollection features = loadFeatures(STATE_POP, null); ShapefileDataSource s = new ShapefileDataSource(getTestResource(STATE_POP)); assertEquals(features.getBounds(), s.getBounds()); } public void testLoadAndVerify() throws Exception { FeatureCollection features = loadFeatures(STATE_POP,null); assertEquals("Number of Features loaded",49,features.size()); FeatureType schema = firstFeature(features).getFeatureType(); assertNotNull(schema.getDefaultGeometry()); assertEquals("Number of Attributes",253,schema.getAttributeTypes().length); assertEquals("Value of statename is wrong",firstFeature(features).getAttribute("STATE_NAME"),"Illinois"); assertEquals("Value of land area is wrong",((Double)firstFeature(features).getAttribute("LAND_KM")).doubleValue(),143986.61,0.001); } ===================================================================== Found a 15 line (150 tokens) duplication in the following files: Starting at line 155 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/proj4j/src/org/geotools/proj4j/Transformer.java Starting at line 193 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/proj4j/src/org/geotools/proj4j/Transformer.java z[io] = z[io] - defn.datum.getParams()[2]; } } else if( defn.datum.datumType == Datum.PJD_7PARAM ) { for(int i = 0; i < point_count; i++ ) { io = i * point_offset; double x_out, y_out, z_out; double Dx_BF = defn.datum.getParams()[0];//not elegent! double Dy_BF = defn.datum.getParams()[1];//and possibly expensive double Dz_BF = defn.datum.getParams()[2];//sigh, no macros in Java double Rx_BF = defn.datum.getParams()[3];//... double Ry_BF = defn.datum.getParams()[4];//still, keeps it readable double Rz_BF = defn.datum.getParams()[5];//if a little verbose double M_BF = defn.datum.getParams()[6];//could do with a better solution though. x_out = M_BF*( x[io] + Rz_BF*y[io] - Ry_BF*z[io]) - Dx_BF; ===================================================================== Found a 23 line (149 tokens) duplication in the following files: Starting at line 69 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/sldstyling/src/org/geotools/styling/SLDTransformer.java Starting at line 292 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/sldstyling/src/org/geotools/styling/XMLEncoder.java out.write("\n"); if (stroke.getGraphicFill() != null) { stroke.getGraphicFill().accept(this); } if (stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); } encodeCssParam("stroke", stroke.getColor()); encodeCssParam("stroke-linecap", stroke.getLineCap()); encodeCssParam("stroke-linejoin", stroke.getLineJoin()); encodeCssParam("stroke-opacity", stroke.getOpacity()); encodeCssParam("stroke-width", stroke.getWidth()); encodeCssParam("stroke-dashoffset", stroke.getDashOffset()); float[] dash = stroke.getDashArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < dash.length; i++) { sb.append(dash[i] + " "); } ===================================================================== Found a 38 line (148 tokens) duplication in the following files: Starting at line 235 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/TextStyleTest.java Starting at line 204 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/DefaultMarkTest.java performTestOnRenderer(new LiteRenderer(context), "builder"); } /** * Test j2d renderer */ public void testJ2DRendererXml() throws Exception { MapContext map = new DefaultMapContext(); map.addLayer(buildFeatureCollection(), loadStyleFromXml()); StyledMapRenderer sr = new StyledMapRenderer(null); sr.setMapContext(map); performTestOnRenderer(sr, "xml"); } /** * Test j2d renderer */ public void testJ2DRendererBuilder() throws Exception { MapContext map = new DefaultMapContext(); map.addLayer(buildFeatureCollection(), loadStyleFromXml()); StyledMapRenderer sr = new StyledMapRenderer(null); sr.setMapContext(map); performTestOnRenderer(sr, "builder"); } /** * Perform test on the passed renderer, which must be already configured with its context */ private void performTestOnRenderer(Renderer2D renderer, String fileSuffix) throws Exception { java.net.URL base = getClass().getResource("rs-testData"); AffineTransform at = new AffineTransform(); at.translate(0, 400); at.scale(9, -9); ===================================================================== Found a 22 line (148 tokens) duplication in the following files: Starting at line 437 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/legend/src/org/geotools/gui/swing/sldeditor/style/full/TreeStyleEditor.java Starting at line 328 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/legend/src/org/geotools/gui/swing/sldeditor/style/full/FullStyleEditor.java return treeEditor.getStyle(); } public static void main(String[] args) throws Exception { AttributeType geom = AttributeTypeFactory.newAttributeType("geom", com.vividsolutions.jts.geom.Polygon.class); AttributeType[] attributeTypes = new AttributeType[] { geom, AttributeTypeFactory.newAttributeType("name", String.class), AttributeTypeFactory.newAttributeType("population", Long.class) }; FeatureType ft = DefaultFeatureTypeFactory.newFeatureType(attributeTypes, "demo", "", false, null, (GeometryAttributeType) geom); FeatureTypeStyle featureStyle = styleBuilder.createFeatureTypeStyle(SymbolizerUtils .getDefaultSymbolizer(ft)); Rule r = featureStyle.getRules()[0]; r.setName("Rule1"); featureStyle.setName("FeatureTypeStyle1"); Style style = styleBuilder.createStyle(); style.addFeatureTypeStyle(featureStyle); FormUtils.show(new FullStyleEditor(ft, style)); ===================================================================== Found a 27 line (143 tokens) duplication in the following files: Starting at line 82 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gui/tests/unit/org/geotools/gui/swing/tables/FeatureTableModelTest.java Starting at line 90 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/filter/SQLEncoderPostgisTest.java LOGGER.finer("created boolean attribute"); AttributeType charAttribute = attFactory.newAttributeType("testCharacter", Character.class); AttributeType byteAttribute = attFactory.newAttributeType("testByte", Byte.class); AttributeType shortAttribute = attFactory.newAttributeType("testShort", Short.class); AttributeType intAttribute = attFactory.newAttributeType("testInteger", Integer.class); AttributeType longAttribute = attFactory.newAttributeType("testLong", Long.class); AttributeType floatAttribute = attFactory.newAttributeType("testFloat", Float.class); AttributeType doubleAttribute = attFactory.newAttributeType("testDouble", Double.class); AttributeType stringAttribute = attFactory.newAttributeType("testString", String.class); AttributeType[] types = { geometryAttribute, booleanAttribute, charAttribute, byteAttribute, shortAttribute, intAttribute, longAttribute, floatAttribute, doubleAttribute, stringAttribute }; // Builds the schema testSchema = FeatureTypeFactory.newFeatureType(types, "testSchema"); ===================================================================== Found a 15 line (139 tokens) duplication in the following files: Starting at line 624 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/array/GenericArray.java Starting at line 664 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/array/GenericArray.java public Character(final char[] array) { super(XArray.isSorted(array)); this.array = array; for (int i=array.length; --i>=0;) { final double value = array[i]; if (valuemaximum) maximum=value; } } public int sizeof () {return 16;} public int length () {return array.length;} public double getAsDouble (int i) {return array[i];} public float getAsFloat (int i) {return array[i];} public int getAsInteger(int i) {return array[i];} protected int binarySearch(double v) {return Arrays.binarySearch(array, (char)Math.floor(v));} ===================================================================== Found a 24 line (139 tokens) duplication in the following files: Starting at line 149 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/data/postgis/PostgisTest.java Starting at line 195 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/data/postgis/PostgisLockingTest.java postgis = new PostgisLockingDataSource(connection, TABLE); collection = postgis.getFeatures(query); Feature feature = (Feature) collection.iterator().next(); LOGGER.fine("name feature is " + feature + ", and feature type is " + feature.getFeatureType()); String[] fidsOnly = new String[0]; query.setPropertyNames(fidsOnly); collection = postgis.getFeatures(query); feature = (Feature) collection.iterator().next(); LOGGER.fine("fid feature is " + feature + ", and feature type is " + feature.getFeatureType()); String[] badAtts = { "bull", "blorg" }; query.setPropertyNames(badAtts); try { collection = postgis.getFeatures(query); fail("exception should be thrown for non matching propertyNames"); } catch (DataSourceException dse) { assertTrue(dse != null); } } ===================================================================== Found a 21 line (139 tokens) duplication in the following files: Starting at line 1401 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 621 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java return javaFont.deriveFont(styleCode, size); } if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("not already loaded"); } if (fontFamilies.contains(requestedFont)) { String reqStyle = (String) fonts[k].getFontStyle().getValue(feature); if (fontStyleLookup.containsKey(reqStyle)) { styleCode = ((Integer) fontStyleLookup.get(reqStyle)).intValue(); } else { styleCode = java.awt.Font.PLAIN; } String reqWeight = (String) fonts[k].getFontWeight().getValue(feature); if (reqWeight.equalsIgnoreCase("Bold")) { styleCode = styleCode | java.awt.Font.BOLD; } ===================================================================== Found a 34 line (137 tokens) duplication in the following files: Starting at line 457 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java Starting at line 818 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java } response.setContentType(format); OutputStream out = response.getOutputStream(); // avoid caching in browser response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); try { formatImageOutputStream(format, image, out); } catch (Exception exp) { exp.printStackTrace(); LOGGER.severe( "Unable to complete image generation after response started : " + exp + exp.getMessage()); if (exp instanceof SecurityException) { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + " JAI may not have 'write' and 'delete' permissions in temp folder"); } else { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + "Check JAI configuration"); } }finally{ out.close(); image = null; } } else { ===================================================================== Found a 56 line (135 tokens) duplication in the following files: Starting at line 101 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Hints.java Starting at line 126 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/j2d/Hints.java public static final RenderingHints.Key PREFETCH = new Hints(3, Boolean.class); /** * The class name for {@link #valueClass}. */ private final String className; /** * Base class of all values for this key. Will be created from {@link #className} * only when first required, in order to avoid too early class loading. */ private Class valueClass; /** * Construct a new key. * * @param id An ID. Must be unique for all instances of {@link Key}. * @param valueClass Base class of all valid values. */ private Hints(final int id, final Class valueClass) { super(id); this.valueClass = valueClass; this.className = valueClass.getName(); } /** * Construct a new key. This constructor is used when a class loading should * be deferred until first needed. * * @param id An ID. Must be unique for all instances of {@link Key}. * @param className Name of base class for all valid values. */ private Hints(final int id, final String className) { super(id); this.className = className; try { assert !Class.forName(className).isPrimitive(); } catch (ClassNotFoundException exception) { throw new AssertionError(exception); } } /** * Returns true if the specified object is a valid value for this key. * * @param value The object to test for validity. * @return true if the value is valid; false otherwise. */ public boolean isCompatibleValue(final Object value) { if (value == null) { return false; } if (valueClass == null) try { valueClass = Class.forName(className); } catch (ClassNotFoundException exception) { Utilities.unexpectedException("org.geotools.renderer", "Hints", "isCompatibleValue", ===================================================================== Found a 25 line (135 tokens) duplication in the following files: Starting at line 1432 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 645 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("requesting " + requestedFont + " " + styleCode + " " + size); } javaFont = new java.awt.Font(requestedFont, styleCode, size); loadedFonts.put(requestedFont, javaFont); return javaFont; } if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("not a system font"); } // may be its a file or url InputStream is = null; if (requestedFont.startsWith("http") || requestedFont.startsWith("file:")) { try { URL url = new URL(requestedFont); is = url.openStream(); } catch (MalformedURLException mue) { // this may be ok - but we should mention it if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Bad url in SLDStyleFactory " + requestedFont + "\n" + mue); ===================================================================== Found a 34 line (134 tokens) duplication in the following files: Starting at line 118 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/shp/MultiLineHandler.java Starting at line 136 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/shp/PolygonHandler.java if (shapeType == ShapeType.POLYGONZ) { //z buffer.position(buffer.position() + 2 * 8); for (int t = 0; t < numPoints; t++) { coords[t].z = buffer.getDouble(); } } int offset = 0; int start; int finish; int length; for (int part = 0; part < numParts; part++) { start = partOffsets[part]; if (part == (numParts - 1)) { finish = numPoints; } else { finish = partOffsets[part + 1]; } length = finish - start; // Use the progressive CCW algorithm. // basically the area algorithm for polygons // which also tells us vertex order based upon the // sign of the area. Coordinate[] points = new Coordinate[length]; //double area = 0; //int sx = offset; for (int i = 0; i < length; i++) { points[i] = coords[offset++]; ===================================================================== Found a 44 line (134 tokens) duplication in the following files: Starting at line 57 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/opengis/src/org/opengis/ct/CT_Parameter.java Starting at line 63 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/opengis/src/org/opengis/cs/CS_ProjectionParameter.java public CS_ProjectionParameter(final String name, final double value) { this.name = name; this.value = value; } /** * Returns a hash value for this parameter. * This value need not remain consistent between * different implementations of the same class. */ public int hashCode() { final long longCode = Double.doubleToLongBits(value); int code = (int)(longCode >>> 32) ^ (int)longCode; if (name!=null) code ^= name.hashCode(); return code; } /** * Returns a copy of this parameter. */ public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException exception) { // Should not happen, since we are cloneable. throw new InternalError(exception.getMessage()); } } /** * Compares the specified object with * this parameter for equality. */ public boolean equals(final Object object) { if (object!=null && getClass().equals(object.getClass())) { final CS_ProjectionParameter that = (CS_ProjectionParameter) object; ===================================================================== Found a 15 line (134 tokens) duplication in the following files: Starting at line 93 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineCoveredByPolygonBoundaryValidation.java Starting at line 89 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/LineNotTouchingPolygonInteriorValidation.java FeatureResults frPoly = fsPoly.getFeatures(); FeatureCollection fcPoly = frPoly.collection(); while(fLine.hasNext()){ Feature line = fLine.next(); FeatureIterator fPoly = fcPoly.features(); Geometry lineGeom = line.getDefaultGeometry(); if(envelope.contains(lineGeom.getEnvelopeInternal())){ // check for valid comparison if(LineString.class.isAssignableFrom(lineGeom.getClass())){ while(fPoly.hasNext()){ Feature poly = fPoly.next(); Geometry polyGeom = poly.getDefaultGeometry(); if(envelope.contains(polyGeom.getEnvelopeInternal())){ if(Polygon.class.isAssignableFrom(polyGeom.getClass())){ ===================================================================== Found a 28 line (134 tokens) duplication in the following files: Starting at line 817 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gc/GridCoverage.java Starting at line 843 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gc/GridCoverage.java Starting at line 869 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gc/GridCoverage.java public double[] evaluate(final Point2D coord, final double[] dest) throws CannotEvaluateException { final Point2D pixel = gridGeometry.inverseTransform(coord); final double fx = pixel.getX(); final double fy = pixel.getY(); if (!Double.isNaN(fx) && !Double.isNaN(fy)) { final int x = (int)Math.round(fx); final int y = (int)Math.round(fy); if (image.getBounds().contains(x,y)) { // getBounds() returns a cached instance. return image.getTile(image.XToTileX(x), image.YToTileY(y)).getPixel(x, y, dest); } } throw new PointOutsideCoverageException(coord); } /** * Returns a debug string for the specified coordinate. This method produces a * string with pixel coordinates and pixel values for all bands (with geophysics * values or category name in parenthesis). Example for a 1-banded image: * *
(1171,1566)=[196 (29.6 0C)]
* * @param coord The coordinate point where to evaluate. * @return A string with pixel coordinates and pixel values at the specified location, * or null if coord is outside coverage. */ public synchronized String getDebugString(final CoordinatePoint coord) { ===================================================================== Found a 60 line (131 tokens) duplication in the following files: Starting at line 193 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/CrossesIntegrity.java Starting at line 197 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/relate/OverlapsIntegrity.java System.out.println("Does the one contain the other?->" + g1.contains(g2)); if(g1.overlaps(g2) != expected || g1.contains(g2) != expected) { results.error( f1, f1.getDefaultGeometry().getGeometryType()+" "+getGeomTypeRefA()+" overlapped "+getGeomTypeRefB()+"("+f2.getID()+"), Result was not "+expected ); success = false; } } } }finally { /** Close the connections to the feature readers*/ try { fr1.close(); if (fr2 != null) fr2.close(); } catch (IOException e4) { e4.printStackTrace(); throw e4; } } return success; } /** * validateSingleLayer Purpose:
*

* This validation tests for a geometry that overlaps with itself. * Uses JTS' Geometry.overlaps(Geometry) and Geometry.contains(Geometry)method. * The DE-9IM intersection matrix for overlaps is: * T*T***T** (for two points or two surfaces) * 1*T***T** (for two curves) * Contains DE-9IM intersection matrix is T*F**F***. *

* * Description:
*

* The function filters the FeatureSource using the given bounding box. * It creates iterators over the filtered FeatureSource. It calls overlaps() and contains() using the * geometries in the FeatureSource layer. Tests the results of the method calls against * the given expected results. Returns true if the returned results and the expected results * are true, false otherwise. * *

* * Author: bowens
* Created on: Apr 27, 2004
* @param featureSourceA - the FeatureSource to pull the original geometries from. This geometry is the one that is tested for overlapping itself * @param expected - boolean value representing the user's expected outcome of the test * @param results - ValidationResults * @param bBox - Envelope - the bounding box within which to perform the overlaps() and contains() * @return boolean result of the test * @throws Exception - IOException if iterators improperly closed */ private boolean validateSingleLayer(FeatureSource featureSourceA, boolean expected, ValidationResults results, Envelope bBox) throws Exception { boolean success = true; ===================================================================== Found a 10 line (131 tokens) duplication in the following files: Starting at line 421 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gtopo30/src/org/geotools/data/gtopo30/GTopo30DataSource.java Starting at line 305 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderingGridCoverageTest.java GeometryFactory geometryFactory = new GeometryFactory(); Rectangle2D rect = gc.getEnvelope().toRectangle2D(); Coordinate[] coord = new Coordinate[5]; coord[0] = new Coordinate(rect.getMinX(), rect.getMinY()); coord[1] = new Coordinate(rect.getMaxX(), rect.getMinY()); coord[2] = new Coordinate(rect.getMaxX(), rect.getMaxY()); coord[3] = new Coordinate(rect.getMinX(), rect.getMaxY()); coord[4] = new Coordinate(rect.getMinX(), rect.getMinY()); Feature feature = null; ===================================================================== Found a 29 line (130 tokens) duplication in the following files: Starting at line 834 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataSource.java Starting at line 205 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java private Set getFidSet(Connection conn) throws IOException { Set fids = new HashSet(); Statement statement = null; try { LOGGER.finer("entering fid set"); //conn = getConnection(); statement = conn.createStatement(); DefaultQuery query = new DefaultQuery(); query.setPropertyNames(new String[0]); SQLUnpacker unpacker = new SQLUnpacker(encoder.getCapabilities()); //REVISIT: redo unpacker-this has to be called first, or it breaks. unpacker.unPackAND(null); String sql = makeSql(unpacker, (Query) query); ResultSet result = statement.executeQuery(sql); while (result.next()) { //REVISIT: this formatting could be done after the remove, //would speed things up, but also would make that code ugly. fids.add(createFid(result.getString(1))); } } catch (SQLException sqle) { String message = CONN_ERROR + sqle.getMessage(); LOGGER.warning(message); ===================================================================== Found a 31 line (129 tokens) duplication in the following files: Starting at line 295 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java Starting at line 325 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java public float[] evaluate(final Point2D coord, float[] dest) throws CannotEvaluateException { if (fallback!=null) { dest = super.evaluate(coord, dest); } try { final Point2D pixel = toGrid.transform(coord, null); final double x = pixel.getX(); final double y = pixel.getY(); if (!Double.isNaN(x) && !Double.isNaN(y)) { dest = interpolate(x, y, dest, 0, image.getNumBands()); if (dest != null) { return dest; } } } catch (TransformException exception) { throw new CannotEvaluateException(coord, exception); } throw new PointOutsideCoverageException(coord); } /** * Return an sequence of double values for a given two-dimensional point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or null. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ public double[] evaluate(final Point2D coord, double[] dest) throws CannotEvaluateException { ===================================================================== Found a 19 line (128 tokens) duplication in the following files: Starting at line 295 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java Starting at line 355 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java public double[] evaluate(final Point2D coord, double[] dest) throws CannotEvaluateException { if (fallback!=null) { dest = super.evaluate(coord, dest); } try { final Point2D pixel = toGrid.transform(coord, null); final double x = pixel.getX(); final double y = pixel.getY(); if (!Double.isNaN(x) && !Double.isNaN(y)) { dest = interpolate(x, y, dest, 0, image.getNumBands()); if (dest != null) { return dest; } } } catch (TransformException exception) { throw new CannotEvaluateException(coord, exception); } throw new PointOutsideCoverageException(coord); } ===================================================================== Found a 22 line (127 tokens) duplication in the following files: Starting at line 562 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataSource.java Starting at line 754 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java AttributeType[] schemaTypes = getSchema().getAttributeTypes(); if (query.retrieveAllProperties()) { return schemaTypes; } else { List attNames = Arrays.asList(query.getPropertyNames()); AttributeType[] retAttTypes = new AttributeType[attNames.size()]; int retPos = 0; for (int i = 0, n = schemaTypes.length; i < n; i++) { String schemaTypeName = schemaTypes[i].getName(); if (attNames.contains(schemaTypeName)) { retAttTypes[retPos++] = schemaTypes[i]; } } //TODO: better error reporting, and completely test this method. if (attNames.size() != retPos) { String msg = "attempted to request a property, " + attNames.get(0) + " that is not part of the schema "; throw new IOException(msg); ===================================================================== Found a 29 line (125 tokens) duplication in the following files: Starting at line 676 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java Starting at line 818 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/wmsserver/src/org/geotools/wms/WMSServlet.java } response.setContentType(format); OutputStream out = response.getOutputStream(); // avoid caching in browser response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); try { formatImageOutputStream(format, image, out); } catch (Exception exp) { exp.printStackTrace(); LOGGER.severe( "Unable to complete image generation after response started : " + exp + exp.getMessage()); if (exp instanceof SecurityException) { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + " JAI may not have 'write' and 'delete' permissions in temp folder"); } else { response.sendError(500, "Image generation failed because of: " + exp.getStackTrace()[0] + "Check JAI configuration"); } }finally{ ===================================================================== Found a 15 line (124 tokens) duplication in the following files: Starting at line 605 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java Starting at line 629 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java String reqStyle = (String) fonts[k].getFontStyle().getValue(feature); if (fontStyleLookup.containsKey(reqStyle)) { styleCode = ((Integer) fontStyleLookup.get(reqStyle)).intValue(); } else { styleCode = java.awt.Font.PLAIN; } String reqWeight = (String) fonts[k].getFontWeight().getValue(feature); if (reqWeight.equalsIgnoreCase("Bold")) { styleCode = styleCode | java.awt.Font.BOLD; } size = ((Number) fonts[k].getFontSize().getValue(feature)).intValue(); ===================================================================== Found a 17 line (124 tokens) duplication in the following files: Starting at line 656 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gc/LocalizationGridTransform2D.java Starting at line 694 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gc/LocalizationGridTransform2D.java final double[] dstPts, int dstOff, int numPts) throws TransformException { int postIncrement = 0; if (srcPts == dstPts && srcOff < dstOff) { srcOff += (numPts-1)*2; dstOff += (numPts-1)*2; postIncrement = -4; } final Point2D.Double source = new Point2D.Double(); final Point2D.Double target = new Point2D.Double(); final AffineTransform tr = new AffineTransform(global); while (--numPts >= 0) { source.x = srcPts[srcOff++]; source.y = srcPts[srcOff++]; inverseTransform(source, target, tr); dstPts[dstOff++] = target.x; ===================================================================== Found a 30 line (123 tokens) duplication in the following files: Starting at line 222 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/ExpressionDOMParser.java Starting at line 252 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/ExpressionDOMParser.java Starting at line 283 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/ExpressionDOMParser.java Starting at line 313 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/ExpressionDOMParser.java math = FILTER_FACT.createMathExpression(DefaultExpression.MATH_DIVIDE); Node value = child.getFirstChild(); while (value.getNodeType() != Node.ELEMENT_NODE) { value = value.getNextSibling(); } LOGGER.finer("add left value -> " + value + "<-"); math.addLeftValue(parseExpression(value)); value = value.getNextSibling(); while (value.getNodeType() != Node.ELEMENT_NODE) { value = value.getNextSibling(); } LOGGER.finer("add right value -> " + value + "<-"); math.addRightValue(parseExpression(value)); return math; } catch (IllegalFilterException ife) { LOGGER.warning("Unable to build expression " + ife); return null; } } if (childName.equalsIgnoreCase("PropertyName")) { ===================================================================== Found a 37 line (122 tokens) duplication in the following files: Starting at line 104 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/attributes/UniqueFIDValidation.java Starting at line 160 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/UniqueFIDIntegrityValidation.java } /** * Override validate. *

* Description ... *

* @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) * * @param layers * @param envelope * @param results * @return */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception{ HashMap FIDs = new HashMap(); boolean result = true; Iterator it = layers.values().iterator(); while (it.hasNext())// for each layer { FeatureSource featureSource = (FeatureSource) it.next(); FeatureReader reader = featureSource.getFeatures().reader(); try { while (reader.hasNext()) // for each feature { Feature feature = reader.next(); String fid = feature.getID(); if(FIDs.containsKey(fid)) // if a FID like this one already exists { results.error(feature, "FID already exists."); result = false; } else ===================================================================== Found a 35 line (121 tokens) duplication in the following files: Starting at line 228 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteShape.java Starting at line 296 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteShape.java public Rectangle2D getBounds2D() { Coordinate[] coords = geometry.getEnvelope().getCoordinates(); // get out corners. the documentation doens't specify in which // order the bounding box coordinates are returned double x1; double y1; double x2; double y2; x1 = x2 = coords[0].x; y1 = y2 = coords[0].y; for (int i = 1; i < 3; i++) { double x = coords[i].x; double y = coords[i].y; if (x < x1) { x1 = x; } if (x > x2) { x2 = x; } if (y < y1) { y1 = y; } if (y > y2) { y2 = y; } } ===================================================================== Found a 41 line (121 tokens) duplication in the following files: Starting at line 117 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/mysql/src/org/geotools/data/mysql/MySQLDataStoreFactory.java Starting at line 139 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataStoreFactory.java if (!((String) params.get("dbtype")).equalsIgnoreCase("postgis")) { return false; } if (!params.containsKey("host")) { return false; } if (!params.containsKey("user")) { return false; } if (!params.containsKey("database")) { return false; } return true; } /** * Construct a postgis data store using the params. * * @param params The full set of information needed to construct a live * data source. Should have dbtype equal to postgis, as well as * host, user, passwd, database, and table. * * @return The created DataSource, this may be null if the required * resource was not found or if insufficent parameters were given. * Note that canProcess() should have returned false if the * problem is to do with insuficent parameters. * * @throws IOException See DataSourceException * @throws DataSourceException Thrown if there were any problems creating * or connecting the datasource. */ public DataStore createDataStore(Map params) throws IOException { String host = (String) HOST.lookUp(params); String user = (String) USER.lookUp(params); String passwd = (String) PASSWD.lookUp(params); Integer port = (Integer) PORT.lookUp(params); String database = (String) DATABASE.lookUp(params); ===================================================================== Found a 8 line (119 tokens) duplication in the following files: Starting at line 38 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gtopo30/tests/unit/org/geotools/data/gtopo30/GT30HeaderTest.java Starting at line 76 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gtopo30/tests/unit/org/geotools/data/gtopo30/GT30HeaderTest.java assertEquals("TotalRowBytes", header.getProperty(GT30Header.TOTALROWBYTES), new Integer(4800)); assertEquals("BandGapBytes", header.getProperty(GT30Header.BANDGAPBYTES), new Integer(0)); assertEquals("NoData", header.getProperty(GT30Header.NODATA), new Integer(-9999)); assertEquals("ULXMap", header.getProperty(GT30Header.ULXMAP), new Double(-19.99583333333333)); assertEquals("ULYMap", header.getProperty(GT30Header.ULYMAP), new Double(89.99583333333334)); assertEquals("XDim", header.getProperty(GT30Header.XDIM), new Double(0.00833333333333)); assertEquals("YDim", header.getProperty(GT30Header.YDIM), new Double(0.00833333333333)); } ===================================================================== Found a 35 line (116 tokens) duplication in the following files: Starting at line 84 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisLockingDataSourceFactory.java Starting at line 89 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataSourceFactory.java if (!params.containsKey("port")) { return false; } return true; } /** * Construct a live data source using the params specifed. * * @param params The full set of information needed to construct a live * data source. Should have dbtype equal to postgis, as well as * host, user, passwd, database, and table. * * @return The created DataSource, this may be null if the required * resource was not found or if insufficent parameters were given. * Note that canProcess() should have returned false if the * problem is to do with insuficent parameters. * * @throws DataSourceException Thrown if there were any problems creating * or connecting the datasource. */ public DataSource createDataSource(Map params) throws DataSourceException { if (!canProcess(params)) { return null; } String host = (String) params.get("host"); String user = (String) params.get("user"); String passwd = (String) params.get("passwd"); String port = (String) params.get("port"); String database = (String) params.get("database"); String table = (String) params.get("table"); String charSet = (String) params.get("charset"); String useStrict = (String) params.get("strictbbox"); ===================================================================== Found a 11 line (115 tokens) duplication in the following files: Starting at line 305 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/TextStyleTest.java Starting at line 265 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/DefaultMarkTest.java java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_RGB); java.awt.Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(java.awt.Color.white); g.fillRect(0, 0, w, h); renderer.paint(g, new java.awt.Rectangle(0, 0, w, h), at); java.io.File file = new java.io.File(base.getPath(), ===================================================================== Found a 17 line (114 tokens) duplication in the following files: Starting at line 1885 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 1950 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java .toString()); Point2D mapCentre = new java.awt.geom.Point2D.Double(tx, ty); Point2D graphicCentre = new java.awt.geom.Point2D.Double(); temp.transform(mapCentre, graphicCentre); markAT.translate(graphicCentre.getX(), graphicCentre.getY()); double shearY = temp.getShearY(); double scaleY = temp.getScaleY(); double originalRotation = Math.atan(shearY / scaleY); if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("originalRotation " + originalRotation); } markAT.rotate(rotation - originalRotation); ===================================================================== Found a 15 line (113 tokens) duplication in the following files: Starting at line 150 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/units/DMSUnit.java Starting at line 171 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/units/DMSUnit.java float value = values[i]*divider; final int deg,min; deg = (int) (value/10000); value -= 10000*deg; min = (int) (value/ 100); value -= 100*min; if (min<=-60 || min>=60) { throw new UnitException("Invalid minutes: "+min); } if (value<=-60 || value>=60) // Accept NaN { throw new UnitException("Invalid secondes: "+value); } values[i] = ((value/60) + min)/60 + deg; } DEGREE.inverseConvert(values, toUnit); } ===================================================================== Found a 50 line (113 tokens) duplication in the following files: Starting at line 46 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/RoadNetworkValidationResults.java Starting at line 45 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/tests/unit/org/geotools/validation/RoadValidationResults.java public RoadValidationResults() { validationList = new ArrayList(); failedFeatures = new ArrayList(); warningFeatures = new ArrayList(); failureMessages = new ArrayList(); warningMessages = new ArrayList(); } /** * Override setValidation. *

* Description ... *

* @see org.geotools.validation.ValidationResults#setValidation(org.geotools.validation.Validation) * * @param validation */ public void setValidation(Validation validation) { validationList.add(validation); } /** * Override error. *

* Description ... *

* @see org.geotools.validation.ValidationResults#error(org.geotools.feature.Feature, java.lang.String) * * @param feature * @param message */ public void error(Feature feature, String message) { failedFeatures.add(feature); failureMessages.add(feature.getID() + ": " + message); } /** * Override warning. *

* Description ... *

* @see org.geotools.validation.ValidationResults#warning(org.geotools.feature.Feature, java.lang.String) * * @param feature * @param message */ public void warning(Feature feature, String message) { warningFeatures.add(feature); warningMessages.add(feature.getID() + ": " + message); } ===================================================================== Found a 21 line (112 tokens) duplication in the following files: Starting at line 410 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java Starting at line 508 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java } catch (SQLException sqle) { fail = true; close(conn, getTransaction(), sqle); String message = CONN_ERROR + sqle.getMessage(); LOGGER.warning(message); throw new DataSourceException(message, sqle); } catch (SQLEncoderException ence) { fail = true; String message = "error encoding sql from filter " + ence.getMessage(); LOGGER.warning(message); throw new DataSourceException(message, ence); } catch (IllegalAttributeException iae) { throw new DataSourceException("attribute problem", iae); } finally { close(statement); close(conn, getTransaction(), null); } } ===================================================================== Found a 8 line (112 tokens) duplication in the following files: Starting at line 29 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gtopo30/tests/unit/org/geotools/data/gtopo30/GT30HeaderTest.java Starting at line 67 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gtopo30/tests/unit/org/geotools/data/gtopo30/GT30HeaderTest.java URL headerURL = getTestResource("SRC.SCH"); GT30Header header = new GT30Header(headerURL); assertEquals("Byteorder", header.getProperty(GT30Header.BYTEORDER), "M"); assertEquals("Layout", header.getProperty(GT30Header.LAYOUT), "BIL"); assertEquals("NRows", header.getProperty(GT30Header.NROWS), new Integer(6000)); assertEquals("BCols", header.getProperty(GT30Header.NCOLS), new Integer(4800)); assertEquals("NBands", header.getProperty(GT30Header.NBANDS), new Integer(1)); assertEquals("NBits", header.getProperty(GT30Header.NBITS), new Integer(8)); ===================================================================== Found a 45 line (112 tokens) duplication in the following files: Starting at line 162 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LineIterator.java Starting at line 161 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/PolygonIterator.java } else if (currentCoord == this.coords.length) { return SEG_CLOSE; } else { coords[0] = this.coords[currentCoord].x; coords[1] = this.coords[currentCoord].y; at.transform(coords, 0, coords, 0, 1); return SEG_LINETO; } } /** * 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. * * @param coords an array that holds the data returned from this method * * @return the path-segment type of the current path segment. * * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public int currentSegment(float[] coords) { double[] dcoords = new double[2]; int result = currentSegment(dcoords); coords[0] = (float) dcoords[0]; coords[1] = (float) dcoords[1]; return result; } /** * Return the winding rule for determining the interior of the path. * * @return WIND_EVEN_ODD by default. */ public int getWindingRule() { return WIND_EVEN_ODD; ===================================================================== Found a 23 line (112 tokens) duplication in the following files: Starting at line 30 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gmldatasource/tests/unit/org/geotools/gml/ServiceTest.java Starting at line 47 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/data/postgis/ServiceTest.java public class ServiceTest extends TestCase { public ServiceTest(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { TestSuite suite = new TestSuite(ServiceTest.class); return suite; } public void testIsAvailable() { Iterator list = DataSourceFinder.getAvailableDataSources(); boolean found = false; while (list.hasNext()) { DataSourceFactorySpi fac = (DataSourceFactorySpi) list.next(); if (fac instanceof PostgisDataSourceFactory) { ===================================================================== Found a 20 line (111 tokens) duplication in the following files: Starting at line 73 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PolygonNotOverlappingLineValidation.java Starting at line 80 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/validation/src/org/geotools/validation/spatial/PolygonNotCoveredByPolygonValidation.java FeatureSource polySource2 = (FeatureSource) layers.get(getRestrictedPolygonTypeRef()); Object[] poly1 = polySource1.getFeatures().collection().toArray(); Object[] poly2 = polySource2.getFeatures().collection().toArray(); if (!envelope.contains(polySource1.getBounds())) { results.error((Feature) poly1[0], "Polygon Feature Source is not contained within the Envelope provided."); return false; } if (!envelope.contains(polySource2.getBounds())) { results.error((Feature) poly1[0], "Restricted Polygon Feature Source is not contained within the Envelope provided."); return false; } for (int i = 0; i < poly2.length; i++) { ===================================================================== Found a 26 line (110 tokens) duplication in the following files: Starting at line 846 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1222 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Geometry(); } jj_consume_token(RP); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final private boolean jj_2_1(int xla) { ===================================================================== Found a 13 line (110 tokens) duplication in the following files: Starting at line 198 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/map/tests/unit/org/geotools/map/MapContextTest.java Starting at line 251 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/map/tests/unit/org/geotools/map/MapContextTest.java context.addLayers(new MapLayer[] { layer3 }); assertEquals(3, context.getLayerCount()); assertEquals(0, boundsChangedCount); assertEquals(1, layerAddedCount); assertEquals(0, layerRemovedCount); assertEquals(0, layerChangedCount); assertEquals(0, layerMovedCount); assertEquals(0, propertyChangeCount); assertEquals(2, ((MapLayerListEvent) events.get(0)).getFromIndex()); assertEquals(2, ((MapLayerListEvent) events.get(0)).getToIndex()); assertEquals(layer3, ((MapLayerListEvent) events.get(0)).getLayer()); clearEventTracking(); ===================================================================== Found a 20 line (109 tokens) duplication in the following files: Starting at line 205 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/DOMParserTest.java Starting at line 175 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/tests/unit/org/geotools/filter/XMLEncoderTest.java LOGGER.fine("exporting " + uri); // first grab a filter node NodeList nodes = dom.getElementsByTagName("Filter"); for (int j = 0; j < nodes.getLength(); j++) { Element filterNode = (Element) nodes.item(j); NodeList list = filterNode.getChildNodes(); Node child = null; for (int i = 0; i < list.getLength(); i++) { child = list.item(i); //_log.getLoggerRepository().setThreshold(Level.INFO); if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) { continue; } filter = FilterDOMParser.parseFilter(child); ===================================================================== Found a 25 line (109 tokens) duplication in the following files: Starting at line 1084 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1115 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1146 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1177 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java jjtn000.token = jj_consume_token(MULTIPOLYGON); CoordsList(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final public void GeometryCollection() throws ParseException { ===================================================================== Found a 24 line (109 tokens) duplication in the following files: Starting at line 848 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1023 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java jj_consume_token(RP); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final public void LineString() throws ParseException { ===================================================================== Found a 24 line (108 tokens) duplication in the following files: Starting at line 206 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 458 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 538 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java UnaryExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte002;} } if (jjte002 instanceof ParseException) { {if (true) throw (ParseException)jjte002;} } {if (true) throw (Error)jjte002;} } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); jjtreeCloseNodeScope(jjtn002); } } break; default: jj_la1[10] = jj_gen; ===================================================================== Found a 25 line (108 tokens) duplication in the following files: Starting at line 90 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 132 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java EqualityExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); jjtreeCloseNodeScope(jjtn001); } } } } final public void EqualityExpression() throws ParseException { ===================================================================== Found a 26 line (108 tokens) duplication in the following files: Starting at line 182 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/filter/SQLEncoderPostgis.java Starting at line 456 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/oraclespatial/src/org/geotools/filter/SQLEncoderOracle.java super.visit(literal); } } /** * DOCUMENT ME! * * @param filter * * @see org.geotools.filter.SQLEncoder#visit(org.geotools.filter.FidFilter) */ public void visit(FidFilter filter) { String[] fids = filter.getFids(); LOGGER.finer("Exporting FID=" + Arrays.asList(fids)); for (int i = 0; i < fids.length; i++) { try { out.write(fidColumn); out.write(" = '"); int pos; if ((pos = fids[i].indexOf('.')) != -1) { out.write(fids[i].substring(pos + 1)); } else { out.write(fids[i]); ===================================================================== Found a 24 line (107 tokens) duplication in the following files: Starting at line 1054 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1085 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java CoordsList(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final public void MultiPoint() throws ParseException { ===================================================================== Found a 24 line (107 tokens) duplication in the following files: Starting at line 1023 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1224 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java jj_consume_token(RP); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final private boolean jj_2_1(int xla) { ===================================================================== Found a 10 line (106 tokens) duplication in the following files: Starting at line 470 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderStyleTest.java Starting at line 380 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/rendering-styling/tests/unit/org/geotools/styling/RenderingGridCoverageTest.java "RenderingGridCoverageTest_" + renderer.getClass().getName().replace('.', '_') + "_" + fileSuffix + width + "x" + height + ".png"); java.io.FileOutputStream out = new java.io.FileOutputStream(file); boolean fred = javax.imageio.ImageIO.write(image, "PNG", out); if (!fred) { System.out.println("Failed to write image to " + file.toString()); } java.io.File file2 = new java.io.File(base.getPath() + "/exemplars/", ===================================================================== Found a 24 line (106 tokens) duplication in the following files: Starting at line 848 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1054 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Coords(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final public void Polygon() throws ParseException { ===================================================================== Found a 17 line (106 tokens) duplication in the following files: Starting at line 560 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/data/postgis/PostgisDataStoreAPITest.java Starting at line 580 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/tests/unit/org/geotools/data/postgis/PostgisDataStoreAPITest.java FeatureType actual = data.getSchema("river"); assertEquals("namespace", expected.getNamespace(), actual.getNamespace()); assertEquals("typeName", expected.getTypeName(), actual.getTypeName()); //assertEquals( "compare", 0, DataUtilities.compare( expected, actual )); assertEquals("attributeCount", expected.getAttributeCount(), actual.getAttributeCount()); for (int i = 0; i < expected.getAttributeCount(); i++) { AttributeType expectedAttribute = expected.getAttributeType(i); AttributeType actualAttribute = actual.getAttributeType(i); assertEquals("attribute " + expectedAttribute.getName(), expectedAttribute, actualAttribute); } assertEquals(expected, actual); } ===================================================================== Found a 18 line (106 tokens) duplication in the following files: Starting at line 551 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/sldstyling/src/org/geotools/styling/SLDParser.java Starting at line 583 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/sldstyling/src/org/geotools/styling/SLDParser.java symbol.setStroke((Stroke) null); NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) { continue; } if (child.getLocalName().equalsIgnoreCase(geomSt)) { symbol.setGeometryPropertyName(parseGeometryName(child)); } if (child.getLocalName().equalsIgnoreCase("Stroke")) { symbol.setStroke(parseStroke(child)); } ===================================================================== Found a 18 line (106 tokens) duplication in the following files: Starting at line 234 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LineIterator.java Starting at line 230 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/PolygonIterator.java } else { if (generalize) { if (oldCoord == null) { currentCoord++; oldCoord = coords[currentCoord]; } else { double distx = 0; double disty = 0; do { currentCoord++; if (currentCoord < coords.length) { distx = Math.abs(coords[currentCoord].x - oldCoord.x); disty = Math.abs(coords[currentCoord].y - oldCoord.y); } } while (((distx * xScale) < maxDistance) && ((disty * yScale) < maxDistance) && (currentCoord < coords.length)); ===================================================================== Found a 26 line (105 tokens) duplication in the following files: Starting at line 45 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/vpf/src/org/geotools/data/vpf/io/CoordinateDouble.java Starting at line 45 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/vpf/src/org/geotools/data/vpf/io/CoordinateFloat.java public CoordinateFloat(float[][] coords) { coordinates = coords; } /** * Describe toString method here. * * @return a String value */ public String toString() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < coordinates.length; i++) { sb.append("("); for (int j = 0; j < coordinates[i].length; j++) { if (j > 0) { sb.append(", "); } sb.append(coordinates[i][j]); } sb.append(")"); } return sb.toString(); } } ===================================================================== Found a 23 line (105 tokens) duplication in the following files: Starting at line 177 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 429 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 509 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java UnaryExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); jjtreeCloseNodeScope(jjtn001); } } break; case 43: ===================================================================== Found a 27 line (105 tokens) duplication in the following files: Starting at line 226 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/XAffineTransform.java Starting at line 267 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/resources/src/org/geotools/resources/XAffineTransform.java transform.inverseTransform(point, point); if (point.xxmax) xmax=point.x; if (point.yymax) ymax=point.y; } if (dest!=null) { dest.setRect(xmin, ymin, xmax-xmin, ymax-ymin); return dest; } return new Rectangle2D.Double(xmin, ymin, xmax-xmin, ymax-ymin); } /** * Calculates the inverse affine transform of a point without bearing in * mind the translation. * * @param transform Affine transform to use. * @param source Point to transform. This rectangle will not be modified. * @param dest Point in which to place the result. If null, a new * point will be created. * * @return The inverse transform of the source point. * @throws NoninvertibleTransformException if the affine transform can't be * inverted. */ public static Point2D inverseDeltaTransform(final AffineTransform transform, ===================================================================== Found a 22 line (104 tokens) duplication in the following files: Starting at line 189 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/shp/MultiLineHandler.java Starting at line 406 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/shapefile/src/org/geotools/data/shapefile/shp/PolygonHandler.java double[] zExtreame = JTSUtilities.zMinMax(multi.getCoordinates()); if (Double.isNaN(zExtreame[0])) { buffer.putDouble(0.0); buffer.putDouble(0.0); } else { buffer.putDouble(zExtreame[0]); buffer.putDouble(zExtreame[1]); } for (int t = 0; t < npoints; t++) { double z = coords[t].z; if (Double.isNaN(z)) { buffer.putDouble(0.0); } else { buffer.putDouble(z); } } } if (shapeType == ShapeType.POLYGONM || shapeType == ShapeType.POLYGONZ) { ===================================================================== Found a 24 line (104 tokens) duplication in the following files: Starting at line 1147 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 1224 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java jj_consume_token(RP); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtreeCloseNodeScope(jjtn000); } } } final private boolean jj_2_1(int xla) { ===================================================================== Found a 22 line (104 tokens) duplication in the following files: Starting at line 206 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 290 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java AdditiveExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte002;} } if (jjte002 instanceof ParseException) { {if (true) throw (ParseException)jjte002;} } {if (true) throw (Error)jjte002;} } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); jjtreeCloseNodeScope(jjtn002); } } break; ===================================================================== Found a 21 line (103 tokens) duplication in the following files: Starting at line 90 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java Starting at line 177 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/filter/src/org/geotools/filter/parser/ExpressionParser.java RelationalExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); jjtreeCloseNodeScope(jjtn001); } } ===================================================================== Found a 13 line (103 tokens) duplication in the following files: Starting at line 540 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/array/GenericArray.java Starting at line 584 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/array/GenericArray.java super(XArray.isSorted(array)); this.array = array; for (int i=array.length; --i>=0;) { final double value = array[i]; if (valuemaximum) maximum=value; } } public int type () {return 2;} public int sizeof () {return 64;} public int length () {return array.length;} public double getAsDouble (int i) {return array[i];} public float getAsFloat (int i) {return array[i];} ===================================================================== Found a 6 line (103 tokens) duplication in the following files: Starting at line 281 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/science/src/org/geotools/science/oceano/SeaWater.java Starting at line 314 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/science/src/org/geotools/science/oceano/SeaWater.java final double K0 = ( polynome(T,EOS80_F) + polynome(T,EOS80_G)*SR )*S + polynome(T,EOS80_E); final double DK = K0 + (((EOS80_J*SR+polynome(T,EOS80_I))*S+polynome(T,EOS80_H)) + (polynome(T,EOS80_K) + polynome(T,EOS80_M)*S)*P)*P; final double K_35_0_P = polynome(P,EOS80_N); final double V_S_T_0 = SVAN_S_T_0 + V_35_0_0; return (SVAN_S_T_0*( 1.0 - P/K_35_0_P ) + V_S_T_0*P*DK/(K_35_0_P*( K_35_0_P + DK ))); ===================================================================== Found a 13 line (102 tokens) duplication in the following files: Starting at line 240 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/j2d/SLDRenderedGeometries.java Starting at line 266 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/j2d/SLDRenderedGeometries.java Paint paint = ls2d.getContour(); if(paint instanceof TexturePaint) { TexturePaint tp = (TexturePaint) paint; BufferedImage image = tp.getImage(); Rectangle2D rect = tp.getAnchorRect(); AffineTransform at = graphics.getTransform(); double width = rect.getWidth() * at.getScaleX(); double height = rect.getHeight() * at.getScaleY(); Rectangle2D scaledRect = new Rectangle2D.Double(0, 0, width, height); paint = new TexturePaint(image, scaledRect); } graphics.setPaint(paint); graphics.setStroke(ls2d.getStroke()); ===================================================================== Found a 24 line (102 tokens) duplication in the following files: Starting at line 989 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisDataSource.java Starting at line 388 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/postgis/src/org/geotools/data/postgis/PostgisFeatureStore.java FeatureReader iter = features.reader(); if (iter.hasNext()) { sql = "DELETE FROM \"" + tableName + "\" WHERE "; for (int i = 0; iter.hasNext(); i++) { fid = formatFid(iter.next()); sql += (fidColumn + " = " + fid); if (iter.hasNext()) { sql += " OR "; } else { sql += ";"; } } LOGGER.fine("our delete says : " + sql); statement.executeUpdate(sql); } } close(statement); } catch (SQLException sqle) { fail = true; ===================================================================== Found a 11 line (102 tokens) duplication in the following files: Starting at line 388 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java Starting at line 456 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java Starting at line 535 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/gcs-coverage/src/org/geotools/gp/Interpolator.java double[] dest, int band, final int bandUp) { final double x0 = Math.floor(x); final double y0 = Math.floor(y); final int ix = (int)x0; final int iy = (int)y0; if (!(ix>=xmin && ix=ymin && iy 0) { modCount++; final Object old = array; final int length = Array.getLength(array); array = Array.newInstance(elementType, length - n); System.arraycopy(old, 0, array, 0, i0); System.arraycopy(old, i1, array, i0, length - i1); } assert (Array.getLength(array) & 1) == 0; return modCountChk != modCount; } /** * Remove a range of values from this set. Range may be removed in any order. * * @param lower The lower value to remove, exclusive. * @param upper The upper value to remove, exclusive. * @return true if this set changed as a result of the call. * @throws IllegalArgumentException if lower is greater than upper. */ public boolean remove(byte lower, byte upper) throws IllegalArgumentException { ===================================================================== Found a 5 line (100 tokens) duplication in the following files: Starting at line 244 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/science/src/org/geotools/science/oceano/SeaWater.java Starting at line 281 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/science/src/org/geotools/science/oceano/SeaWater.java final double K0 = ( polynome(T,EOS80_F) + polynome(T,EOS80_G)*SR )*S + polynome(T,EOS80_E); final double DK = K0 + (((EOS80_J*SR+polynome(T,EOS80_I))*S+polynome(T,EOS80_H)) + (polynome(T,EOS80_K) + polynome(T,EOS80_M)*S)*P)*P; final double K_35_0_P = polynome(P,EOS80_N); final double V_S_T_0 = SVAN_S_T_0 + V_35_0_0; ===================================================================== Found a 13 line (100 tokens) duplication in the following files: Starting at line 1378 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/lite-rendering/src/org/geotools/renderer/lite/LiteRenderer.java Starting at line 629 of /home/tom/pmd/pmd-web/src/geotools2/geotools-src/renderer/src/org/geotools/renderer/style/SLDStyleFactory.java String reqStyle = (String) fonts[k].getFontStyle().getValue(feature); if (fontStyleLookup.containsKey(reqStyle)) { styleCode = ((Integer) fontStyleLookup.get(reqStyle)).intValue(); } else { styleCode = java.awt.Font.PLAIN; } String reqWeight = (String) fonts[k].getFontWeight().getValue(feature); if (reqWeight.equalsIgnoreCase("Bold")) { styleCode = styleCode | java.awt.Font.BOLD; }