mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Use more simple toString style
This commit is contained in:
@@ -23,6 +23,8 @@ import org.apache.commons.lang3.builder.*;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.*;
|
import javax.annotation.concurrent.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Checkmark represents the completion status of the habit for a given day.
|
* A Checkmark represents the completion status of the habit for a given day.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -108,7 +110,7 @@ public final class Checkmark
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("timestamp", timestamp)
|
.append("timestamp", timestamp)
|
||||||
.append("value", value)
|
.append("value", value)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.util.*;
|
|||||||
import javax.annotation.concurrent.*;
|
import javax.annotation.concurrent.*;
|
||||||
|
|
||||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The collection of {@link Checkmark}s belonging to a habit.
|
* The collection of {@link Checkmark}s belonging to a habit.
|
||||||
@@ -396,7 +397,7 @@ public abstract class CheckmarkList
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("begin", begin)
|
.append("begin", begin)
|
||||||
.append("center", center)
|
.append("center", center)
|
||||||
.append("end", end)
|
.append("end", end)
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import org.apache.commons.lang3.builder.*;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.*;
|
import javax.annotation.concurrent.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents how often is the habit repeated.
|
* Represents how often is the habit repeated.
|
||||||
*/
|
*/
|
||||||
@@ -92,7 +94,7 @@ public class Frequency
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("numerator", numerator)
|
.append("numerator", numerator)
|
||||||
.append("denominator", denominator)
|
.append("denominator", denominator)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import javax.annotation.concurrent.*;
|
|||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
|
||||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The thing that the user wants to track.
|
* The thing that the user wants to track.
|
||||||
@@ -414,7 +415,7 @@ public class Habit
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("name", name)
|
.append("name", name)
|
||||||
.append("description", description)
|
.append("description", description)
|
||||||
.append("frequency", frequency)
|
.append("frequency", frequency)
|
||||||
@@ -475,7 +476,7 @@ public class Habit
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("id", id)
|
.append("id", id)
|
||||||
.append("data", data)
|
.append("data", data)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import android.support.annotation.*;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.builder.*;
|
import org.apache.commons.lang3.builder.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
public final class Reminder
|
public final class Reminder
|
||||||
{
|
{
|
||||||
private final int hour;
|
private final int hour;
|
||||||
@@ -83,7 +85,7 @@ public final class Reminder
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("hour", hour)
|
.append("hour", hour)
|
||||||
.append("minute", minute)
|
.append("minute", minute)
|
||||||
.append("days", days)
|
.append("days", days)
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ package org.isoron.uhabits.core.models;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.builder.*;
|
import org.apache.commons.lang3.builder.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a record that the user has performed a certain habit at a certain
|
* Represents a record that the user has performed a certain habit at a certain
|
||||||
* date.
|
* date.
|
||||||
@@ -89,7 +91,7 @@ public final class Repetition
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("timestamp", timestamp)
|
.append("timestamp", timestamp)
|
||||||
.append("value", value)
|
.append("value", value)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.core.models;
|
|||||||
import org.apache.commons.lang3.builder.*;
|
import org.apache.commons.lang3.builder.*;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
import static java.lang.Math.*;
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents how strong a habit is at a certain date.
|
* Represents how strong a habit is at a certain date.
|
||||||
@@ -88,7 +89,7 @@ public final class Score
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("timestamp", timestamp)
|
.append("timestamp", timestamp)
|
||||||
.append("value", value)
|
.append("value", value)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ package org.isoron.uhabits.core.models;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.builder.*;
|
import org.apache.commons.lang3.builder.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
public final class Streak
|
public final class Streak
|
||||||
{
|
{
|
||||||
private final Timestamp start;
|
private final Timestamp start;
|
||||||
@@ -64,7 +66,7 @@ public final class Streak
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("start", start)
|
.append("start", start)
|
||||||
.append("end", end)
|
.append("end", end)
|
||||||
.toString();
|
.toString();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.apache.commons.lang3.builder.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static java.util.Calendar.DAY_OF_WEEK;
|
import static java.util.Calendar.DAY_OF_WEEK;
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
public final class Timestamp
|
public final class Timestamp
|
||||||
{
|
{
|
||||||
@@ -137,7 +138,7 @@ public final class Timestamp
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("unixTime", unixTime)
|
.append("unixTime", unixTime)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import org.apache.commons.lang3.builder.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
||||||
|
|
||||||
public final class WeekdayList
|
public final class WeekdayList
|
||||||
{
|
{
|
||||||
public static final WeekdayList EVERY_DAY = new WeekdayList(127);
|
public static final WeekdayList EVERY_DAY = new WeekdayList(127);
|
||||||
@@ -92,7 +94,7 @@ public final class WeekdayList
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this, defaultToStringStyle())
|
||||||
.append("weekdays", weekdays)
|
.append("weekdays", weekdays)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,35 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.core.utils;
|
package org.isoron.uhabits.core.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.*;
|
||||||
|
|
||||||
import java.math.*;
|
import java.math.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class StringUtils
|
public class StringUtils
|
||||||
{
|
{
|
||||||
|
private static StandardToStringStyle toStringStyle = null;
|
||||||
|
|
||||||
public static String getRandomId()
|
public static String getRandomId()
|
||||||
{
|
{
|
||||||
return new BigInteger(260, new Random()).toString(32).substring(0, 32);
|
return new BigInteger(260, new Random()).toString(32).substring(0, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removePointers(String original)
|
public static ToStringStyle defaultToStringStyle()
|
||||||
{
|
{
|
||||||
return original.replaceAll("@[0-9a-f]*", "@00000000");
|
if (toStringStyle == null)
|
||||||
|
{
|
||||||
|
toStringStyle = new StandardToStringStyle();
|
||||||
|
toStringStyle.setFieldSeparator(", ");
|
||||||
|
toStringStyle.setUseClassName(false);
|
||||||
|
toStringStyle.setUseIdentityHashCode(false);
|
||||||
|
toStringStyle.setContentStart("{");
|
||||||
|
toStringStyle.setContentEnd("}");
|
||||||
|
toStringStyle.setFieldNameValueSeparator(": ");
|
||||||
|
toStringStyle.setArrayStart("[");
|
||||||
|
toStringStyle.setArrayEnd("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
return toStringStyle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import nl.jqno.equalsverifier.*;
|
|||||||
import static org.hamcrest.MatcherAssert.*;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.core.IsEqual.*;
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
|
||||||
|
|
||||||
public class CheckmarkListTest extends BaseUnitTest
|
public class CheckmarkListTest extends BaseUnitTest
|
||||||
{
|
{
|
||||||
@@ -360,21 +359,14 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
Timestamp t = Timestamp.ZERO.plus(100);
|
Timestamp t = Timestamp.ZERO.plus(100);
|
||||||
Checkmark checkmark = new Checkmark(t, 2);
|
Checkmark checkmark = new Checkmark(t, 2);
|
||||||
String s = removePointers(checkmark.toString());
|
assertThat(checkmark.toString(),
|
||||||
assertThat(s, equalTo(
|
equalTo("{timestamp: {unixTime: 8640000000}, value: 2}"));
|
||||||
"org.isoron.uhabits.core.models.Checkmark@00000000[" +
|
|
||||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
|
||||||
"value=2]"));
|
|
||||||
|
|
||||||
|
|
||||||
CheckmarkList.Interval interval =
|
CheckmarkList.Interval interval =
|
||||||
new CheckmarkList.Interval(t, t.plus(1), t.plus(2));
|
new CheckmarkList.Interval(t, t.plus(1), t.plus(2));
|
||||||
s = removePointers(interval.toString());
|
assertThat(interval.toString(), equalTo(
|
||||||
assertThat(s, equalTo(
|
"{begin: {unixTime: 8640000000}, center: {unixTime: 8726400000}," +
|
||||||
"org.isoron.uhabits.core.models.CheckmarkList$Interval@00000000[" +
|
" end: {unixTime: 8812800000}}"));
|
||||||
"begin=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
|
||||||
"center=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8726400000]," +
|
|
||||||
"end=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8812800000]]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import nl.jqno.equalsverifier.*;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.isoron.uhabits.core.utils.DateUtils.*;
|
import static org.isoron.uhabits.core.utils.DateUtils.*;
|
||||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class HabitTest extends BaseUnitTest
|
public class HabitTest extends BaseUnitTest
|
||||||
@@ -150,22 +149,14 @@ public class HabitTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
Habit h = modelFactory.buildHabit();
|
Habit h = modelFactory.buildHabit();
|
||||||
h.setReminder(new Reminder(22, 30, WeekdayList.EVERY_DAY));
|
h.setReminder(new Reminder(22, 30, WeekdayList.EVERY_DAY));
|
||||||
|
String expected = "{id: <null>, data: {name: , description: ," +
|
||||||
|
" frequency: {numerator: 3, denominator: 7}," +
|
||||||
|
" color: 8, archived: false, targetType: 0," +
|
||||||
|
" targetValue: 100.0, type: 0, unit: ," +
|
||||||
|
" reminder: {hour: 22, minute: 30," +
|
||||||
|
" days: {weekdays: [true,true,true,true,true,true,true]}}," +
|
||||||
|
" position: 0}}";
|
||||||
|
|
||||||
String s = removePointers(h.toString());
|
assertThat(h.toString(), equalTo(expected));
|
||||||
|
|
||||||
String expected =
|
|
||||||
"org.isoron.uhabits.core.models.Habit@00000000[" +
|
|
||||||
"id=<null>," +
|
|
||||||
"data=org.isoron.uhabits.core.models.Habit$HabitData@00000000[" +
|
|
||||||
"name=,description=," +
|
|
||||||
"frequency=org.isoron.uhabits.core.models.Frequency@00000000[numerator=3,denominator=7]," +
|
|
||||||
"color=8,archived=false,targetType=0,targetValue=100.0,type=0,unit=," +
|
|
||||||
"reminder=org.isoron.uhabits.core.models.Reminder@00000000[" +
|
|
||||||
"hour=22,minute=30," +
|
|
||||||
"days=org.isoron.uhabits.core.models.WeekdayList@00000000[" +
|
|
||||||
"weekdays={true,true,true,true,true,true,true}]]," +
|
|
||||||
"position=0]]";
|
|
||||||
|
|
||||||
assertThat(s, equalTo(expected));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,6 @@ import java.util.*;
|
|||||||
import static junit.framework.TestCase.assertFalse;
|
import static junit.framework.TestCase.assertFalse;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.IsEqual.*;
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
@@ -192,10 +191,6 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
public void testToString() throws Exception
|
public void testToString() throws Exception
|
||||||
{
|
{
|
||||||
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 20);
|
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 20);
|
||||||
String s = removePointers(rep.toString());
|
assertThat(rep.toString(), equalTo("{timestamp: {unixTime: 8640000000}, value: 20}"));
|
||||||
assertThat(s, equalTo(
|
|
||||||
"org.isoron.uhabits.core.models.Repetition@00000000[" +
|
|
||||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
|
||||||
"value=20]"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,11 +22,10 @@ package org.isoron.uhabits.core.models;
|
|||||||
import org.isoron.uhabits.core.*;
|
import org.isoron.uhabits.core.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
import static org.hamcrest.number.IsCloseTo.closeTo;
|
import static org.hamcrest.number.IsCloseTo.*;
|
||||||
import static org.isoron.uhabits.core.models.Score.compute;
|
import static org.isoron.uhabits.core.models.Score.*;
|
||||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
|
||||||
|
|
||||||
|
|
||||||
public class ScoreTest extends BaseUnitTest
|
public class ScoreTest extends BaseUnitTest
|
||||||
@@ -75,10 +74,6 @@ public class ScoreTest extends BaseUnitTest
|
|||||||
public void testToString() throws Exception
|
public void testToString() throws Exception
|
||||||
{
|
{
|
||||||
Score score = new Score(Timestamp.ZERO.plus(100), 150.0);
|
Score score = new Score(Timestamp.ZERO.plus(100), 150.0);
|
||||||
String string = removePointers(score.toString());
|
assertThat(score.toString(), equalTo( "{timestamp: {unixTime: 8640000000}, value: 150.0}"));
|
||||||
assertThat(string, equalTo(
|
|
||||||
"org.isoron.uhabits.core.models.Score@00000000[" +
|
|
||||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
|
||||||
"value=150.0]"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.util.*;
|
|||||||
import static junit.framework.TestCase.*;
|
import static junit.framework.TestCase.*;
|
||||||
import static org.hamcrest.MatcherAssert.*;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.core.IsEqual.*;
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
import static org.isoron.uhabits.core.utils.StringUtils.*;
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class StreakListTest extends BaseUnitTest
|
public class StreakListTest extends BaseUnitTest
|
||||||
@@ -124,10 +123,7 @@ public class StreakListTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
Timestamp time = Timestamp.ZERO.plus(100);
|
Timestamp time = Timestamp.ZERO.plus(100);
|
||||||
Streak streak = new Streak(time, time.plus(10));
|
Streak streak = new Streak(time, time.plus(10));
|
||||||
String string = removePointers(streak.toString());
|
assertThat(streak.toString(), equalTo(
|
||||||
assertThat(string, equalTo(
|
"{start: {unixTime: 8640000000}, end: {unixTime: 9504000000}}"));
|
||||||
"org.isoron.uhabits.core.models.Streak@00000000[" +
|
|
||||||
"start=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
|
||||||
"end=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=9504000000]]"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user