Skip to main content
formatting
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Your program will first take the name of the package the files are moved to (eg. com.google.raycasting), after that each file with <FILENAME>****<FILENAME>**** between them. You read the input however you want (STDIN, program arguments, file, etc.).

com.loovjo.tetris
****Vector.java****
package com.loovjo.someoldproject;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}
****Logger.java****
package com.loovjo.someoldproject;
class Logger {
    public String name;
    public Logger(String name) {
        this.name = name;
    }
}

com.loovjo.tetris *Vector.java package com.loovjo.someoldproject; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.someoldproject; class Logger { public String name; public Logger(String name) { this.name = name; } } (Of course these aren't the real files.)

Vector.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } }

****Vector.java****
package com.loovjo.tetris;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}
****Logger.java****
package com.loovjo.tetris;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}

Your program will first take the name of the package the files are moved to (eg. com.google.raycasting), after that each file with <FILENAME> between them. You read the input however you want (STDIN, program arguments, file, etc.).

com.loovjo.tetris *Vector.java package com.loovjo.someoldproject; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.someoldproject; class Logger { public String name; public Logger(String name) { this.name = name; } } (Of course these aren't the real files.)

Vector.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } }

Your program will first take the name of the package the files are moved to (eg. com.google.raycasting), after that each file with ****<FILENAME>**** between them. You read the input however you want (STDIN, program arguments, file, etc.).

com.loovjo.tetris
****Vector.java****
package com.loovjo.someoldproject;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}
****Logger.java****
package com.loovjo.someoldproject;
class Logger {
    public String name;
    public Logger(String name) {
        this.name = name;
    }
}

(Of course these aren't the real files.)

****Vector.java****
package com.loovjo.tetris;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}
****Logger.java****
package com.loovjo.tetris;
class Vector {
    public Vector (int x, int y) {
        System.out.println(x + ", " + y);
    }
}
Source Link
xenia
  • 8.2k
  • 2
  • 28
  • 59

Java Package Correction

I have a lot of java projects and I am often making new ones. I have a few helper classes (Vector, Logger, etc.) and it takes a lot of time correcting the first line to the correct package, I would really need a little program to help me fix it automatically.

Your program will first take the name of the package the files are moved to (eg. com.google.raycasting), after that each file with <FILENAME> between them. You read the input however you want (STDIN, program arguments, file, etc.).

When an EOF is reached, the program should output each file in the same way as in the input, but with the package declaration changed.

Example:

Input:

com.loovjo.tetris *Vector.java package com.loovjo.someoldproject; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.someoldproject; class Logger { public String name; public Logger(String name) { this.name = name; } } (Of course these aren't the real files.)

Output:

Vector.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } } Logger.java package com.loovjo.tetris; class Vector { public Vector (int x, int y) { System.out.println(x + ", " + y); } }

Further specification on Input/Output:

  • The package declaration will not always be on the first line, the input may contain some newlines/spaces before it. If this is the case, those characters must be there in the output.
  • The files in the input will always have correct syntax.

Remember, this is Code Golf, so the shortest code wins!