001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015-2016 ForgeRock AS.
016 */
017package org.opends.server.types;
018
019/**
020 * This class defines a data structure for providing information about
021 * the state of a completed LDIF import, including the total number of
022 * entries read, skipped, and rejected.
023 */
024@org.opends.server.types.PublicAPI(
025     stability=org.opends.server.types.StabilityLevel.VOLATILE,
026     mayInstantiate=false,
027     mayExtend=false,
028     mayInvoke=true)
029public final class LDIFImportResult
030{
031  /** The total number of entries read during the import. */
032  private final long entriesRead;
033  /** The total number of entries rejected during the import. */
034  private final long entriesRejected;
035  /** The total number of entries skipped during the import. */
036  private final long entriesSkipped;
037
038
039
040  /**
041   * Creates a new LDIF import result object with the provided
042   * information.
043   *
044   * @param  entriesRead      The total number of entries read
045   *                          during the import, including those that
046   *                          were later rejected or skipped.
047   * @param  entriesRejected  The total number of entries rejected
048   *                          during the import.
049   * @param  entriesSkipped   The total number of entries skipped
050   *                          during the import.
051   */
052  public LDIFImportResult(long entriesRead, long entriesRejected,
053                          long entriesSkipped)
054  {
055    this.entriesRead     = entriesRead;
056    this.entriesRejected = entriesRejected;
057    this.entriesSkipped  = entriesSkipped;
058  }
059
060
061
062  /**
063   * Retrieves the total number of entries read during the import,
064   * including those that were later rejected or skipped.
065   *
066   * @return  The total number of entries read during the import,
067   *          including those that were later rejected or skipped.
068   */
069  public long getEntriesRead()
070  {
071    return entriesRead;
072  }
073
074
075
076  /**
077   * Retrieves the total number of entries that were successfully
078   * imported.
079   *
080   * @return  The total number of entries that were successfully
081   *          imported.
082   */
083  public long getEntriesImported()
084  {
085    return entriesRead - entriesRejected - entriesSkipped;
086  }
087
088
089
090  /**
091   * Retrieves the total number of entries rejected during the import.
092   *
093   * @return  The total number of entries rejected during the import.
094   */
095  public long getEntriesRejected()
096  {
097    return entriesRejected;
098  }
099
100
101
102  /**
103   * Retrieves the total number of entries skipped during the import.
104   *
105   * @return  The total number of entries skipped during the import.
106   */
107  public long getEntriesSkipped()
108  {
109    return entriesSkipped;
110  }
111
112
113
114  /**
115   * Retrieves a string representation of this LDIF import result
116   * object.
117   *
118   * @return  A string representation of this LDIF import result
119   *          object.
120   */
121  @Override
122  public String toString()
123  {
124    StringBuilder buffer = new StringBuilder();
125    toString(buffer);
126    return buffer.toString();
127  }
128
129
130
131  /**
132   * Appends a string representation of this LDIF import result object
133   * to the provided buffer.
134   *
135   * @param  buffer  The buffer to which the information should be
136   *                 appended.
137   */
138  private void toString(StringBuilder buffer)
139  {
140    buffer.append("LDIFImportResult(entriesRead=");
141    buffer.append(entriesRead);
142    buffer.append(", entriesRejected=");
143    buffer.append(entriesRejected);
144    buffer.append(", entriesSkipped=");
145    buffer.append(entriesSkipped);
146    buffer.append(")");
147  }
148}