You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/06/01 05:47:00 UTC

[jira] [Work logged] (LANG-1490) Create a more generic/string representation of a DiffResult and a Diff

     [ https://issues.apache.org/jira/browse/LANG-1490?focusedWorklogId=439349&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-439349 ]

ASF GitHub Bot logged work on LANG-1490:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Jun/20 05:46
            Start Date: 01/Jun/20 05:46
    Worklog Time Spent: 10m 
      Work Description: kinow commented on a change in pull request #457:
URL: https://github.com/apache/commons-lang/pull/457#discussion_r433050850



##########
File path: src/main/java/org/apache/commons/lang3/builder/DiffView.java
##########
@@ -0,0 +1,64 @@
+package org.apache.commons.lang3.builder;

Review comment:
       I think this file is missing the copyright license header.

##########
File path: src/main/java/org/apache/commons/lang3/builder/DiffView.java
##########
@@ -0,0 +1,64 @@
+package org.apache.commons.lang3.builder;
+
+/**
+ * <p>A {@code DiffView} object holds the string representation of the difference of
+ * a given field between two objects.</p>
+ *
+ * @since 3.10
+ */
+public class DiffView {
+	private final String field;
+	private final String leftValue;
+	private final String rightValue;
+
+	/**
+	 * <p>Constructs a {@code DiffView} from 3 string params: field, leftValue and rightValue</p>
+	 *
+	 * @param field designates the field identified as different.
+	 * @param leftValue holds the string representation of the value in the left side of the comparison.
+	 * @param rightValue holds the string representation of the value in the right side of the comparison.
+	 */
+	public DiffView(String field, String leftValue, String rightValue) {
+		this.field = field;

Review comment:
       I think the files were formatted with tabs, and this may cause issues in Travis when it builds using Checkstyle.

##########
File path: src/main/java/org/apache/commons/lang3/builder/DiffResultView.java
##########
@@ -0,0 +1,157 @@
+package org.apache.commons.lang3.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * A {@code DiffResultView} encapsulates two objects of the same type and list their differences
+ * as a list of {@link DiffView} objects, each holding a field name and the two different values found for this field
+ * in the Left and Right object.
+ * </p>
+ *
+ * <p>
+ * It can be built with or without a pre-defined list of {@link DiffView} objects, or from an existing
+ * {@link DiffResult}.
+ * </p>
+ *
+ * @param <T> type of the left and right object.
+ *
+ * @since 3.10
+ */
+public class DiffResultView<T> {
+
+	/**
+	 * The list of {@link DiffView} objects for the two compared objects.
+	 */
+	private List<DiffView> diffs;
+
+	/**
+	 * Holds the left object of the comparison.
+	 */
+	private T left;
+	/**
+	 * Holds the right object of the comparison.
+	 */
+	private T right;
+
+	/**
+	 * <p>Creates a simple {@code DiffResultView} without predefined list of {@link DiffView}.
+	 * The list will be initialized as an empty @{link ArrayList}.</p>
+	 *
+	 * @param o1 left object of the comparison
+	 * @param o2 right object of the comparison
+	 */
+	public DiffResultView(T o1, T o2) {
+		this.left = o1;
+		this.right = o2;
+		this.diffs = new ArrayList<>();
+	}
+
+	/**
+	 * <p>Creates a simple {@code DiffResultView} with a predefined list of {@link DiffView}.</p>
+	 *
+	 * @param o1 left object of the comparison.
+	 * @param o2 right object of the comparison.
+	 * @param diffs list of {@link DiffView} objects.
+	 */
+	public DiffResultView(T o1, T o2, List<DiffView> diffs) {
+		this(o1, o2);
+		this.diffs = diffs;
+	}
+
+	/**
+	 * <p>Creates a simple {@code DiffResultView} from a {@link DiffResult} object.</p>
+	 * <p>{@link DiffView} objects will be constructed from {@link DiffResult} {@link Diff} objects and
+	 * added to the diffs list</p>
+	 *
+	 * @param diffResult {@link DiffResult} object used to initialize the {@code DiffResultView}
+	 */
+	public DiffResultView(DiffResult<T> diffResult) {
+		this(diffResult.getLeft(), diffResult.getRight());
+		this.addDiffs(diffResult);
+	}
+
+	/**
+	 * <p>Returns the list of the {@link DiffView} objects</p>
+	 * @return the list of the {@link DiffView} objects
+	 */
+	public List<DiffView> getDiffs() {
+		return diffs;
+	}
+
+	/**
+	 * <p>Returns only a list of the fields of all {@link DiffView} objects, that is, fields that have been detected
+	 * as changed between the objects.</p>
+	 *
+	 * @return the list of the {@link DiffView} objects
+	 */
+	public List<String> getDiffFields() {
+		return diffs.stream().map(DiffView::getField).collect(Collectors.toList());
+	}
+
+	/**
+	 * <p>Adds one {@link DiffView} to the list of the diffs between the two objects.</p>
+	 *
+	 * @param diffView the {@link DiffView} object to be added to the diffs list.
+	 */
+	public void addDiff(DiffView diffView) {
+		diffs.add(diffView);
+	}
+
+	/**
+	 * <p>Builds a {@link DiffView} from a {@link Diff} object and adds it to the diffs list.</p>
+	 *
+	 * @param diff the {@link Diff} object from which the {@link DiffView} object will be built and added to the list.
+	 */
+	public void addDiff(Diff<?> diff) {
+		diffs.add(new DiffView(diff));
+	}
+
+	/**
+	 * <p>Builds a {@link DiffView} from each {@link Diff} object of the {@link DiffResult}
+	 * and adds them to the diffs list.</p>
+	 *
+	 * @param diffResult the {@link DiffResult} object from which the {@link DiffView} objects
+	 *                      will be built and added to the list.
+	 */
+	public void addDiffs(DiffResult<?> diffResult) {
+		diffs.addAll(
+				diffResult
+						.getDiffs()
+						.stream()
+						.map(DiffView::new)
+						.collect(Collectors.toList())
+		);

Review comment:
       Probably will fail checkstyle due to tabs here, instead of spaces.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 439349)
    Time Spent: 1h 10m  (was: 1h)

> Create a more generic/string representation of a DiffResult and a Diff
> ----------------------------------------------------------------------
>
>                 Key: LANG-1490
>                 URL: https://issues.apache.org/jira/browse/LANG-1490
>             Project: Commons Lang
>          Issue Type: Wish
>            Reporter: Nicolas BARTHE-DEJEAN
>            Priority: Major
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Currently, a DiffResult and a Diff can only handle the differences of two objects of the same type A, and we cannot set custom differences for a DiffResult<A> if encapsulated objects of type B are different.
> I suggest to implement a `DiffView class` as a simple `String field`, `String leftValue` and `String rightValue` triplet.
> I also wrote a `DiffResultView` class holding two objects of type `T` and a list of `DiffView` objects.
> https://issues.apache.org/jira/browse/LANG-1490



--
This message was sent by Atlassian Jira
(v8.3.4#803005)