Skip to content

Commit

Permalink
replace boilerplate code with lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Sep 18, 2017
1 parent a1093cd commit 34c89cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package de.metas.ui.web.quickinput;

import java.util.Objects;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.google.common.base.MoreObjects;

import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentType;
import de.metas.ui.web.window.descriptor.DetailId;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;

/*
* #%L
Expand Down Expand Up @@ -50,7 +50,15 @@ public interface IQuickInputDescriptorFactory

QuickInputDescriptor createQuickInputEntityDescriptor(final DocumentType documentType, final DocumentId documentTypeId, final DetailId detailId);

//
//
// -------------------------------------------------------------------
//
//

/** Key used to identify the {@link IQuickInputDescriptorFactory} to be used */
@Value
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static final class MatchingKey
{
public static final MatchingKey includedDocument(final DocumentType documentType, final int documentTypeIdInt, final String tableName)
Expand All @@ -74,49 +82,5 @@ public static final MatchingKey ofTableName(final String tableName)
private final DocumentType documentType;
private final DocumentId documentTypeId;
private final String tableName;

private MatchingKey(final DocumentType documentType, final DocumentId documentTypeId, final String tableName)
{
this.documentType = documentType;
this.documentTypeId = documentTypeId;
this.tableName = tableName;
}

@Override
public String toString()
{
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("documentType", documentType)
.add("documentTypeId", documentTypeId)
.add("tableName", tableName)
.toString();
}

@Override
public int hashCode()
{
return Objects.hash(documentType, documentTypeId, tableName);
}

@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj instanceof MatchingKey)
{
final MatchingKey other = (MatchingKey)obj;
return Objects.equals(documentType, other.documentType)
&& Objects.equals(documentTypeId, other.documentTypeId)
&& Objects.equals(tableName, other.tableName);
}
else
{
return false;
}
}
}
}
48 changes: 6 additions & 42 deletions src/main/java/de/metas/ui/web/quickinput/QuickInputDescriptor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package de.metas.ui.web.quickinput;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Check;

import com.google.common.base.MoreObjects;

import de.metas.ui.web.window.descriptor.DetailId;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import lombok.NonNull;
import lombok.Value;

/*
* #%L
Expand All @@ -30,51 +29,16 @@
* #L%
*/

@Value(staticConstructor = "of")
public class QuickInputDescriptor
{
public static final QuickInputDescriptor of( //
final DocumentEntityDescriptor entityDescriptor //
, final QuickInputLayoutDescriptor layout //
, final Class<? extends IQuickInputProcessor> processorClass //
)
{
return new QuickInputDescriptor(entityDescriptor, layout, processorClass);
}

@NonNull
private final DocumentEntityDescriptor entityDescriptor;
@NonNull
private final QuickInputLayoutDescriptor layout;
@NonNull
private final Class<? extends IQuickInputProcessor> processorClass;

private QuickInputDescriptor(final DocumentEntityDescriptor entityDescriptor, final QuickInputLayoutDescriptor layout, final Class<? extends IQuickInputProcessor> processorClass)
{
Check.assumeNotNull(entityDescriptor, "Parameter entityDescriptor is not null");
Check.assumeNotNull(layout, "Parameter layout is not null");
Check.assumeNotNull(processorClass, "Parameter processorClass is not null");

this.entityDescriptor = entityDescriptor;
this.layout = layout;
this.processorClass = processorClass;
}

@Override
public String toString()
{
return MoreObjects.toStringHelper(this)
.add("processorClass", processorClass)
.add("entityDescriptor", entityDescriptor)
.toString();
}

public DocumentEntityDescriptor getEntityDescriptor()
{
return entityDescriptor;
}

public QuickInputLayoutDescriptor getLayout()
{
return layout;
}

public IQuickInputProcessor createProcessor()
{
try
Expand Down

0 comments on commit 34c89cd

Please sign in to comment.