Example usage for java.util Map.Entry toString

List of usage examples for java.util Map.Entry toString

Introduction

In this page you can find the example usage for java.util Map.Entry toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:Main.java

public static void printMap() {
    if (uuidsToNames != null) {
        String mapString = "Map: ";
        for (Map.Entry<UUID, String> entry : uuidsToNames.entrySet()) {
            mapString += entry.toString();
            mapString += "\n";
        }//from w w  w.ja v a  2 s .  c  o m
        Log.e("Helpers: Map", mapString);
    } else {
        Log.e("Helpers: Map", "Map is null :(");
    }

}

From source file:Main.java

private static void writePageNameHashesToFile(Map<UUID, String> map, File folder) {
    if (uuidsToNames != null) {
        String mapString = "Map: ";
        for (Map.Entry<UUID, String> entry : uuidsToNames.entrySet()) {
            mapString += entry.toString();
            mapString += "\n";
        }//  ww  w. j a  v  a  2s  .c  om
    }

    if (map == null) { // TODO: Do I need this?
        map = new HashMap<UUID, String>();
    }

    try {
        FileOutputStream fos = new FileOutputStream(folder.getAbsolutePath() + fileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(map);
        oos.close();
    } catch (Exception e) {
        Log.e("Write to file", e.toString());
    }
}

From source file:org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesLabelConverter.java

/**
 * Checks if there are any potential problems coupled with label conversion
 * @param label//from  w  ww . j a v a2 s.  co  m
 * @return true if label has no conversion issues, false otherwise
 */
private static boolean hasConversionProblems(final Map.Entry<String, String> label) {
    boolean hasProblems = false;
    String key = label.getKey();
    String value = label.getValue();

    if (StringUtils.isBlank(value)) {
        LOG.error("The label {} is blank", label.toString());
        hasProblems = true;
    } else if (key.contains(".") || key.contains("_") || value.contains("_")) {
        LOG.error("Cannot convert label {} to DNS Name: '-' and '.' are used as escape characters",
                label.toString());
        hasProblems = true;
    } else if (!key.startsWith(CHE_SERVER_LABEL_PREFIX)) {
        LOG.warn("Expected CreateContainerParams label key {} to start with {}", key, CHE_SERVER_LABEL_PREFIX);
    }
    return hasProblems;
}

From source file:MinimalHTTPServer.java

public void handle(HttpExchange xchg) throws IOException {
    Headers headers = xchg.getRequestHeaders();
    Set<Map.Entry<String, List<String>>> entries = headers.entrySet();

    StringBuffer response = new StringBuffer();
    for (Map.Entry<String, List<String>> entry : entries)
        response.append(entry.toString() + "\n");

    xchg.sendResponseHeaders(200, response.length());
    OutputStream os = xchg.getResponseBody();
    os.write(response.toString().getBytes());
    os.close();//  w w  w .  java 2 s.  c  o m
}

From source file:org.mendix.eclipse.builder.Mod4jEclipseWorkflowRunner.java

/**
 * General Mod4j workflow runner. // w  w  w  . j  av a  2s . c o m
 * 
 * @param wfFile
 *            absolute path string of the workflow file to execute
 * @param properties
 *            Map containing the properties for <code>wfFile</code>.
 * @throws Mod4jWorkflowException
 */
public void runWorkflow(final String wfFile, final Map<String, String> properties)
        throws Mod4jEclipseWorkflowException {

    Map<String, Object> slotContents = new HashMap<String, Object>();
    WorkflowRunner runner = new WorkflowRunner();

    String propertiesListing = "";
    for (Map.Entry<String, String> prop : properties.entrySet()) {
        propertiesListing += "\t\t" + prop.toString() + "\n";
    }

    logger.info("Running workflow [" + wfFile + "] with properties : \n" + propertiesListing);

    Date date = new Date(System.currentTimeMillis());
    System.err.println("03 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    ResourceLoader loader = ResourceLoaderFactory.getCurrentThreadResourceLoader();

    System.err.println("Classloader: " + (loader == null ? "NULL" : loader.toString()));
    if (loader == null) {
        CachingResourceLoaderImpl crl = new CachingResourceLoaderImpl(
                new OsgiResourceLoader("org.mendix.common", FileTrack.class.getClassLoader()));

        ResourceLoaderFactory.setCurrentThreadResourceLoader(crl);
    }

    date = new Date(System.currentTimeMillis());
    System.err.println("04 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) {
        logger.error("--------------------------------------------------------------------------------------");
        logger.error("------- ERROR(S) detected while running workflow : [" + wfFile + "] ");
        logger.error("------- See logging above for more details.");
        logger.error("--------------------------------------------------------------------------------------");
        throw new Mod4jEclipseWorkflowException("ERROR(S) detected while running workflow :" + wfFile);
    }
    date = new Date(System.currentTimeMillis());
    System.err.println("05 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    logger.info("--------------------------------------------------------------------------");
    logger.info("-------- Workflow SUCCESSFUL! ");
    logger.info("--------------------------------------------------------------------------");
}

From source file:org.mendix.dslcommon.openarchitectureware.Mod4jWorkflowRunner.java

/**
 * General Mod4j workflow runner. //from   w ww  . jav a2s  .co  m
 * 
 * @param wfFile
 *            absolute path string of the workflow file to execute
 * @param properties
 *            Map containing the properties for <code>wfFile</code>.
 * @throws Mod4jWorkflowException
 */
public void runWorkflow(final String wfFile, final Map<String, String> properties)
        throws Mod4jWorkflowException {

    Map<String, Object> slotContents = new HashMap<String, Object>();
    WorkflowRunner runner = new WorkflowRunner();

    String propertiesListing = "";
    for (Map.Entry<String, String> prop : properties.entrySet()) {
        propertiesListing += "\t\t" + prop.toString() + "\n";
    }

    logger.info("Running workflow [" + wfFile + "] with properties : \n" + propertiesListing);

    Date date = new Date(System.currentTimeMillis());
    //        System.err.println("03 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    //        ResourceLoader loader = ResourceLoaderFactory.getCurrentThreadResourceLoader();
    //        
    //        System.err.println("Classloader: " + (loader == null ? "NULL" : loader.toString() ) ) ;
    //        if( loader == null ){
    //              CachingResourceLoaderImpl crl = new CachingResourceLoaderImpl(
    //                      new OsgiResourceLoader("org.mendix.common", FileTrack.class.getClassLoader() )
    //              ); 
    //    
    //              ResourceLoaderFactory.setCurrentThreadResourceLoader(crl);
    //        }
    //
    //        date = new Date(System.currentTimeMillis());
    System.err.println("04 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) {
        logger.error("--------------------------------------------------------------------------------------");
        logger.error("------- ERROR(S) detected while running workflow : [" + wfFile + "] ");
        logger.error("------- See logging above for more details.");
        logger.error("--------------------------------------------------------------------------------------");
        throw new Mod4jWorkflowException("ERROR(S) detected while running workflow :" + wfFile);
    }
    date = new Date(System.currentTimeMillis());
    System.err.println("05 ================== " + date.toString() + ": workflow [" + wfFile + "]");
    logger.info("--------------------------------------------------------------------------");
    logger.info("-------- Workflow SUCCESSFUL! ");
    logger.info("--------------------------------------------------------------------------");
}

From source file:org.smigo.config.WebAppInitializer.java

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
    super.beforeSpringSecurityFilterChain(servletContext);
    log.info("Starting servlet context");
    log.info("contextName: " + servletContext.getServletContextName());
    log.info("contextPath:" + servletContext.getContextPath());
    log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion());
    log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion());
    log.info("majorVersion:" + servletContext.getMajorVersion());
    log.info("minorVersion:" + servletContext.getMinorVersion());
    log.info("serverInfo:" + servletContext.getServerInfo());
    //               ", virtualServerName:" + servletContext.getVirtualServerName() +
    log.info("toString:" + servletContext.toString());

    for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) {
        log.info("Attribute:" + e.nextElement());
    }/*from  w w w  .ja v  a 2  s . c  om*/
    for (Map.Entry<String, String> env : System.getenv().entrySet()) {
        log.info("System env:" + env.toString());
    }
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        log.info("System prop:" + prop.toString());
    }

    final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION);
    log.info("Starting with profile " + profile);

    WebApplicationContext context = new AnnotationConfigWebApplicationContext() {
        {
            register(WebConfiguration.class);
            setDisplayName("SomeRandomName");
            getEnvironment().setActiveProfiles(profile);
        }
    };

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    servletContext.addListener(new RequestContextListener());
    servletContext.addListener(new ContextLoaderListener(context));

    //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains
    //        servletContext.getSessionCookieConfig().setDomain(getDomain());

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(false);
    servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/");
}

From source file:org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesLabelConverter.java

/**
 * Converts a map of labels to match Kubernetes annotation requirements. Annotations are limited
 * to alphanumeric characters, {@code '.'}, {@code '_'} and {@code '-'}, and must start and end
 * with an alphanumeric character, i.e. they must match the regex
 * {@code ([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]}
 *
 * <p>Note that entry keys should begin with {@link KubernetesLabelConverter#CHE_SERVER_LABEL_PREFIX} and
 * entries should not contain {@code '.'} or {@code '_'} before conversion;
 * otherwise label will not be converted and included in output.
 *
 * <p>This implementation is relatively fragile -- changes to how Che generates labels may cause
 * this method to stop working. In general, it will only be possible to convert labels that are
 * alphanumeric plus up to 3 special characters (by converting the special characters to {@code '_'},
 * {@code '-'}, and {@code '.'} as necessary).
 *
 * @param labels Map of labels to convert
 * @return Map of labels converted to DNS Names
 *//* ww  w  .  j  a v  a 2 s.  c o m*/
public static Map<String, String> labelsToNames(Map<String, String> labels) {
    Map<String, String> names = new HashMap<>();
    for (Map.Entry<String, String> label : labels.entrySet()) {

        if (!hasConversionProblems(label)) {

            String key = label.getKey();
            String value = label.getValue();

            // Convert keys: e.g. "che:server:4401/tcp:ref" ->
            // "che.server.4401-tcp.ref"
            key = convertLabelKey(key);
            // Convert values: e.g. "/api" -> ".api" -- note values may
            // include '-' e.g. "tomcat-debug"
            value = convertLabelValue(value);

            // Add padding since DNS names must start and end with
            // alphanumeric characters
            key = addPadding(key);
            value = addPadding(value);

            if (matchesKubernetesLabelRegex(key) && matchesKubernetesLabelRegex(value)) {
                names.put(key, value);
            } else {
                LOG.error(
                        "Could not convert label {} into Kubernetes annotation: labels must be alphanumeric with ':' and '/'",
                        label.toString());
            }
        }
    }
    return names;
}

From source file:report.Report.java

/**
 * Initialize the IXDocReport struct with the JSON
 * @param jsonText The JSON text./*from w  w w.  jav  a2s .  c  o  m*/
 * @throws IOException If the template or output file can't be opened or written.
 * @throws GeneratorException 
 */
private void buildFromJson(String jsonText) throws GeneratorException {
    // Parses the JSON text:
    JSONObject json;
    try {
        JSONParser parser = new JSONParser();
        json = (JSONObject) parser.parse(jsonText);
    } catch (ParseException e) {
        throw new GeneratorException(GeneratorError.JSON_ERROR,
                "Error while parsing the JSON file:" + e.toString());
    }

    // Initializes the template file and creates the report object:
    try {
        InputStream in = new FileInputStream(template);
        report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
    } catch (XDocReportException e) {
        throw new GeneratorException(GeneratorError.TEMPLATE_ERROR,
                "Error with the template file:" + e.toString());
    } catch (FileNotFoundException e) {
        throw new GeneratorException(GeneratorError.PARAMETER_ERROR, "Template file does not exists.");
    } catch (IOException e) {
        throw new GeneratorException(GeneratorError.IO_ERROR, "I/O error...");
    }

    // Creates the FieldsMetadata.
    metadata = new FieldsMetadata();

    // Creates the report context:
    try {
        context = report.createContext();
    } catch (XDocReportException e) {
        throw new GeneratorException(GeneratorError.CONTEXT_ERROR,
                "Error while creating the context:" + e.toString());
    }

    Iterator<?> iter = json.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next();
        BuilderFactory.getBuilder(entry.toString()).build((JSONObject) entry.getValue(), metadata, context);
    }

    // Links the FieldsMetaData to the report.
    report.setFieldsMetadata(metadata);
}

From source file:com.fatwire.dta.sscrawler.util.SSUriHelper.java

public String toLink(final QueryString uri) {
    if (!uri.isOK()) {
        return null;
    }/*from   w  w w  . ja  v  a  2s .c o  m*/
    try {
        final Map<String, String> map = new TreeMap<String, String>(uri.getParameters());
        map.remove(HelperStrings.CACHECONTROL);
        map.remove(HelperStrings.RENDERMODE);
        final StringBuilder qs = new StringBuilder();
        qs.append(path);
        // qs.append("ContentServer");
        qs.append("?");

        for (final Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext();) {
            final Map.Entry<String, String> entry = i.next();
            if (log.isTraceEnabled())
                log.trace(entry.toString());
            qs.append(encode(entry.getKey()));
            qs.append("=");
            final String v = entry.getValue();
            if (v != null && v.startsWith(HelperStrings.SSURI_START)) {

                final Link inner = createLink(v);
                qs.append(encode(toLink(inner)));
            } else if (v != null) {
                qs.append(encode(v));
            }
            if (i.hasNext()) {
                qs.append("&");
            }
        }
        return qs.toString();
    } catch (final EncoderException e) {
        log.warn(e);
        return null;
    } catch (final RuntimeException e) {
        log.warn(e);
        return null;
    }

}