Skip to content

Commit

Permalink
DocumentQueryOrderBy.copyOverridingFieldName; refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 3, 2017
1 parent 6a5773e commit 697a010
Showing 1 changed file with 7 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package de.metas.ui.web.window.model;

import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;

import javax.annotation.concurrent.Immutable;

import org.adempiere.util.Check;
import org.adempiere.util.GuavaCollectors;

import com.google.common.base.MoreObjects;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;

import lombok.NonNull;
import lombok.Value;

/*
* #%L
Expand All @@ -40,9 +36,8 @@
* #L%
*/

@Immutable
@SuppressWarnings("serial")
public final class DocumentQueryOrderBy implements Serializable
@Value
public final class DocumentQueryOrderBy
{
public static final DocumentQueryOrderBy byFieldName(final String fieldName, final boolean ascending)
{
Expand Down Expand Up @@ -95,52 +90,18 @@ else if (orderByStr.charAt(0) == '-')

private DocumentQueryOrderBy(final String fieldName, final boolean ascending)
{
super();
Check.assumeNotEmpty(fieldName, "fieldName is not empty");
this.fieldName = fieldName;
this.ascending = ascending;
}

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

@Override
public int hashCode()
public DocumentQueryOrderBy copyOverridingFieldName(final String fieldName)
{
return Objects.hash(fieldName, ascending);
}

@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj instanceof DocumentQueryOrderBy)
if (Objects.equals(this.fieldName, fieldName))
{
final DocumentQueryOrderBy other = (DocumentQueryOrderBy)obj;
return Objects.equals(fieldName, other.fieldName)
&& ascending == other.ascending;
return this;
}
return false;
}

@NonNull
public String getFieldName()
{
return fieldName;
}

public boolean isAscending()
{
return ascending;
return new DocumentQueryOrderBy(fieldName, ascending);
}

public <T> Comparator<T> asComparator(final BiFunction<T, String, Object> fieldValueExtractor)
Expand Down

0 comments on commit 697a010

Please sign in to comment.