*/
package org.sonar.api.database.configuration;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
@Override
public String toString() {
- return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
- .append("key", key)
- .append("resource", resourceId)
- .append("user", userId)
- .append("value", value)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
}
*/
package org.sonar.jpa.entity;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
import javax.persistence.*;
import java.util.Date;
public String getUserLogin() {
return userLogin;
}
+
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
package org.sonar.jpa.entity;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.notifications.Notification;
import org.sonar.api.utils.SonarException;
}
}
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
*/
package org.sonar.jpa.entity;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+import javax.persistence.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import javax.persistence.*;
-
@Entity
-@Table(name = SchemaMigration.TABLE_NAME, uniqueConstraints = { @UniqueConstraint(columnNames = { "version" }) })
+@Table(name = SchemaMigration.TABLE_NAME, uniqueConstraints = {@UniqueConstraint(columnNames = {"version"})})
public class SchemaMigration {
public final static int VERSION_UNKNOWN = -1;
}
}
}
+
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
*/
package org.sonar.api.database.model;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.database.DatabaseProperties;
public int hashCode() {
return snapshotId.hashCode();
}
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("snapshot_id", snapshotId)
+ .append("data", StringUtils.abbreviate(data, 1000))
+ .toString();
+ }
}
*/
package org.sonar.api.database.model;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import javax.persistence.Column;
public int hashCode() {
return login.hashCode();
}
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import javax.persistence.*;
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("id", getId())
- .append("fromSnapshotId", fromSnapshotId)
- .append("fromResourceId", fromResourceId)
- .append("fromScope", fromScope)
- .append("toSnapshotId", toSnapshotId)
- .append("toResourceId", toResourceId)
- .append("toScope", toScope)
- .append("weight", weight)
- .append("usage", usage)
- .append("projectSnapshotId", projectSnapshotId)
- .append("parentDependencyId", parentDependencyId)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
}
package org.sonar.api.measures;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
/**
* Creates an empty metric
- *
+ *
* @deprecated in 1.12. Use the {@link Builder} factory.
*/
@Deprecated
}
private Metric(String key, String name, ValueType type, String description, Integer direction, String domain, Boolean qualitative, Double worstValue, Double bestValue,
- Boolean optimizedBestValue, Boolean hidden, Formula formula, boolean userManaged) {
+ Boolean optimizedBestValue, Boolean hidden, Formula formula, boolean userManaged) {
this.key = key;
this.name = name;
this.description = description;
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("key", key)
- .append("name", name)
- .append("type", type)
- .append("enabled", enabled)
- .append("qualitative", qualitative)
- .append("direction", direction)
- .append("domain", domain)
- .append("worstValue", worstValue)
- .append("bestValue", bestValue)
- .append("optimizedBestValue", optimizedBestValue)
- .append("hidden", hidden)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
/**
private boolean userManaged = false;
/**
- * @param key the metric key, should be unique among all metrics
+ * @param key the metric key, should be unique among all metrics
* @param name the metric name
* @param type the metric type
*/
/**
* Values of user-managed metrics can be set online in the "Manual measures" page.
+ *
* @since 2.10
*/
public boolean isUserManaged() {
/**
* Values of user-managed metrics can be set online in the "Manual measures" page.
- *
+ *
* @since 2.10
*/
public Builder setUserManaged(boolean b) {
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
package org.sonar.api.resources;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.database.model.ResourceModel;
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("key", key)
- .append("name", name)
- .append("href", href)
- .append("resource", resource)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
public void copyFieldsFrom(ProjectLink link) {
*/
package org.sonar.api.rules;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.*;
import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.profiles.RulesProfile;
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("id", getId())
- .append("profile", rulesProfile)
- .append("rule", rule)
- .append("modifier", userName)
- .append("changed at", date)
- .append("enabled", enabled)
- .append("new severity", newSeverity)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
}
package org.sonar.api.rules;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.*;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.check.Cardinality;
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("id", getId())
- .append("name", name)
- .append("key", key)
- .append("configKey", configKey)
- .append("plugin", pluginName)
- .toString();
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
private String removeNewLineCharacters(String text) {
*/
package org.sonar.api.security;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import javax.persistence.Column;
public boolean isAnyone() {
return groupId==ANYONE_GROUP_ID;
}
+
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
*/
package org.sonar.api.security;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import javax.persistence.Column;
this.resourceId = resourceId;
return this;
}
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+ }
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.database.model;
+
+import org.hamcrest.core.Is;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.internal.matchers.StringContains.containsString;
+
+public class UserTest {
+
+ @Test
+ public void testToString() {
+ User user = new User()
+ .setEmail("super@m.an")
+ .setLogin("superman")
+ .setName("Superman");
+ assertThat(user.toString(), containsString("super@m.an"));
+ assertThat(user.toString(), containsString("superman"));
+ assertThat(user.toString(), containsString("Superman"));
+ }
+
+ @Test
+ public void testEquals() {
+ User one = new User()
+ .setLogin("one")
+ .setName("One");
+
+ User two = new User()
+ .setLogin("two")
+ .setName("Two");
+
+ assertThat(one.equals(one), Is.is(true));
+ assertThat(one.equals(new User().setLogin("one")), Is.is(true));
+ assertThat(one.equals(two), Is.is(false));
+
+ assertEquals(one.hashCode(), new User().setLogin("one").hashCode());
+ }
+}