Example usage for java.util Objects.ToStringHelper toString

List of usage examples for java.util Objects.ToStringHelper toString

Introduction

In this page you can find the example usage for java.util Objects.ToStringHelper toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * ??   ?, ? ? .  @param obj the obj//from  w w  w .j  ava2  s . c om
 *
 * @param obj the obj
 * @return the string
 */
public static String objectToString(final Object obj) {
    if (obj == null)
        return NULL_STR;

    Objects.ToStringHelper helper = Objects.toStringHelper(obj);

    try {
        Class objClazz = obj.getClass();
        Field[] fields = objClazz.getFields();

        for (Field field : fields)
            helper.add(field.getName(), field.get(obj));

    } catch (IllegalAccessException ignored) {
        log.warn("  ? .", ignored);
    }
    return helper.toString();
}

From source file:de.rwhq.btree.BTree.java

public String toString() {
    final Objects.ToStringHelper helper = Objects.toStringHelper(this);
    if (isValid()) {
        helper.add("numberOfEntries", getNumberOfEntries());
        helper.add("root", root);
    }/*from  ww  w. j a  v a  2s  .  c om*/
    helper.add("resourceManager", rm);
    helper.add("valid", valid);
    return helper.toString();
}

From source file:org.apache.hadoop.hbase.mttr.IntegrationTestMTTR.java

public void run(Callable<Boolean> monkeyCallable, String testName) throws Exception {
    int maxIters = util.getHBaseClusterInterface().isDistributedCluster() ? 10 : 3;

    // Array to keep track of times.
    ArrayList<TimingResult> resultPuts = new ArrayList<TimingResult>(maxIters);
    ArrayList<TimingResult> resultScan = new ArrayList<TimingResult>(maxIters);
    ArrayList<TimingResult> resultAdmin = new ArrayList<TimingResult>(maxIters);
    long start = System.nanoTime();

    // We're going to try this multiple times
    for (int fullIterations = 0; fullIterations < maxIters; fullIterations++) {
        // Create and start executing a callable that will kill the servers
        Future<Boolean> monkeyFuture = executorService.submit(monkeyCallable);

        // Pass that future to the timing Callables.
        Future<TimingResult> putFuture = executorService.submit(new PutCallable(monkeyFuture));
        Future<TimingResult> scanFuture = executorService.submit(new ScanCallable(monkeyFuture));
        Future<TimingResult> adminFuture = executorService.submit(new AdminCallable(monkeyFuture));

        Future<Boolean> loadFuture = executorService.submit(new LoadCallable(monkeyFuture));

        monkeyFuture.get();/*from  ww  w  .ja  v a2s  .com*/
        loadFuture.get();

        // Get the values from the futures.
        TimingResult putTime = putFuture.get();
        TimingResult scanTime = scanFuture.get();
        TimingResult adminTime = adminFuture.get();

        // Store the times to display later.
        resultPuts.add(putTime);
        resultScan.add(scanTime);
        resultAdmin.add(adminTime);

        // Wait some time for everything to settle down.
        Thread.sleep(5000l);
    }

    long runtimeMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);

    Objects.ToStringHelper helper = Objects.toStringHelper("MTTRResults").add("putResults", resultPuts)
            .add("scanResults", resultScan).add("adminResults", resultAdmin).add("totalRuntimeMs", runtimeMs)
            .add("name", testName);

    // Log the info
    LOG.info(helper.toString());
}

From source file:org.apache.sentry.policy.db.TestResourceAuthorizationProviderGeneralCases.java

private void doTestAuthorizables(Subject subject, Set<? extends Action> privileges, boolean expected,
        Authorizable... authorizables) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(authorizables);
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("authorizables", authzHierarchy).add("Privileges", privileges);
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges, ActiveRoleSet.ALL));
    LOGGER.info("Passed " + helper.toString());
}

From source file:org.apache.sentry.policy.db.TestResourceAuthorizationProviderGeneralCases.java

private void doTestResourceAuthorizationProvider(Subject subject, Server server, Database database, Table table,
        Set<? extends Action> privileges, boolean expected) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(new Authorizable[] { server, database, table });
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("Subject", subject).add("Server", server).add("DB", database).add("Table", table)
            .add("Privileges", privileges).add("authzHierarchy", authzHierarchy);
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges, ActiveRoleSet.ALL));
    LOGGER.info("Passed " + helper.toString());
}

From source file:org.apache.sentry.policy.indexer.TestIndexerAuthorizationProviderGeneralCases.java

private void doTestResourceAuthorizationProvider(Subject subject, Indexer indexer,
        Set<? extends Action> privileges, boolean expected) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(new Authorizable[] { indexer });
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("Subject", subject).add("Indexer", indexer).add("Privileges", privileges).add("authzHierarchy",
            authzHierarchy);/*from   www.  j  a va 2  s.c  om*/
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges, ActiveRoleSet.ALL));
    LOGGER.info("Passed " + helper.toString());
}

From source file:org.apache.sentry.policy.kafka.provider.TestKafkaAuthorizationProviderGeneralCases.java

private void doTestResourceAuthorizationProvider(Subject subject,
        List<? extends Authorizable> authorizableHierarchy, Set<? extends Action> actions, boolean expected)
        throws Exception {
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("Subject", subject).add("authzHierarchy", authorizableHierarchy).add("action", actions);
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authorizableHierarchy, actions, ActiveRoleSet.ALL));
}

From source file:org.apache.sentry.policy.search.TestSearchAuthorizationProviderGeneralCases.java

private void doTestResourceAuthorizationProvider(Subject subject, Collection collection,
        Set<? extends Action> privileges, boolean expected) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(new Authorizable[] { collection });
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("Subject", subject).add("Collection", collection).add("Privileges", privileges)
            .add("authzHierarchy", authzHierarchy);
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges, ActiveRoleSet.ALL));
    LOGGER.info("Passed " + helper.toString());
}

From source file:org.apache.sentry.provider.file.TestResourceAuthorizationProviderGeneralCases.java

private void doTestAuthorizables(Subject subject, EnumSet<Action> privileges, boolean expected,
        Authorizable... authorizables) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(authorizables);
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("authorizables", authzHierarchy).add("Privileges", privileges);
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges));
    LOGGER.info("Passed " + helper.toString());
}

From source file:org.apache.sentry.provider.file.TestResourceAuthorizationProviderGeneralCases.java

private void doTestResourceAuthorizationProvider(Subject subject, Server server, Database database, Table table,
        EnumSet<Action> privileges, boolean expected) throws Exception {
    List<Authorizable> authzHierarchy = Arrays.asList(new Authorizable[] { server, database, table });
    Objects.ToStringHelper helper = Objects.toStringHelper("TestParameters");
    helper.add("Subject", subject).add("Server", server).add("DB", database).add("Table", table)
            .add("Privileges", privileges).add("authzHierarchy", authzHierarchy);
    LOGGER.info("Running with " + helper.toString());
    Assert.assertEquals(helper.toString(), expected,
            authzProvider.hasAccess(subject, authzHierarchy, privileges));
    LOGGER.info("Passed " + helper.toString());
}