Project

General

Profile

« Previous | Next » 

Revision 9a8f2111

Added by unknown about 5 years ago

Fix doc of isPartial

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/ImageFile.java
65 65
		if(imageInfo != null){
66 66
			imageFile.setHeight(imageInfo.getHeight());
67 67
			imageFile.setWidth(imageInfo.getWidth());
68
//			imageFile.setSize((int)imageInfo.getLength());
68 69
		}
69 70

  
70 71
		return imageFile;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/MediaUtils.java
36 36
        // find best matching representations of each media
37 37
        SortedMap<Integer, MediaRepresentation> prefRepresentations
38 38
                = filterAndOrderMediaRepresentations(media.getRepresentations(), null, mimeTypes,
39
                        size, widthOrDuration, height);
39
                        size, widthOrDuration, height, false);
40 40
        try {
41 41
            // take first one and remove all other representations
42 42
            MediaRepresentation prefOne = prefRepresentations.get(prefRepresentations.firstKey());
......
107 107
        return mediaRepresentationPart;
108 108
    }
109 109

  
110
    /**
111
     * @see #findPreferredMedia(List, Class, String[], String[], Integer, Integer, Integer, boolean)
112
     */
113
    public static Map<Media, MediaRepresentation> findPreferredMedia(List<Media> mediaList,
114
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypes, String[] sizeTokens,
115
            Integer widthOrDuration, Integer height, Integer size
116
            ) {
117
        return findPreferredMedia(mediaList, representationPartType, mimeTypes, sizeTokens,
118
                widthOrDuration, height, size, false);
119
    }
120

  
110 121

  
111 122
    /**
112 123
     * Filters the given List of Media by the supplied filter parameters <code>representationPartType</code>,
......
125 136
     * @param widthOrDuration
126 137
     * @param height
127 138
     * @param size
139
     * @param onlyBestMatchIfFilterMatches if <code>true</code> and all required filter parameters
140
     *      (like size, width and height) are not <code>null</code> only the best matching representation is returned.
141
     *       Otherwise all representations are returned in sorted order.
128 142
     * @return
129 143
     */
130 144
    public static Map<Media, MediaRepresentation> findPreferredMedia(List<Media> mediaList,
131 145
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypes, String[] sizeTokens,
132
            Integer widthOrDuration, Integer height, Integer size) {
146
            Integer widthOrDuration, Integer height, Integer size,
147
            boolean onlyBestMatchIfFilterMatches) {
133 148

  
134 149
        if(mimeTypes != null) {
135 150
            for(int i=0; i<mimeTypes.length; i++){
......
171 186

  
172 187
                SortedMap<Integer, MediaRepresentation> prefRepresentations
173 188
                    = filterAndOrderMediaRepresentations(candidateRepresentations, representationPartType,
174
                            mimeTypes, size, widthOrDuration, height);
189
                            mimeTypes, size, widthOrDuration, height, false);
175 190
                try {
176 191
                    if(prefRepresentations.size() > 0){
177 192
                        // Media.representations is a set
......
242 257
    }
243 258

  
244 259
    */
260

  
245 261
    /**
262
     * @param mediaRepresentations
263
     * @param representationPartType
246 264
     * @param mimeTypeRegexes
247 265
     * @param size
248 266
     * @param widthOrDuration
249 267
     * @param height
268
     * @param onlyBestMatchIfFilterMatches if <code>true</code> and all required filter parameters
269
     *      (like size, width and height) are not <code>null</code> only the best matching representation is returned.
270
     *       Otherwise all representations are returned in sorted order.
250 271
     * @return
251
     *
252
     *
253 272
     */
254 273
    private static SortedMap<Integer, MediaRepresentation> filterAndOrderMediaRepresentations(
255 274
            Set<MediaRepresentation> mediaRepresentations,
256 275
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypeRegexes,
257
            Integer size, Integer widthOrDuration, Integer height) {
276
            Integer size, Integer widthOrDuration, Integer height, boolean onlyBestMatchIfFilterMatches) {
258 277

  
259 278
        SortedMap<Integer, MediaRepresentation> prefRepr = new TreeMap<>();
260 279

  
......
264 283
        height = (height == null ? new Integer(0) : height);
265 284
        mimeTypeRegexes = (mimeTypeRegexes == null ? new String[]{".*"} : mimeTypeRegexes);
266 285

  
286
        boolean filterMatches = true;
267 287
        for (String mimeTypeRegex : mimeTypeRegexes) {
268 288
            // getRepresentationByMimeType
269 289
            Pattern mimeTypePattern = Pattern.compile(mimeTypeRegex);
......
280 300

  
281 301
                int dwa = 0;
282 302

  
283

  
284 303
                //first the size is used for comparison
285 304
                for (MediaRepresentationPart part : representation.getParts()) {
286 305

  
......
296 315
                    logger.debug(part + " matches");
297 316
                    matchingParts.add(part);
298 317

  
318
                    boolean partFilterMatches = false;
319

  
299 320
                    if (part.getSize()!= null){
300 321
                        int sizeOfPart = part.getSize();
301 322
                        int distance = sizeOfPart - size;
......
303 324
                            distance *= -1;
304 325
                        }
305 326
                        dwa += distance;
327
                        if (size > 0){
328
                            partFilterMatches = true;
329
                        }
306 330
                    }
307 331

  
308 332
                    //if height and width/duration is defined, add this information, too
......
327 351
                        }
328 352
                        dwa += durationWidthWeight;
329 353

  
354
                    }else{
355
                        partFilterMatches = true;
330 356
                    }
357
                    filterMatches &= partFilterMatches;
331 358
                } // loop parts
332 359
                logger.debug("matchingParts.size():" + matchingParts.size());
333 360
                if(matchingParts.size() > 0 ){
......
343 370
            } // loop representations
344 371
        } // loop mime types
345 372
        logger.debug(prefRepr.size() + " preferred representations found");
346
        return prefRepr;
373

  
374
        if (onlyBestMatchIfFilterMatches && filterMatches){
375
            SortedMap<Integer, MediaRepresentation> result = new TreeMap<>();
376
            try {
377
                result.put(prefRepr.firstKey(), prefRepr.get(prefRepr.firstKey()));
378
                return result;
379
            } catch (Exception e) {
380
                return result;
381
            }
382
        }else{
383
            return prefRepr;
384
        }
347 385
    }
348 386
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Synonym.java
192 192
    }
193 193

  
194 194
    /**
195
     * Returns "true" if the ProParte flag is set.
195
     * Returns "true" if the <cod>partial</code> flag is set.
196 196
     * This indicates that the {@link name.TaxonName taxon name} used as <code>this</code>
197 197
     * {@link Synonym synonym} designated originally a real taxon which later has
198 198
     * been lumped together with another one. In this case the

Also available in: Unified diff