From 310df200f78f7d98cc52e4ab97d8a5feb744fa52 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 28 Apr 2016 09:04:35 +0000
Subject: [PATCH] UCDetector and AutoRefactor code cleanup
---
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java | 110 ++++++++++++++++++------------------------------------
1 files changed, 37 insertions(+), 73 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
index bb47ed2..30a1047 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -75,49 +75,38 @@
/** The reader that will be used to read the data. */
private BufferedReader reader;
-
/** The import configuration that specifies what should be imported. */
- protected LDIFImportConfig importConfig;
+ protected final LDIFImportConfig importConfig;
/** The lines that comprise the body of the last entry read. */
protected List<StringBuilder> lastEntryBodyLines;
-
- /**
- * The lines that comprise the header (DN and any comments) for the last entry
- * read.
- */
+ /** The lines that comprise the header (DN and any comments) for the last entry read. */
protected List<StringBuilder> lastEntryHeaderLines;
-
/**
* The number of entries that have been ignored by this LDIF reader because
* they didn't match the criteria.
*/
private final AtomicLong entriesIgnored = new AtomicLong();
-
/**
* The number of entries that have been read by this LDIF reader, including
* those that were ignored because they didn't match the criteria, and
* including those that were rejected because they were invalid in some way.
*/
protected final AtomicLong entriesRead = new AtomicLong();
-
/** The number of entries that have been rejected by this LDIF reader. */
private final AtomicLong entriesRejected = new AtomicLong();
/** The line number on which the last entry started. */
protected long lastEntryLineNumber = -1;
-
- /**
- * The line number of the last line read from the LDIF file, starting with 1.
- */
+ /** The line number of the last line read from the LDIF file, starting with 1. */
private long lineNumber;
/**
* The plugin config manager that will be used if we are to invoke plugins on
* the entries as they are read.
*/
- protected PluginConfigManager pluginConfigManager;
+ protected final PluginConfigManager pluginConfigManager;
/**
* Creates a new LDIF reader that will read information from the specified
@@ -265,6 +254,7 @@
logToSkipWriter(lines, ERR_LDIF_SKIP.get(entryDN));
return false;
}
+ return true;
}
catch (Exception e)
{
@@ -274,7 +264,6 @@
ERR_LDIF_COULD_NOT_EVALUATE_FILTERS_FOR_IMPORT.get(entry.getName(), lastEntryLineNumber, e);
throw new LDIFException(message, lastEntryLineNumber, true, e);
}
- return true;
}
private boolean invokeImportPlugins(Entry entry, LinkedList<StringBuilder> lines)
@@ -286,16 +275,10 @@
if (!pluginResult.continueProcessing())
{
final DN entryDN = entry.getName();
- LocalizableMessage m;
LocalizableMessage rejectMessage = pluginResult.getErrorMessage();
- if (rejectMessage == null)
- {
- m = ERR_LDIF_REJECTED_BY_PLUGIN_NOMESSAGE.get(entryDN);
- }
- else
- {
- m = ERR_LDIF_REJECTED_BY_PLUGIN.get(entryDN, rejectMessage);
- }
+ LocalizableMessage m = rejectMessage != null
+ ? ERR_LDIF_REJECTED_BY_PLUGIN.get(entryDN, rejectMessage)
+ : ERR_LDIF_REJECTED_BY_PLUGIN_NOMESSAGE.get(entryDN);
logToRejectWriter(lines, m);
return false;
@@ -348,7 +331,7 @@
* @param builders the list of AttributeBuilders
* @return a new list of Attributes
*/
- protected List<Attribute> toAttributesList(List<AttributeBuilder> builders)
+ private List<Attribute> toAttributesList(List<AttributeBuilder> builders)
{
List<Attribute> results = new ArrayList<>(builders.size());
for (AttributeBuilder builder : builders)
@@ -397,47 +380,37 @@
}
String changeType = readChangeType(lines);
-
- ChangeRecordEntry entry;
-
if(changeType != null)
{
- if(changeType.equals("add"))
+ switch (changeType)
{
- entry = parseAddChangeRecordEntry(entryDN, lines);
- } else if (changeType.equals("delete"))
- {
- entry = parseDeleteChangeRecordEntry(entryDN, lines);
- } else if (changeType.equals("modify"))
- {
- entry = parseModifyChangeRecordEntry(entryDN, lines);
- } else if (changeType.equals("modrdn"))
- {
- entry = parseModifyDNChangeRecordEntry(entryDN, lines);
- } else if (changeType.equals("moddn"))
- {
- entry = parseModifyDNChangeRecordEntry(entryDN, lines);
- } else
- {
+ case "add":
+ return parseAddChangeRecordEntry(entryDN, lines);
+ case "delete":
+ return parseDeleteChangeRecordEntry(entryDN, lines);
+ case "modify":
+ return parseModifyChangeRecordEntry(entryDN, lines);
+ case "modrdn":
+ return parseModifyDNChangeRecordEntry(entryDN, lines);
+ case "moddn":
+ return parseModifyDNChangeRecordEntry(entryDN, lines);
+ default:
LocalizableMessage message = ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get(
changeType, "add, delete, modify, moddn, modrdn");
throw new LDIFException(message, lastEntryLineNumber, false);
}
- } else
- {
- // default to "add"?
- if(defaultAdd)
- {
- entry = parseAddChangeRecordEntry(entryDN, lines);
- } else
- {
- LocalizableMessage message = ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get(
- null, "add, delete, modify, moddn, modrdn");
- throw new LDIFException(message, lastEntryLineNumber, false);
- }
}
-
- return entry;
+ else if (defaultAdd)
+ {
+ // default to "add"
+ return parseAddChangeRecordEntry(entryDN, lines);
+ }
+ else
+ {
+ LocalizableMessage message =
+ ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get(null, "add, delete, modify, moddn, modrdn");
+ throw new LDIFException(message, lastEntryLineNumber, false);
+ }
}
}
@@ -455,15 +428,14 @@
*/
protected LinkedList<StringBuilder> readEntryLines() throws IOException, LDIFException
{
- // Read the entry lines into a buffer.
- LinkedList<StringBuilder> lines = new LinkedList<>();
- int lastLine = -1;
-
if(reader == null)
{
return null;
}
+ // Read the entry lines into a buffer.
+ LinkedList<StringBuilder> lines = new LinkedList<>();
+ int lastLine = -1;
while (true)
{
String line = reader.readLine();
@@ -479,11 +451,7 @@
break;
}
reader = importConfig.nextReader();
- if (reader != null)
- {
- return readEntryLines();
- }
- return null;
+ return reader != null ? readEntryLines() : null;
}
else if (line.length() == 0)
{
@@ -1034,11 +1002,7 @@
}
}
-
-
- /**
- * Closes this LDIF reader and the underlying file or input stream.
- */
+ /** Closes this LDIF reader and the underlying file or input stream. */
@Override
public void close()
{
--
Gitblit v1.10.0