Example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString

List of usage examples for org.apache.commons.lang.builder ReflectionToStringBuilder toString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString.

Prototype

public static String toString(Object object, ToStringStyle style) 

Source Link

Document

Builds a toString value through reflection.

Usage

From source file:com.google.cloud.language.v1.LanguageServiceSmokeTest.java

public static void executeNoCatch() throws Exception {
    try (LanguageServiceClient client = LanguageServiceClient.create()) {
        String content = "Hello, world!";
        Document.Type type = Document.Type.PLAIN_TEXT;
        Document document = Document.newBuilder().setContent(content).setType(type).build();

        AnalyzeSentimentResponse response = client.analyzeSentiment(document);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }//from  ww w.  j av a2 s.  com
}

From source file:com.google.cloud.speech.v1.SpeechSmokeTest.java

public static void executeNoCatch() throws Exception {
    try (SpeechClient client = SpeechClient.create()) {
        String languageCode = "en-US";
        int sampleRateHertz = 44100;
        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
        RecognitionConfig config = RecognitionConfig.newBuilder().setLanguageCode(languageCode)
                .setSampleRateHertz(sampleRateHertz).setEncoding(encoding).build();
        String uri = "gs://gapic-toolkit/hello.flac";
        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();

        RecognizeResponse response = client.recognize(config, audio);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }//w ww .j  a v a 2 s . co  m
}

From source file:com.google.cloud.speech.v1beta1.SpeechSmokeTest.java

public static void executeNoCatch() throws Exception {
    try (SpeechClient client = SpeechClient.create()) {
        String languageCode = "en-US";
        int sampleRate = 44100;
        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
        RecognitionConfig config = RecognitionConfig.newBuilder().setLanguageCode(languageCode)
                .setSampleRate(sampleRate).setEncoding(encoding).build();
        String uri = "gs://gapic-toolkit/hello.flac";
        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();

        SyncRecognizeResponse response = client.syncRecognize(config, audio);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }//from   w w w .j  a v  a  2 s. c  o  m
}

From source file:com.google.cloud.dlp.v2beta1.DlpServiceSmokeTest.java

public static void executeNoCatch() throws Exception {
    try (DlpServiceClient client = DlpServiceClient.create()) {
        Likelihood minLikelihood = Likelihood.POSSIBLE;
        InspectConfig inspectConfig = InspectConfig.newBuilder().setMinLikelihood(minLikelihood).build();
        String type = "text/plain";
        String value = "my phone number is 215-512-1212";
        ContentItem itemsElement = ContentItem.newBuilder().setType(type).setValue(value).build();
        List<ContentItem> items = Arrays.asList(itemsElement);

        InspectContentResponse response = client.inspectContent(inspectConfig, items);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }//from w  w  w  . ja v a2s  .c  o m
}

From source file:com.google.cloud.vision.v1.ImageAnnotatorSmokeTest.java

public static void executeNoCatch() throws Exception {
    try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        String gcsImageUri = "gs://gapic-toolkit/President_Barack_Obama.jpg";
        ImageSource source = ImageSource.newBuilder().setGcsImageUri(gcsImageUri).build();
        Image image = Image.newBuilder().setSource(source).build();
        Feature.Type type = Feature.Type.FACE_DETECTION;
        Feature featuresElement = Feature.newBuilder().setType(type).build();
        List<Feature> features = Arrays.asList(featuresElement);
        AnnotateImageRequest requestsElement = AnnotateImageRequest.newBuilder().setImage(image)
                .addAllFeatures(features).build();
        List<AnnotateImageRequest> requests = Arrays.asList(requestsElement);

        BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }/* w  ww  .j  a  v a  2s . c  o  m*/
}

From source file:com.pieframework.model.system.Access.java

@Override
public String toString() {
    return ReflectionToStringBuilder.toString(this, ToStringStyle.SIMPLE_STYLE);
}

From source file:com.supermap.desktop.icloud.commontypes.LicenseInfo.java

public String toString() {
    return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}

From source file:com.zxy.commons.lang.utils.ObjectsUtils.java

/**
 * ??/*from ww w  .  j a va2 s  . c  om*/
 * 
 * @param obj 
 * @param toStringStyle ?
 *                      {@code ToStringStyle.SIMPLE_STYLE }
 *                      {@code ToStringStyle.SHORT_PREFIX_STYLE }
 *                      {@code ToStringStyle.MULTI_LINE_STYLE }
 * @return ??
 * @see ToStringStyle
 */
public static String toString(Object obj, ToStringStyle toStringStyle) {
    if (obj == null) {
        return null;
    }
    if ((obj instanceof Collection)) {
        Collection<?> cs = (Collection<?>) obj;
        List<String> returnCs = new ArrayList<>();
        for (Object c : cs) {
            returnCs.add(ReflectionToStringBuilder.toString(c, toStringStyle));
        }
        return returnCs.toString();
    }
    if ((obj instanceof Map)) {
        Map<?, ?> maps = (Map<?, ?>) obj;
        Map<String, String> returnMaps = new HashMap<>();
        for (Map.Entry<?, ?> entry : maps.entrySet()) {
            String key = entry.getKey().toString();
            String value = ReflectionToStringBuilder.toString(entry.getValue(), toStringStyle);
            returnMaps.put(key, value);
        }
        return returnMaps.toString();
    }
    //        return ReflectionToStringBuilder.toString(obj, ToStringStyle.SHORT_PREFIX_STYLE);
    return ReflectionToStringBuilder.toString(obj, toStringStyle);
}

From source file:io.reign.examples.PresenceServiceExample.java

public static void presenceServiceExample(Reign reign) throws Exception {
    // get presence service
    final PresenceService presenceService = reign.getService("presence");

    // separate thread to exercise waitUntilAvailable for ServiceInfo
    Thread t1 = new Thread() {
        @Override//w  w  w  .  ja v  a2  s .  c  om
        public void run() {
            ServiceInfo serviceInfo = presenceService.waitUntilAvailable("examples", "service1", -1);
            presenceService.observe("examples", "service1", new PresenceObserver<ServiceInfo>() {
                @Override
                public void updated(ServiceInfo updated, ServiceInfo previous) {
                    if (updated != null) {
                        logger.info("***** T1:  Observer:  serviceInfo={}",
                                ReflectionToStringBuilder.toString(updated, ToStringStyle.DEFAULT_STYLE));
                    } else {
                        logger.info("***** T1:  Observer:  serviceInfo deleted");
                    }
                }
            });
            logger.info("T1:  serviceInfo={}",
                    ReflectionToStringBuilder.toString(serviceInfo, ToStringStyle.DEFAULT_STYLE));
        }
    };
    t1.start();

    // separate thread to exercise waitUntilAvailable for NodeInfo
    Thread t2 = new Thread() {
        @Override
        public void run() {
            NodeInfo nodeInfo = presenceService.waitUntilAvailable("examples", "service1", "node1", -1);
            presenceService.observe("examples", "service1", "node1", new PresenceObserver<NodeInfo>() {
                @Override
                public void updated(NodeInfo updated, NodeInfo previous) {
                    if (updated != null) {
                        logger.info("***** T2:  Observer:  nodeInfo={}",
                                ReflectionToStringBuilder.toString(updated, ToStringStyle.DEFAULT_STYLE));
                    } else {
                        logger.info("***** T2:  Observer:  nodeInfo deleted");
                    }
                }
            });
            logger.info("T2:  nodeInfo={}",
                    ReflectionToStringBuilder.toString(nodeInfo, ToStringStyle.DEFAULT_STYLE));
        }
    };
    t2.start();

    Thread t3 = new Thread() {
        @Override
        public void run() {
            NodeInfo nodeInfo = presenceService.waitUntilAvailable("examples", "service1", "node1", 1);
            presenceService.observe("examples", "service1", "node1", new PresenceObserver<NodeInfo>() {
                @Override
                public void updated(NodeInfo updated, NodeInfo previous) {
                    if (updated != null) {
                        logger.info("***** T3:  Observer:  nodeInfo={}",
                                ReflectionToStringBuilder.toString(updated, ToStringStyle.DEFAULT_STYLE));
                    } else {
                        logger.info("***** T3:  Observer:  nodeInfo deleted");
                    }
                }
            });
            logger.info("T3:  nodeInfo={}",
                    ReflectionToStringBuilder.toString(nodeInfo, ToStringStyle.DEFAULT_STYLE));
        }
    };
    t3.start();

    Thread.sleep(3000);

    // try to retrieve service info (which may not be immediately
    // available); include observer to be notified of changes in service
    // info
    ServiceInfo serviceInfo = presenceService.getServiceInfo("examples", "service1",
            new PresenceObserver<ServiceInfo>() {
                @Override
                public void updated(ServiceInfo updated, ServiceInfo previous) {
                    if (updated != null) {
                        logger.info("***** Observer:  serviceInfo={}",
                                ReflectionToStringBuilder.toString(updated, ToStringStyle.DEFAULT_STYLE));
                    } else {
                        logger.info("***** Observer:  serviceInfo deleted");
                    }
                }
            });
    logger.info("serviceInfo={}", ReflectionToStringBuilder.toString(serviceInfo, ToStringStyle.DEFAULT_STYLE));

    // try to retrieve node info (which may not be immediately
    // available); include observer to be notified of changes in node
    // info
    NodeInfo nodeInfo = presenceService.getNodeInfo("examples", "service2", "node1",
            new PresenceObserver<NodeInfo>() {
                @Override
                public void updated(NodeInfo updated, NodeInfo previous) {
                    if (updated != null) {
                        logger.info("***** Observer:  nodeInfo={}",
                                ReflectionToStringBuilder.toString(updated, ToStringStyle.DEFAULT_STYLE));

                    } else {
                        logger.info("***** Observer:  nodeInfo deleted");
                    }
                }
            });
    logger.info("nodeInfo={}", ReflectionToStringBuilder.toString(nodeInfo, ToStringStyle.DEFAULT_STYLE));

    // basic service node announcement
    presenceService.announce("examples", "service1", true);

    // service node announcement with some additional info
    Map<String, String> nodeAttributes = new HashMap<String, String>();
    nodeAttributes.put("port", "1234");
    presenceService.announce("examples", "service2", true, nodeAttributes);

    // sleep a bit
    Thread.sleep(10000);

    presenceService.hide("examples", "service2");

    // sleep a bit
    Thread.sleep(10000);

    presenceService.show("examples", "service2");

    // new node available in service
    presenceService.announce("examples", "service1", true);

    // sleep a bit
    Thread.sleep(10000);

    // new node available in service
    presenceService.hide("examples", "service1");

    // reannounce service with changed attributes
    // service node announcement with some additional info
    nodeAttributes = new HashMap<String, String>();
    nodeAttributes.put("port", "9999");
    presenceService.announce("examples", "service2", true, nodeAttributes);

}

From source file:com.google.cloud.logging.v2.LoggingSmokeTest.java

public static void executeNoCatch(String projectId) throws Exception {
    try (LoggingClient client = LoggingClient.create()) {
        LogNameOneof logName = LogNameOneof
                .from(LogName.create(projectId, "test-" + System.currentTimeMillis()));
        MonitoredResource resource = MonitoredResource.newBuilder().build();
        Map<String, String> labels = new HashMap<>();
        List<LogEntry> entries = new ArrayList<>();

        WriteLogEntriesResponse response = client.writeLogEntries(logName, resource, labels, entries);
        System.out.println(ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE));
    }//from  w  ww.j  a  v a 2 s.c om
}