You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Richard Eigenmann (JIRA)" <ji...@apache.org> on 2015/04/13 16:32:12 UTC

[jira] [Issue Comment Deleted] (JCS-124) Make the code in Step 5 on the JCS overview page a full working class that can compile

     [ https://issues.apache.org/jira/browse/JCS-124?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Richard Eigenmann updated JCS-124:
----------------------------------
    Comment: was deleted

(was: Here comes the unified diff:

import java.io.Serializable;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
import org.apache.commons.jcs.access.exception.CacheException;

public class JcsExample {

    public static void main( String[] args ) {
        JcsExample example = new JcsExample();
        example.testCache();
    }

    private CacheAccess<String, City> cache = null;

    public JcsExample() {
        try {
            cache = JCS.getInstance( "default" );
        } catch ( CacheException e ) {
            System.out.println( String.format( "Problem initializing cache: %s", e.getMessage() ) );
        }
    }

    public void putInCache( City city ) {
        String key = city.name;
        try {
            cache.put( key, city );
        } catch ( CacheException e ) {
            System.out.println( String.format( "Problem putting city %s in the cache, for key %s%n%s",
                    city.name, key, e.getMessage() ) );
        }
    }

    public City retrieveFromCache( String cityKey ) {
        return cache.get( cityKey );
    }

    public void testCache() {
        City zurich = new City( "Zürich", "Switzerland", 366765 );
        putInCache( zurich );
        
        City berlin = new City( "Berlin", "Germany", 3502000 );
        putInCache( berlin );
        
        City johannesburg = new City( "Johannesburg", "South Africa", 12200000 );
        putInCache( johannesburg );

        City retrievedCity1 = retrieveFromCache( "Berlin" );
        if ( retrievedCity1 != null ) {
            System.out.println( retrievedCity1.toString() );
        } else {
            System.out.println( "No object was found in the cache for the key \"Berlin\"" );
        }

        City retrievedCity2 = retrieveFromCache( "New York" );
        if ( retrievedCity2 != null ) {
            System.out.println( retrievedCity2.toString() );
        } else {
            System.out.println( "No object was found in the cache for the key \"New York\"" );
        }
    }

    // defined as a nested inner class to reduce number of .java files in the example
    public class City implements Serializable {

        private static final long serialVersionUID = 6392376146163510146L;
        public String name;
        public String country;
        public int population;

        public City( String name, String country, int population ) {
            this.name = name;
            this.country = country;
            this.population = population;
        }

        @Override
        public String toString() {
            return String.format( "%s is a city in the country %s with a population of %d", name, country, population );
        }
    }
}
)

> Make the code in Step 5 on the JCS overview page a full working class that can compile
> --------------------------------------------------------------------------------------
>
>                 Key: JCS-124
>                 URL: https://issues.apache.org/jira/browse/JCS-124
>             Project: Commons JCS
>          Issue Type: Improvement
>          Components: Documentation
>    Affects Versions: jcs-2.0-beta-1
>         Environment: Testing
>            Reporter: Richard Eigenmann
>             Fix For: jcs-2.0-beta-2
>
>         Attachments: intro.xml
>
>
> Step 5: http://commons.apache.org/proper/commons-jcs/getting_started/intro.html
> Please make this a fully compilable class that can be cut and pasted for a quick success experience for the newby.
> Defaults and examples are extremely powerful and many people never venture further than the defaults and samples they discovered so it is extremely important to show sensible default values and good code.
> In this vein, drop the words "might" and "could" in the comments. It's either a good way to do it or you should not be showing it for it will be copied.
> Please also correct the setCache(c); instruction which doesn't make sense. The example doesn't indicate that it is extending another class where setCache(c) might be defined and isn't defining the method. Is this instruction needed?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)