EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.utils]

COVERAGE SUMMARY FOR SOURCE FILE [Named.java]

nameclass, %method, %block, %line, %
Named.java100% (2/2)55%  (6/11)63%  (100/158)66%  (23/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Named$MapSource100% (1/1)43%  (3/7)23%  (15/66)33%  (5/15)
equals (Object): boolean 0%   (0/1)0%   (0/23)0%   (0/4)
getName (): String 0%   (0/1)0%   (0/12)0%   (0/4)
hashCode (): int 0%   (0/1)0%   (0/6)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/10)0%   (0/1)
Named$MapSource (Map): void 100% (1/1)100% (6/6)100% (3/3)
getNames (): Set 100% (1/1)100% (4/4)100% (1/1)
getValue (String): Object 100% (1/1)100% (5/5)100% (1/1)
     
class Named$ContextSource100% (1/1)75%  (3/4)92%  (85/92)90%  (18/20)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getNames (): Set 100% (1/1)88%  (29/33)88%  (7/8)
Named$ContextSource (String, Named$Source, String []): void 100% (1/1)100% (12/12)100% (5/5)
getValue (String): Object 100% (1/1)100% (44/44)100% (6/6)

1package org.jtoolkit.essence.utils;
2 
3import org.jetbrains.annotations.NotNull;
4import org.jetbrains.annotations.Nullable;
5import org.jtoolkit.essence.concurrency.Immutable;
6 
7import java.util.*;
8 
9/*
10   Copyright 2006 Peter Lawrey
11 
12   Licensed under the Apache License, Version 2.0 (the "License");
13   you may not use this file except in compliance with the License.
14   You may obtain a copy of the License at
15 
16       http://www.apache.org/licenses/LICENSE-2.0
17 
18   Unless required by applicable law or agreed to in writing, software
19   distributed under the License is distributed on an "AS IS" BASIS,
20   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   See the License for the specific language governing permissions and
22   limitations under the License.
23*/
24 
25/**
26 * A class which has a unique name for a given name space.  Useful for comments.
27 *
28 * @author Peter Lawrey
29 */
30public interface Named {
31    /**
32     * @return A printable name.
33     */
34    @NotNull public String getName();
35 
36    public interface Source<T> extends Named {
37        Source EMPTY_SOURCE = new MapSource(Collections.emptyMap());
38        /**
39         * @return names available in this source.
40         */
41        @NotNull public Set<String> getNames();
42 
43        /**
44         * @param name of the object.
45         * @return the object in source or null.
46         */
47        @Nullable public T getValue(@NotNull String name);
48    }
49 
50    @Immutable
51    public static class ContextSource<T> implements Source<T> {
52        private static final String SEP = "..";
53        private final String name;
54        private final Source<T> source;
55        private final String[] contexts;
56 
57        public ContextSource(String name, Source<T> source, String[] contexts) {
58            this.name = name;
59            this.source = source;
60            this.contexts = contexts;
61        }
62 
63        @NotNull public Set<String> getNames() {
64            Set<String> ret = new LinkedHashSet<String>();
65            for(String name: source.getNames()) {
66                int pos = name.indexOf(SEP);
67                if (pos>=0)
68                    name = name.substring(pos);
69                ret.add(name);
70            }
71            return ret;
72        }
73 
74        public T getValue(@NotNull String name){
75            for(String context:contexts) {
76                String key = context.length() == 0 ? name : name + SEP + context;
77                T value = source.getValue(key);
78                if (value != null)
79                    return value;
80            }
81            return null;
82        }
83 
84        @NotNull public String getName() {
85            return name;
86        }
87    }
88 
89    @Immutable
90    public static class MapSource<T> implements Source<T> {
91        private final Map<String, T> map;
92 
93        public MapSource(@NotNull Map<String, T> map ) {
94            this.map = map;
95        }
96 
97        @NotNull public Set<String> getNames() {
98            return map.keySet();
99        }
100 
101        public T getValue(@NotNull String name) {
102            return map.get(name);
103        }
104 
105        @NotNull public String getName() {
106            Object obj = getValue("name");
107            if (obj == null)
108                return toString();
109            return obj.toString();
110        }
111 
112        public boolean equals(Object o) {
113            if (this == o) return true;
114            if (o == null || getClass() != o.getClass()) return false;
115            MapSource mapSource = (MapSource) o;
116            return map.equals(mapSource.map);
117        }
118 
119        public int hashCode() {
120            return map.hashCode() * 17;
121        }
122 
123        public String toString() {
124            return "MapSource "+map;
125        }
126    }
127 
128/*
129    @Immutable
130    public static class PairedSource<T> extends Pair<Source<T>, Source<T>> implements Source<T> {
131        public PairedSource(Source<T> first, Source<T> second) {
132            super(first, second);
133        }
134 
135        @NotNull public Set<String> getNames() {
136            Set<String> ret = new LinkedHashSet<String>(first.getNames());
137            ret.addAll(second.getNames());
138            return ret;
139        }
140 
141        public T getValue(@NotNull String name) throws NoSuchElementException {
142            try {
143                return first.getValue(name);
144            } catch (NoSuchElementException e) {
145                return second.getValue(name);
146            }        }
147 
148        @NotNull public String getName() {
149            try {
150                return (String) getValue("name");
151            } catch (NoSuchElementException ignored) {
152                return toString();
153            }
154        }
155    }
156*/
157}

[all classes][org.jtoolkit.essence.utils]
EMMA 2.0.5312 (C) Vladimir Roubtsov