下面列出了怎么用org.apache.commons.lang.builder.ToStringStyle的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* {@inheritDoc}
*/
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this.id, ToStringStyle.DEFAULT_STYLE).append("id", this.id)
.append("username", this.username).append("enabled", this.enabled).append("accountExpired", this.accountExpired)
.append("credentialsExpired", this.credentialsExpired).append("accountLocked", this.accountLocked);
if (roles != null) {
sb.append("Granted Authorities: ");
int i = 0;
for (Role role : roles) {
if (i > 0) {
sb.append(", ");
}
sb.append(role.toString());
i++;
}
} else {
sb.append("No Granted Authorities");
}
return sb.toString();
}
public Log(String operationCode, Object entity) {
if(operationCode != null && operationCode.length() > 100) {
operationCode = operationCode.substring(0, 100);
}
entity = entity == null ? "" : entity;
this.setOperatorId( Environment.getUserId() );
this.setOperatorName( Environment.getUserName() );
this.setOperatorIP( Environment.getClientIp() );
this.setOperationCode( operationCode );
this.setOperateTable ( entity.getClass().getName() );
this.setOperateTime ( new Date() );
String content;
if(entity instanceof String || entity instanceof Number) {
content = String.valueOf(entity);
} else {
content = ToStringBuilder.reflectionToString(entity, ToStringStyle.SHORT_PREFIX_STYLE);
}
this.setContent( content);
this.setOperatorBrowser( Environment.getOrigin() );
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
tsb.append("name", name);
if (converter != null) {
tsb.append("converter", converter);
}
if (action != null) {
tsb.append("action", action);
}
if (forceUpdate) {
tsb.append("forceUpdate", forceUpdate);
}
if (delay > 0.0) {
tsb.append("delay", delay);
}
return tsb.toString();
}
public static void readFromAvro(InputStream is) throws IOException {
DataFileStream<StockAvg> reader = //<co id="ch03_smallfileread_comment1"/>
new DataFileStream<StockAvg>(
is,
new SpecificDatumReader<StockAvg>(StockAvg.class));
for (StockAvg a : reader) { //<co id="ch03_smallfileread_comment2"/>
System.out.println(ToStringBuilder.reflectionToString(a,
ToStringStyle.SHORT_PREFIX_STYLE
));
}
IOUtils.closeStream(is);
IOUtils.closeStream(reader);
}
@Override
public List<GenericEntity> searchStudents(String token, String query, Map<String, String> params) {
LOG.info("searchStudents: " + query);
LOG.info("params: " + ToStringBuilder.reflectionToString(params, ToStringStyle.MULTI_LINE_STYLE));
//rreturn this.readEntityList(token, "search/students?q=" + query + "&" + this.buildQueryString(params));
return this.readEntityList(token, SDKConstants.STUDENTS + "?" + SDKConstants.PARAM_LAST_NAME + "=~" + query + "&" + this.buildQueryString(params));
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("sunrise", getRise())
.append("noon", getNoon()).append("sunset", getSet()).append("night", night)
.append("morningNight", morningNight).append("astroDawn", astroDawn).append("nauticDawn", nauticDawn)
.append("civilDawn", civilDawn).append("civilDusk", civilDusk).append("nauticDusk", nauticDusk)
.append("astroDusk", astroDusk).append("daylight", getDaylight())
.append("eveningNight", getEveningNight()).append("eclipse", eclipse).toString();
}
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("id", this.id)
.toString();
}
/**
*
* @return String
*/
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("id", this.id)
.toString();
}
public String toIdStateString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("id", "" + seq + "(" + this.containerId + ")")
.append("state", this.getState())
.toString();
}
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("operators", this.operators)
.append("streams", this.streams)
.append("properties", this.attributes)
.toString();
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("x", x)
.append("y", y)
.toString();
}
/**
* {@inheritDoc}
*/
@Override
public void addForward(String fqdn, String ipAddress) {
List<String> commands = createCommands();
List<String> stdins = createAddForward(fqdn, ipAddress);
CommandResult result = execute(commands, stdins);
if (result.getExitValue() != 0) {
// 正引きレコードの追加に失敗
AutoException exception = new AutoException("ECOMMON-000201", fqdn, ipAddress);
exception.addDetailInfo(
"result=" + ReflectionToStringBuilder.toString(result, ToStringStyle.SHORT_PREFIX_STYLE));
throw exception;
}
// 正引きの確認
long timeout = 10000L;
long startTime = System.currentTimeMillis();
while (true) {
String hostAddress = getHostAddress(fqdn);
if (StringUtils.equals(ipAddress, hostAddress)) {
break;
}
if (System.currentTimeMillis() - startTime > timeout) {
// タイムアウト発生時
throw new AutoException("ECOMMON-000202", fqdn, ipAddress, hostAddress);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
}
}
/**
* {@inheritDoc}
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
final ToStringBuilder builder = new ToStringBuilder( this, ToStringStyle.SHORT_PREFIX_STYLE );
builder.append( "packageName", this.packageName );
return builder.toString();
}
@Test
public void testInspect() {
ListMultimap<CustomizationType, Customization> customizationMap = loadCustomizationMap();
List<Customization> curCustomizations = customizationMap.get(CustomizationType.INFO);
for(Customization cur : curCustomizations) {
System.out.println(ReflectionToStringBuilder.toString(cur, ToStringStyle.MULTI_LINE_STYLE));
}
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("sunrise", getRise())
.append("noon", getNoon()).append("sunset", getSet()).append("night", getNight())
.append("morningNight", getMorningNight()).append("astroDawn", getAstroDawn())
.append("nauticDawn", getNauticDawn()).append("civilDawn", getCivilDawn())
.append("civilDusk", getCivilDusk()).append("nauticDusk", getNauticDawn())
.append("astroDusk", getAstroDusk()).append("daylight", getDaylight())
.append("eveningNight", getEveningNight()).append("eclipse", eclipse).append("phase", phase)
.append("radiation", radiation).toString();
}
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("moduleId", moduleId)
.append("testName", testName)
.append("commitId", commitId)
.append("runNumber", runNumber)
.append("metricType", metric)
.append("percentile", percentile)
.append("failureType", failureType)
.toString();
}
@Override
public String toString() {
return new ToStringBuilder( this, ToStringStyle.SHORT_PREFIX_STYLE )
.append( "url", url )
.append( "ipv4Address", ipv4Address )
.append( "hostname", hostname )
.append( "serverPort", serverPort )
.append( "tempDir", tempDir )
.toString();
}
/**
* @return string representation.
*/
public String toMultiLineString() {
final ToStringBuilder builder = new ToStringBuilder( this, ToStringStyle.MULTI_LINE_STYLE );
for ( KeyValue<?> keyValue : this.entries.values() ) {
builder.append( keyValue.getKey(), keyValue.getValue() );
}
return builder.toString();
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("config", configDirectory)
.append("principal", principalName)
.append("keytab", keytabPath)
.append("kerberosMinMillisBeforeRelogin", kerberosMinMillisBeforeRelogin)
.toString();
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("rise", DateTimeUtils.getDate(getRise().getStart()))
.append("set", DateTimeUtils.getDate(getSet().getEnd())).append("phase", phase).append("apogee", apogee)
.append("perigee", perigee).append("distance", distance).append("eclipse", eclipse)
.append("position", position).append("zodiac", zodiac).toString();
}
/**
* {@inheritDoc}
*/
@Override
public void deleteCanonicalName(String fqdn) {
List<String> commands = createCommands();
List<String> stdins = createDeleteCanonicalName(fqdn);
CommandResult result = execute(commands, stdins);
if (result.getExitValue() != 0) {
// CNAMEレコードの削除に失敗
AutoException exception = new AutoException("ECOMMON-000211", fqdn);
exception.addDetailInfo(
"result=" + ReflectionToStringBuilder.toString(result, ToStringStyle.SHORT_PREFIX_STYLE));
throw exception;
}
// CNAMEの確認
long timeout = 10000L;
long startTime = System.currentTimeMillis();
while (true) {
String cname = getCanonicalName(fqdn);
if (cname == null) {
break;
}
if (System.currentTimeMillis() - startTime > timeout) {
// タイムアウト発生時
throw new AutoException("ECOMMON-000212", fqdn, cname);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
}
}
@Override
public String toString() {
ToStringBuilder toStringBuilder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
toStringBuilder.append("actionId", actionId)
.append("messageId", messageId)
.append("classValue", classValue)
.append("probabilities", predictedClassProbability);
return toStringBuilder.toString();
}
/**
* Create a key including the
* <li><b>expenditureFinancialDocumentNumber</b></li>
* <li><b>expenditureFinancialDocumentTypeCode</b></li>
* with accounting information for asset payment distribution
*
* Make sure the full accounting line information is part of the key
* chartOfAccount, accountNumber, subAccountNumber, objectCode, subObjectCode, projectCode
*
* @return
*/
public String getAssetPaymentDetailKey() {
LinkedHashMap<String,String> paymentMap = assetPaymentToStringMapper();
paymentMap.put("expenditureFinancialDocumentTypeCode",this.getExpenditureFinancialDocumentTypeCode());
paymentMap.put("expenditureFinancialDocumentNumber",this.getExpenditureFinancialDocumentNumber());
//use SHORT_PREFIX_STYLE so that memory address is not part of the toString output
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
for (String key : paymentMap.keySet()){
builder.append(key, paymentMap.get(key));
}
return paymentMap.toString();
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("adGroupId", adGroupId)
.append("biddingStrategyConfig", biddingStrategyConfig)
.append("originalRoot is empty", originalRoot == null)
// Add a newline before the root so that the tree levels all line up.
.append("root", String.format("%n%s", root.toDetailedString()))
.toString();
}
@Override
public String toString() {
ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
tsb.append("planet", planetName.toString().toLowerCase()).append("type", type).append("property", property);
if (offset != 0) {
tsb.append("offset", offset);
}
return tsb.toString();
}
public T testSerialization(T in) throws Exception {
byte[] wire=serialize(in);
if (wire==null) {
throw new NullPointerException("Could not Serialize ["+ToStringBuilder.reflectionToString(in,ToStringStyle.MULTI_LINE_STYLE)+"]");
}
T out=deserialize(wire);
if (out==null) {
throw new NullPointerException("Could not Deserialize ["+ToStringBuilder.reflectionToString(in,ToStringStyle.MULTI_LINE_STYLE)+"]");
}
return out;
}
@Override
public String toString() {
String result = super.toString();
ToStringBuilder ts = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
ts.append("name", getName());
ts.append("inputDirectory", getInputDirectory());
ts.append("wildcard", getWildcard());
result += ts.toString();
return result;
}
/**
* {@inheritDoc}
*/
@Override
public void deleteReverse(String ipAddress) {
List<String> commands = createCommands();
List<String> stdins = createDeleteReverse(ipAddress);
CommandResult result = execute(commands, stdins);
if (result.getExitValue() != 0) {
// 逆引きレコードの削除に失敗
AutoException exception = new AutoException("ECOMMON-000209", ipAddress);
exception.addDetailInfo(
"result=" + ReflectionToStringBuilder.toString(result, ToStringStyle.SHORT_PREFIX_STYLE));
throw exception;
}
// 逆引きの確認
long timeout = 10000L;
long startTime = System.currentTimeMillis();
while (true) {
String hostName = getHostName(ipAddress);
if (StringUtils.equals(ipAddress, hostName)) {
break;
}
if (System.currentTimeMillis() - startTime > timeout) {
// タイムアウト発生時
throw new AutoException("ECOMMON-000210", ipAddress, hostName);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
}
}
private Set<String> getEdOrgs(Entity principal, boolean filterByOwnership) {
LOG.trace(">>>EdOrgHelper.getDirectEdorgs()");
LOG.trace(" principal: " + ToStringBuilder.reflectionToString(principal, ToStringStyle.MULTI_LINE_STYLE));
LOG.trace(" filterByOwnership: " + filterByOwnership);
Set<String> result = new HashSet<String>();
if (isStaff(principal) || isTeacher(principal)) {
LOG.trace(" ...staff or teacher");
result = getStaffDirectlyAssociatedEdorgs(principal, filterByOwnership);
} else if (isStudent(principal)) {
LOG.trace(" ...student");
result = getStudentsCurrentAssociatedEdOrgs(Collections.singleton(principal.getEntityId()), filterByOwnership);
} else if (isParent(principal)) {
LOG.trace(" ...parent");
SLIPrincipal prince = new SLIPrincipal();
prince.setEntity(principal);
prince.populateChildren(repo);
result = getStudentsCurrentAssociatedEdOrgs(prince.getOwnedStudentIds(), false);
}
if (result == null) {
LOG.debug(" ...method did not do anything so return empty set...");
}
return result;
}
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("operator", this.operatorMeta)
.append("portAnnotation", this.portAnnotation)
.append("adrAnnotation", this.adrAnnotation)
.append("field", this.fieldName)
.toString();
}