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 ForgeRock AS.
016 */
017package org.opends.server.types;
018
019
020
021/**
022 * This class defines a data structure for providing information about
023 * the state of a completed LDIF import, including the total number of
024 * entries read, skipped, and rejected.
025 */
026@org.opends.server.types.PublicAPI(
027     stability=org.opends.server.types.StabilityLevel.VOLATILE,
028     mayInstantiate=false,
029     mayExtend=false,
030     mayInvoke=true)
031public final class LDIFImportResult
032{
033  /** The total number of entries read during the import. */
034  private final long entriesRead;
035
036  /** The total number of entries rejected during the import. */
037  private final long entriesRejected;
038
039  /** The total number of entries skipped during the import. */
040  private final long entriesSkipped;
041
042
043
044  /**
045   * Creates a new LDIF import result object with the provided
046   * information.
047   *
048   * @param  entriesRead      The total number of entries read
049   *                          during the import, including those that
050   *                          were later rejected or skipped.
051   * @param  entriesRejected  The total number of entries rejected
052   *                          during the import.
053   * @param  entriesSkipped   The total number of entries skipped
054   *                          during the import.
055   */
056  public LDIFImportResult(long entriesRead, long entriesRejected,
057                          long entriesSkipped)
058  {
059    this.entriesRead     = entriesRead;
060    this.entriesRejected = entriesRejected;
061    this.entriesSkipped  = entriesSkipped;
062  }
063
064
065
066  /**
067   * Retrieves the total number of entries read during the import,
068   * including those that were later rejected or skipped.
069   *
070   * @return  The total number of entries read during the import,
071   *          including those that were later rejected or skipped.
072   */
073  public long getEntriesRead()
074  {
075    return entriesRead;
076  }
077
078
079
080  /**
081   * Retrieves the total number of entries that were successfully
082   * imported.
083   *
084   * @return  The total number of entries that were successfully
085   *          imported.
086   */
087  public long getEntriesImported()
088  {
089    return entriesRead - entriesRejected - entriesSkipped;
090  }
091
092
093
094  /**
095   * Retrieves the total number of entries rejected during the import.
096   *
097   * @return  The total number of entries rejected during the import.
098   */
099  public long getEntriesRejected()
100  {
101    return entriesRejected;
102  }
103
104
105
106  /**
107   * Retrieves the total number of entries skipped during the import.
108   *
109   * @return  The total number of entries skipped during the import.
110   */
111  public long getEntriesSkipped()
112  {
113    return entriesSkipped;
114  }
115
116
117
118  /**
119   * Retrieves a string representation of this LDIF import result
120   * object.
121   *
122   * @return  A string representation of this LDIF import result
123   *          object.
124   */
125  public String toString()
126  {
127    StringBuilder buffer = new StringBuilder();
128    toString(buffer);
129    return buffer.toString();
130  }
131
132
133
134  /**
135   * Appends a string representation of this LDIF import result object
136   * to the provided buffer.
137   *
138   * @param  buffer  The buffer to which the information should be
139   *                 appended.
140   */
141  public void toString(StringBuilder buffer)
142  {
143    buffer.append("LDIFImportResult(entriesRead=");
144    buffer.append(entriesRead);
145    buffer.append(", entriesRejected=");
146    buffer.append(entriesRejected);
147    buffer.append(", entriesSkipped=");
148    buffer.append(entriesSkipped);
149    buffer.append(")");
150  }
151}
152