CPD Results

The following document contains the results of PMD's CPD 4.3.

Duplications

File Line
org/deegree/tools/rendering/manager/stage/StageManager.java 308
org/deegree/tools/rendering/manager/trees/TreeManager.java 277
    }

    private float parseFloatingPoint( String f, Column c ) {
        try {
            return Float.parseFloat( f );
        } catch ( NumberFormatException e ) {
            throw new IllegalArgumentException( c.toString() + ": " + f + " is not a floating point value." );
        }
    }

    /**
     * @param columnsNames
     * @return
     */
    private Map<Column, Integer> mapColumns( String[] columnsNames ) {
        if ( columnsNames == null ) {
            throw new IllegalArgumentException(
                                                "Columnnames must be specified, (they should be the first line of the csv document)" );
        }
        if ( columnsNames.length < Column.values().length ) {
            throw new IllegalArgumentException( "Not enough columns specified, at least: " + Column.values().length
                                                + " columns are expected." );
        }
        Map<Column, Integer> result = new HashMap<Column, Integer>();
        for ( int i = 0; i < columnsNames.length; ++i ) {
            String s = columnsNames[i];
            try {
                Column c = Column.valueOf( s.toUpperCase() );
                result.put( c, i );
            } catch ( Exception e ) {
                LOG.warn( "Could not map: " + s + " to a known column name, column names must be one of: "
                          + Arrays.toString( Column.values() ) );
            }
        }
        boolean columnsCheckout = true;
        for ( Column c : Column.values() ) {
            if ( !result.containsKey( c ) ) {
                LOG.warn( "Missing column: " + c.name().toLowerCase() + ", " + c.getDescription() );
                columnsCheckout = false;
            }

        }
        if ( !columnsCheckout ) {
            throw new IllegalArgumentException(
                                                "Your csv file misses some columns (see above messages, for more information on which columns are missing), cannot proceed without given information." );
        }

        return result;
    }

}
File Line
org/deegree/tools/crs/georeferencing/i18n/Messages.java 134
org/deegree/tools/i18n/Messages.java 127
        }
    }

    private static String get( Properties props, String key, Object... args ) {
        String s = (String) props.get( key );
        if ( s != null ) {
            return MessageFormat.format( s, args );
        }

        return "$Message with key: " + key + " not found$";
    }

    /**
     * @param loc
     *            the locale to be used
     * @param key
     *            to get
     * @param arguments
     *            to fill in the message
     * @return the localized message
     */
    public static synchronized String getMessage( Locale loc, String key, Object... arguments ) {
        if ( loc.getLanguage().equals( lang ) ) {
            return getMessage( key, arguments );
        }

        if ( !props.containsKey( loc ) ) {
            Properties p = new Properties();

            String l = loc.getLanguage();

            if ( !"".equals( l ) ) {
                try {
                    // override messages in this order:
                    // messages_en.properties
                    // /messages_en.properties
                    // messages_lang.properties
                    // /messages_lang.properties
                    String fileName = "messages_en.properties";
                    overrideMessages( fileName, p );
                    fileName = "/messages_en.properties";
                    overrideMessages( fileName, p );
                    fileName = "messages_" + l + ".properties";
                    overrideMessages( fileName, p );
                    fileName = "/messages_" + l + ".properties";
                    overrideMessages( fileName, p );
                } catch ( IOException e ) {
                    LOG.error( "Error loading language file for language '" + l + "': ", e );
                }
            }

            props.put( loc, p );
        }

        return get( props.get( loc ), key, arguments );
    }

    /**
     * Returns the message assigned to the passed key. If no message is assigned, an error message will be returned that
     * indicates the missing key.
     * 
     * @see MessageFormat for conventions on string formatting and escape characters.
     * 
     * @param key
     * @param arguments
     * @return the message assigned to the passed key
     */
    public static String getMessage( String key, Object... arguments ) {
        return get( defaultProps, key, arguments );
    }
File Line
org/deegree/tools/rendering/dem/builder/MacroTriangle.java 415
org/deegree/tools/rendering/dem/builder/dag/DAGBuilder.java 259
    }

    private float[][] mergeBBoxes( float[][] bbox1, float[][] bbox2 ) {
        float[][] bbox = new float[][] { new float[] { bbox1[0][0], bbox1[0][1], bbox1[0][2] },
                                        new float[] { bbox1[1][0], bbox1[1][1], bbox1[1][2] } };
        for ( int i = 0; i <= 2; i++ ) {
            if ( bbox[0][i] > bbox2[0][i] ) {
                bbox[0][i] = bbox2[0][i];
            }
        }
        for ( int i = 0; i <= 2; i++ ) {
            if ( bbox[1][i] < bbox2[1][i] ) {
                bbox[1][i] = bbox2[1][i];
            }
        }
        return bbox;
    }
File Line
org/deegree/tools/rendering/manager/ModelGeneralizor.java 271
org/deegree/tools/rendering/manager/PrototypeAssigner.java 323
        option.setArgName( "\"WHERE id='building_id'\"" );
        options.addOption( option );

        addDatabaseParameters( options );

        CommandUtils.addDefaultOptions( options );
        return options;

    }

    /**
     * Database parameters
     * 
     * @param options
     *            to add the database option to.
     */
    private static void addDatabaseParameters( Options options ) {

        Option option = new Option( "host", DB_HOST, true, "url to the database, with or without port" );
        option.setArgs( 1 );
        option.setArgName( "for example jdbc:postgresql://dbhost:5432/db_name" );
        option.setRequired( true );
        options.addOption( option );

        option = new Option( OPT_DB_USER.substring( 0, 1 ), OPT_DB_USER, true,
                             "username of the database, default will be ${user.name}" );
        option.setArgs( 1 );
        option.setArgName( "for example postgres" );
        options.addOption( option );

        option = new Option( OPT_DB_PASS.substring( 0, 1 ), OPT_DB_PASS, true,
                             "password of the database, default will be empty" );
        option.setArgs( 1 );
        option.setArgName( "for example my_secret_password" );
        options.addOption( option );

    }

    private static void printHelp( Options options ) {
        CommandUtils.printHelp( options, ModelGeneralizor.class.getSimpleName(), null, null );
File Line
org/deegree/tools/rendering/manager/ModelGeneralizor.java 214
org/deegree/tools/rendering/manager/PrototypeAssigner.java 235
    }

    /**
     * @param optionValue
     * @return
     */
    private static double[] createTranslationVector( String optionValue, int size ) {
        double[] result = new double[size];
        if ( optionValue != null && !"".equals( optionValue ) ) {
            try {
                result = ArrayUtils.splitAsDoubles( optionValue, "," );
                if ( result.length != size ) {
                    throw new NumberFormatException(
                                                     "Illigal number of values, only two dimensional translations are allowed" );
                }
            } catch ( NumberFormatException e ) {
                System.err.println( "Translation vector "
                                    + optionValue
                                    + " could not be read, please make sure it is a comma seperated list of (floating point) numbers: "
                                    + e.getLocalizedMessage() );
            }
        }
        return result;
    }

    private static Options initOptions() {
        Options options = new Options();

        Option option = new Option( "type", TYPE, true, "the type of object to assign a prototype to (building)" );
        option.setArgs( 1 );
        option.setArgName( "building" );
        option.setRequired( true );
        options.addOption( option );

        option = new Option( "ql", TARGET_QL, true,
File Line
org/deegree/tools/crs/georeferencing/application/listeners/ButtonListener.java 293
org/deegree/tools/crs/georeferencing/application/listeners/ButtonListener.java 350
            } else if ( ( (JMenuItem) source ).getText().startsWith( get( "MENUITEM_SAVE_BUILDING" ) ) ) {
                List<String> list = new ArrayList<String>();
                list.add( "gml" );
                list.add( "xml" );
                String desc = "(*.gml, *.xml) GML or CityGML-Files";
                Pair<List<String>, String> supportedFiles = new Pair<List<String>, String>( list, desc );
                List<Pair<List<String>, String>> supportedOpenFiles = new ArrayList<Pair<List<String>, String>>();
                supportedOpenFiles.add( supportedFiles );
                FileChooser fileChooser = new FileChooser( supportedOpenFiles,
                                                           this.state.conModel.getView().getParent(), true );
                this.state.chosenFile = fileChooser.getOpenPath();
File Line
org/deegree/tools/crs/georeferencing/application/ApplicationState.java 243
org/deegree/tools/crs/georeferencing/application/ApplicationState.java 312
    public void initFootprintScene( String filePath ) {
        this.isInitFoot = true;
        if ( this.isInitGeoref ) {
            this.tablePanel.getSaveButton().setEnabled( true );
            this.tablePanel.getLoadButton().setEnabled( true );
        }

        this.footPrint = new Footprint( this.sceneValues, this.geom );
        Controller.removeListeners( this.conModel.getFootPanel() );
        this.conModel.getFootPanel().addScene2DMouseListener( new FootprintMouseListener( this ) );
        this.conModel.getFootPanel().addScene2DMouseMotionListener( new Scene2DMouseMotionListener( this ) );
        this.conModel.getFootPanel().addScene2DMouseWheelListener( new Scene2DMouseWheelListener( this ) );

        this.mouseFootprint = new FootprintMouseModel();
File Line
org/deegree/tools/crs/georeferencing/communication/FileChooser.java 96
org/deegree/tools/rendering/viewer/GLViewer.java 273
        if ( !lastFile.exists() && !lastFile.getParentFile().exists() ) {
            lastFile = new File( System.getProperty( "user.home" ) );
        }
        JFileChooser fileChooser = new JFileChooser( lastFile );
        fileChooser.setMultiSelectionEnabled( false );
        if ( fileFilter != null && fileFilter.size() > 0 ) {
            // the *.* file filter is off
            fileChooser.setAcceptAllFileFilterUsed( false );
            String lastExtension = prefs.get( LAST_EXTENSION, "*" );
            FileFilter selected = fileFilter.get( 0 );
            for ( ViewerFileFilter filter : fileFilter ) {
                fileChooser.setFileFilter( filter );
                if ( filter.accepts( lastExtension ) ) {
                    selected = filter;
                }
            }

            fileChooser.setFileFilter( selected );
        }
        return fileChooser;
    }

    /**
     * 
     * @return the selected file path, could be <Code>null</Code>.
     */
    public String getOpenPath() {
File Line
org/deegree/tools/rendering/manager/ModelGeneralizor.java 94
org/deegree/tools/rendering/manager/PrototypeAssigner.java 107
    private static DeegreeWorkspace workspace;

    /**
     * Creates the commandline parser and adds the options.
     * 
     * @param args
     */
    public static void main( String[] args ) {
        CommandLineParser parser = new PosixParser();

        Options options = initOptions();
        boolean verbose = false;

        // for the moment, using the CLI API there is no way to respond to a help argument; see
        // https://issues.apache.org/jira/browse/CLI-179
        if ( args.length == 0 || ( args.length > 0 && ( args[0].contains( "help" ) || args[0].contains( "?" ) ) ) ) {
            printHelp( options );
        }

        workspace = DeegreeWorkspace.getInstance();

        try {
            CommandLine line = parser.parse( options, args );
            verbose = line.hasOption( OPT_VERBOSE );
File Line
org/deegree/tools/rendering/manager/DataManager.java 188
org/deegree/tools/rendering/manager/ModelGeneralizor.java 94
org/deegree/tools/rendering/manager/PrototypeAssigner.java 107
    private static DeegreeWorkspace workspace;

    /**
     * Creates the commandline parser and adds the options.
     * 
     * @param args
     */
    public static void main( String[] args ) {
        CommandLineParser parser = new PosixParser();

        Options options = initOptions();
        boolean verbose = false;

        // for the moment, using the CLI API there is no way to respond to a
        // help argument; see
        // https://issues.apache.org/jira/browse/CLI-179
        if ( args.length == 0 || ( args.length > 0 && ( args[0].contains( "help" ) || args[0].contains( "?" ) ) ) ) {
            printHelp( options );
        }

        workspace = DeegreeWorkspace.getInstance();

        try {
            CommandLine line = parser.parse( options, args );
            verbose = line.hasOption( CommandUtils.OPT_VERBOSE );