class FileSystem {

	@Pure
	public static File replaceExtension(File filename, String extension) {
		if (filename == null) {
			return null;
		}
		if (extension == null) {
			return filename;
		}
		final File dir = filename.getParentFile();
		final String name = filename.getName();
		final int idx = name.lastIndexOf(getFileExtensionCharacter());
		final StringBuilder n = new StringBuilder();
		if (idx < 0) {
			n.append(name);
		} else {
			n.append(name.substring(0, idx));
		}
		if (!name.endsWith(EXTENSION_SEPARATOR) && !extension.startsWith(EXTENSION_SEPARATOR)) {
			n.append(EXTENSION_SEPARATOR);
		}
		n.append(extension);
		return new File(dir, n.toString());
	}

	private  FileSystem();

}