Package org.apache.xmlgraphics.image.loader.util

Examples of org.apache.xmlgraphics.image.loader.util.Penalty


     * If no such value is set, 0 is returned.
     * @param className the fully qualified class name of the implementation class
     * @return the additional penalty value
     */
    public Penalty getAdditionalPenalty(String className) {
        Penalty p = (Penalty)this.additionalPenalties.get(className);
        return (p != null ? p : Penalty.ZERO_PENALTY);
    }
View Full Code Here


     * different possible pipelines.
     * @param registry the image implementation registry
     * @return the overall penalty (a non-negative integer)
     */
    public Penalty getConversionPenalty(ImageImplRegistry registry) {
        Penalty penalty = Penalty.ZERO_PENALTY;
        if (loader != null) {
            penalty = penalty.add(loader.getUsagePenalty());
            if (registry != null) {
                penalty = penalty.add(
                        registry.getAdditionalPenalty(loader.getClass().getName()));
            }
        }
        Iterator iter = converters.iterator();
        while (iter.hasNext()) {
            ImageConverter converter = (ImageConverter)iter.next();
            penalty = penalty.add(converter.getConversionPenalty());
            if (registry != null) {
                penalty = penalty.add(
                        registry.getAdditionalPenalty(converter.getClass().getName()));
            }
        }
        return penalty;
    }
View Full Code Here

    /**
     * Tests for the {@link Penalty} class.
     * @throws Exception if an error occurs
     */
    public void testPenalty() throws Exception {
        Penalty p1 = Penalty.toPenalty(100);
        assertEquals(100, p1.getValue());
        Penalty p2 = p1.add(Penalty.toPenalty(50));
        assertEquals(150, p2.getValue());

        p1 = Penalty.toPenalty(0);
        assertEquals(0, p1.getValue());

        p1 = Penalty.INFINITE_PENALTY;
        assertEquals(Integer.MAX_VALUE, p1.getValue());
        assertTrue(p1.isInfinitePenalty());
        p2 = p1.add(p2);
        assertEquals(Integer.MAX_VALUE, p2.getValue());
        assertTrue(p2.isInfinitePenalty());
    }
View Full Code Here

        }
        for (int i = count - 1; i >= 0; i--) {
            if (candidates[i] == null) {
                continue;
            }
            Penalty penalty = candidates[i].getConversionPenalty(getRegistry());
            if (penalty.isInfinitePenalty()) {
                continue; //Exclude candidate on infinite penalty
            }
            if (penalty.getValue() <= minPenalty) {
                pipeline = candidates[i];
                minPenalty = penalty.getValue();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Chosen pipeline: " + pipeline);
        }
View Full Code Here

     * different possible pipelines.
     * @param registry the image implementation registry
     * @return the overall penalty (a non-negative integer)
     */
    public Penalty getConversionPenalty(ImageImplRegistry registry) {
        Penalty penalty = Penalty.ZERO_PENALTY;
        if (loader != null) {
            penalty = penalty.add(loader.getUsagePenalty());
            if (registry != null) {
                penalty = penalty.add(
                        registry.getAdditionalPenalty(loader.getClass().getName()));
            }
        }
        Iterator iter = converters.iterator();
        while (iter.hasNext()) {
            ImageConverter converter = (ImageConverter)iter.next();
            penalty = penalty.add(converter.getConversionPenalty());
            if (registry != null) {
                penalty = penalty.add(
                        registry.getAdditionalPenalty(converter.getClass().getName()));
            }
        }
        return penalty;
    }
View Full Code Here

            //Rebuild edge directory
            DefaultEdgeDirectory dir = new DefaultEdgeDirectory();
            Iterator iter = converters.iterator();
            while (iter.hasNext()) {
                ImageConverter converter = (ImageConverter)iter.next();
                Penalty penalty = Penalty.toPenalty(converter.getConversionPenalty());
                penalty = penalty.add(
                        registry.getAdditionalPenalty(converter.getClass().getName()));
                dir.addEdge(new ImageConversionEdge(converter, penalty));
            }

            converterEdgeDirectoryVersion = registry.getImageConverterModifications();
View Full Code Here

            //Find the best pipeline for each flavor
            ImageProviderPipeline pipeline = newImageConverterPipeline(imageInfo, flavors[i]);
            if (pipeline == null) {
                continue; //No suitable pipeline found for flavor
            }
            Penalty p = pipeline.getConversionPenalty(this.manager.getRegistry());
            if (!p.isInfinitePenalty()) {
                candidates.add(pipeline);
            }
        }
        return (ImageProviderPipeline[])candidates.toArray(
                new ImageProviderPipeline[candidates.size()]);
View Full Code Here

     * If no such value is set, 0 is returned.
     * @param className the fully qualified class name of the implementation class
     * @return the additional penalty value
     */
    public Penalty getAdditionalPenalty(String className) {
        Penalty p = (Penalty)this.additionalPenalties.get(className);
        return (p != null ? p : Penalty.ZERO_PENALTY);
    }
View Full Code Here

        try {
            for (int i = 0, c = penalties.length; i < c; i++) {
                Configuration penaltyCfg = penalties[i];
                String className = penaltyCfg.getAttribute("class");
                String value = penaltyCfg.getAttribute("value");
                Penalty p = null;
                if (value.toUpperCase().startsWith("INF")) {
                    p = Penalty.INFINITE_PENALTY;
                } else {
                    try {
                        p = Penalty.toPenalty(Integer.parseInt(value));
View Full Code Here

        try {
            for (int i = 0, c = penalties.length; i < c; i++) {
                Configuration penaltyCfg = penalties[i];
                String className = penaltyCfg.getAttribute("class");
                String value = penaltyCfg.getAttribute("value");
                Penalty p = null;
                if (value.toUpperCase().startsWith("INF")) {
                    p = Penalty.INFINITE_PENALTY;
                } else {
                    try {
                        p = Penalty.toPenalty(Integer.parseInt(value));
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.util.Penalty

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.