Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.appbasics.object;
 
 
 
Abstract base implementation of IObject that handles everything except com.helger.commons.type.IHasType.getTypeID(), java.lang.Object.equals(java.lang.Object) and java.lang.Object.hashCode().

Author(s):
Philip Helger
 
 public abstract class AbstractBaseObject implements IObject
 {
   private final String m_sID;
   private final DateTime m_aCreationDT;
   private final String m_sCreationUserID;
   private DateTime m_aDeletionDT;
   private String m_sDeletionUserID;
 
   public AbstractBaseObject (@Nonnull final IObject aObject)
   {
     this (aObject.getID (),
           aObject.getCreationDateTime (),
           aObject.getCreationUserID (),
           aObject.getLastModificationDateTime (),
           aObject.getLastModificationUserID (),
           aObject.getDeletionDateTime (),
           aObject.getDeletionUserID ());
   }
 
   public AbstractBaseObject (@Nonnull @Nonempty final String sID,
                              @Nullable final DateTime aCreationDT,
                              @Nullable final String sCreationUserID,
                              @Nullable final DateTime aLastModificationDT,
                              @Nullable final String sLastModificationUserID,
                              @Nullable final DateTime aDeletionDT,
                              @Nullable final String sDeletionUserID)
   {
      = ValueEnforcer.notEmpty (sID"ID");
      = aCreationDT;
      = sCreationUserID;
      = aLastModificationDT;
      = sLastModificationUserID;
      = aDeletionDT;
      = sDeletionUserID;
   }
 
   @Nonnull
   @Nonempty
   public final String getID ()
   {
     return ;
   }
 
   @Nullable
   public final DateTime getCreationDateTime ()
   {
     return ;
   }
 
   @Nullable
   public final String getCreationUserID ()
   {
     return ;
   }
 
   @Nullable
   public final DateTime getLastModificationDateTime ()
  {
    return ;
  }
  public final String getLastModificationUserID ()
  {
  }
  public final void setLastModificationNow ()
  {
    setLastModification (PDTFactory.getCurrentDateTime (), LoggedInUserManager.getInstance ().getCurrentUserID ());
  }
  public final void setLastModification (@Nonnull final DateTime aLastModificationDT,
                                         @Nonnull @Nonempty final String sLastModificationUserID)
  {
    ValueEnforcer.notNull (aLastModificationDT"LastModificationDT");
    ValueEnforcer.notEmpty (sLastModificationUserID"LastModificationUserID");
    if (isDeleted ())
      throw new IllegalStateException ("Object is deleted and can therefore not be modified!");
     = aLastModificationDT;
     = sLastModificationUserID;
  }
  public final DateTime getDeletionDateTime ()
  {
    return ;
  }
  public final String getDeletionUserID ()
  {
    return ;
  }
  public final EChange setDeletionNow ()
  {
    return setDeletion (PDTFactory.getCurrentDateTime (), LoggedInUserManager.getInstance ().getCurrentUserID ());
  }
  public final EChange setDeletion (@Nonnull final DateTime aDeletionDT, @Nonnull @Nonempty final String sDeletionUserID)
  {
    ValueEnforcer.notNull (aDeletionDT"DeletionDT");
    ValueEnforcer.notEmpty (sDeletionUserID"DeletionUserID");
    if ( != null)
    {
      // Object is already deleted...
      return .;
    }
     = aDeletionDT;
     = sDeletionUserID;
    return .;
  }
  public final EChange setUndeletionNow ()
  {
    return setUndeletion (PDTFactory.getCurrentDateTime (), LoggedInUserManager.getInstance ().getCurrentUserID ());
  }
  public final EChange setUndeletion (@Nonnull final DateTime aUndeletionDT,
                                      @Nonnull @Nonempty final String sUndeletionUserID)
  {
    ValueEnforcer.notNull (aUndeletionDT"UndeletionDT");
    ValueEnforcer.notEmpty (sUndeletionUserID"UndeletionUserID");
    if ( == null)
    {
      // Object is not deleted and can therefore not be undeleted
      return .;
    }
    setLastModification (aUndeletionDTsUndeletionUserID);
     = null;
     = null;
    return .;
  }
  public final boolean isDeleted ()
  {
    return  != null;
  }
  public final boolean isDeleted (@Nonnull final DateTime aDT)
  {
    ValueEnforcer.notNull (aDT"DateTime");
    return  != null && PDTUtils.isLessOrEqual (aDT);
  }
  public final boolean isDeleted (@Nonnull final LocalDateTime aDT)
  {
    ValueEnforcer.notNull (aDT"DateTime");
    return isDeleted (PDTFactory.createDateTime (aDT));
  }
  public String toString ()
  {
    return new ToStringGenerator (this).append ("ID")
                                       .appendIfNotNull ("creationDT")
                                       .appendIfNotNull ("creationUserID")
                                       .appendIfNotNull ("lastModificationDT")
                                       .appendIfNotNull ("lastModificationUserID")
                                       .appendIfNotNull ("deletionDT")
                                       .appendIfNotNull ("deletionUserID")
                                       .toString ();
  }
New to GrepCode? Check out our FAQ X