}
@Override
- public Persister instantiate(PropertiesProvider propertiesProvider) {
+ public Persister instantiate(final PropertiesProvider propertiesProvider) {
if(instance != null) {
return instance;
}
if (!result) {
throw new RuntimeException("Unable to create storage file " + localStorage);
}
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new RuntimeException("Unable to create storage file " + localStorage, e);
}
}
}
@VisibleForTesting
- public void setFileStorage(File storage) {
+ public void setFileStorage(final File storage) {
this.storage = storage;
}
@VisibleForTesting
- public void setNumberOfBackups(Integer numberOfBackups) {
+ public void setNumberOfBackups(final Integer numberOfBackups) {
numberOfStoredBackups = numberOfBackups;
}
- private static File extractStorageFileFromProperties(PropertiesProvider propertiesProvider) {
+ private static File extractStorageFileFromProperties(final PropertiesProvider propertiesProvider) {
String fileStorageProperty = propertiesProvider.getProperty(FILE_STORAGE_PROP);
Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + propertiesProvider.getFullKeyForReporting(FILE_STORAGE_PROP));
File result = new File(fileStorageProperty);
}
@Override
- public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+ public void persistConfig(final ConfigSnapshotHolder holder) throws IOException {
Preconditions.checkNotNull(storage, "Storage file is null");
Set<String> installedFeatureIds = Collections.emptySet();
private List<ConfigSnapshot> snapshots;
- Config(List<ConfigSnapshot> snapshots) {
+ Config(final List<ConfigSnapshot> snapshots) {
this.snapshots = snapshots;
}
return snapshots;
}
- public void setSnapshots(List<ConfigSnapshot> snapshots) {
+ public void setSnapshots(final List<ConfigSnapshot> snapshots) {
this.snapshots = snapshots;
}
- public void toXml(File to) {
+ public void toXml(final File to) {
try {
// TODO Moxy has to be used instead of default jaxb impl due to a bug
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(this, to);
- } catch (JAXBException e) {
+ } catch (final JAXBException e) {
throw new PersistException("Unable to persist configuration", e);
}
}
- public static Config fromXml(File from) {
+ public static Config fromXml(final File from) {
if(isEmpty(from)) {
return new Config();
}
}
}
- private static boolean isEmpty(File from) {
+ private static boolean isEmpty(final File from) {
return from.length() == 0 || isBlank(from);
}
- private static boolean isBlank(File from) {
+ private static boolean isBlank(final File from) {
try {
return StringUtils.isBlank(Files.toString(from, StandardCharsets.UTF_8));
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new IllegalStateException("Unexpected error reading file" + from, e);
}
}
return last == null ? Optional.<ConfigSnapshot>absent() : Optional.of(last);
}
- public void addConfigSnapshot(ConfigSnapshot snap, int numberOfStoredBackups) {
+ public void addConfigSnapshot(final ConfigSnapshot snap, final int numberOfStoredBackups) {
if (shouldReplaceLast(numberOfStoredBackups) && !snapshots.isEmpty()) {
snapshots.remove(0);
}
snapshots.add(snap);
}
- private boolean shouldReplaceLast(int numberOfStoredBackups) {
+ private boolean shouldReplaceLast(final int numberOfStoredBackups) {
return numberOfStoredBackups == snapshots.size();
}
}
private SortedSet<String> capabilities = new TreeSet<>();
private Set<String> features = new HashSet<>();
- ConfigSnapshot(String configXml, SortedSet<String> capabilities) {
+ ConfigSnapshot(final String configXml, final SortedSet<String> capabilities) {
this.configXml = configXml;
this.capabilities = capabilities;
}
- ConfigSnapshot(String configXml, SortedSet<String> capabilities, Set<String> features) {
+ ConfigSnapshot(final String configXml, final SortedSet<String> capabilities, final Set<String> features) {
this.configXml = configXml;
this.capabilities = capabilities;
this.features = features;
ConfigSnapshot() {
}
- public static ConfigSnapshot fromConfigSnapshot(ConfigSnapshotHolder cfg) {
+ public static ConfigSnapshot fromConfigSnapshot(final ConfigSnapshotHolder cfg) {
return new ConfigSnapshot(cfg.getConfigSnapshot(), cfg.getCapabilities());
}
- public static ConfigSnapshot fromConfigSnapshot(ConfigSnapshotHolder cfg, Set<String> features) {
+ public static ConfigSnapshot fromConfigSnapshot(final ConfigSnapshotHolder cfg, final Set<String> features) {
return new ConfigSnapshot(cfg.getConfigSnapshot(), cfg.getCapabilities(), features);
}
return configXml;
}
- public void setConfigSnapshot(String configSnapshot) {
+ public void setConfigSnapshot(final String configSnapshot) {
this.configXml = configSnapshot;
}
return capabilities;
}
- public void setCapabilities(SortedSet<String> capabilities) {
+ public void setCapabilities(final SortedSet<String> capabilities) {
this.capabilities = capabilities;
}
final class PersistException extends RuntimeException {
private static final long serialVersionUID = 1L;
- public PersistException(String s, Exception e) {
+ public PersistException(final String s, final Exception e) {
super(s, e);
}
}
private StringWriter xmlWriter = new StringWriter();
@Override
- public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) {
+ public StreamResult createUnmarshaller(final ValidationEventHandler errorHandler) {
xmlWriter.getBuffer().setLength(0);
return new StreamResult(xmlWriter);
}
@Override
- public String getElement(StreamResult rt) {
+ public String getElement(final StreamResult rt) {
String xml = rt.getWriter().toString();
int beginIndex = xml.indexOf(START_TAG) + START_TAG.length();
int endIndex = xml.indexOf(END_TAG);
}
@Override
- public Source marshal(String n, ValidationEventHandler errorHandler) {
+ public Source marshal(final String n, final ValidationEventHandler errorHandler) {
try {
String xml = START_TAG + n.trim() + END_TAG;
StringReader xmlReader = new StringReader(xml);
return new StreamSource(xmlReader);
- } catch(Exception e) {
+ } catch(final Exception e) {
throw new RuntimeException(e);
}
}
final class StringTrimAdapter extends XmlAdapter<String, String> {
@Override
- public String unmarshal(String v) throws Exception {
+ public String unmarshal(final String v) throws Exception {
if (v == null) {
return null;
}
}
@Override
- public String marshal(String v) throws Exception {
+ public String marshal(final String v) throws Exception {
if (v == null) {
return null;
}