Lines 53-59
Link Here
|
53 |
import java.util.Arrays; |
53 |
import java.util.Arrays; |
54 |
import java.util.Collection; |
54 |
import java.util.Collection; |
55 |
import java.util.Collections; |
55 |
import java.util.Collections; |
56 |
import java.util.HashMap; |
|
|
57 |
import java.util.HashSet; |
56 |
import java.util.HashSet; |
58 |
import java.util.Iterator; |
57 |
import java.util.Iterator; |
59 |
import java.util.LinkedHashMap; |
58 |
import java.util.LinkedHashMap; |
Lines 65-71
Link Here
|
65 |
import java.util.concurrent.Future; |
64 |
import java.util.concurrent.Future; |
66 |
import java.util.concurrent.FutureTask; |
65 |
import java.util.concurrent.FutureTask; |
67 |
import java.util.concurrent.RunnableFuture; |
66 |
import java.util.concurrent.RunnableFuture; |
68 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
69 |
import java.util.jar.Attributes; |
67 |
import java.util.jar.Attributes; |
70 |
import java.util.jar.Manifest; |
68 |
import java.util.jar.Manifest; |
71 |
import java.util.logging.Level; |
69 |
import java.util.logging.Level; |
Lines 79-84
Link Here
|
79 |
import org.netbeans.api.annotations.common.NullAllowed; |
77 |
import org.netbeans.api.annotations.common.NullAllowed; |
80 |
import org.netbeans.api.java.classpath.ClassPath; |
78 |
import org.netbeans.api.java.classpath.ClassPath; |
81 |
import org.netbeans.api.java.queries.SourceLevelQuery; |
79 |
import org.netbeans.api.java.queries.SourceLevelQuery; |
|
|
80 |
import org.netbeans.api.java.queries.SourceLevelQuery.Profile; |
82 |
import org.netbeans.api.project.FileOwnerQuery; |
81 |
import org.netbeans.api.project.FileOwnerQuery; |
83 |
import org.netbeans.api.project.Project; |
82 |
import org.netbeans.api.project.Project; |
84 |
import org.netbeans.api.project.ProjectManager; |
83 |
import org.netbeans.api.project.ProjectManager; |
Lines 109-114
Link Here
|
109 |
import org.openide.filesystems.URLMapper; |
108 |
import org.openide.filesystems.URLMapper; |
110 |
import org.openide.util.ImageUtilities; |
109 |
import org.openide.util.ImageUtilities; |
111 |
import org.openide.util.RequestProcessor; |
110 |
import org.openide.util.RequestProcessor; |
|
|
111 |
import org.openide.util.Union2; |
112 |
/** |
112 |
/** |
113 |
* |
113 |
* |
114 |
* @author Tomas Zezula |
114 |
* @author Tomas Zezula |
Lines 192-210
Link Here
|
192 |
@Override |
192 |
@Override |
193 |
public Collection<? extends ProjectProblem> run() { |
193 |
public Collection<? extends ProjectProblem> run() { |
194 |
final SourceLevelQuery.Result mySL = listenenOnProjectMetadata(); |
194 |
final SourceLevelQuery.Result mySL = listenenOnProjectMetadata(); |
195 |
final Profile profile = StandardProfile.forName(mySL.getProfile()); |
195 |
final Profile profile = mySL.getProfile(); |
196 |
if (!profile.isValid() || profile == StandardProfile.DEFAULT) { |
196 |
if (profile == Profile.DEFAULT) { |
197 |
return Collections.<ProjectProblem>emptySet(); |
197 |
return Collections.<ProjectProblem>emptySet(); |
198 |
} |
198 |
} |
199 |
final Set<Reference> problems = collectReferencesWithWrongProfile(profile); |
199 |
final Set<Reference> problems = collectReferencesWithWrongProfile(profile); |
200 |
if (problems.isEmpty()) { |
200 |
if (problems.isEmpty()) { |
201 |
return Collections.<ProjectProblem>emptySet(); |
201 |
return Collections.<ProjectProblem>emptySet(); |
202 |
} |
202 |
} |
203 |
final Profile minProfile = requiredProfile(problems, StandardProfile.forName("dummy")); //NOI18N |
203 |
Profile minProfile = null; |
|
|
204 |
for (Reference problem : problems) { |
205 |
final Profile problemProfile = problem.getRequiredProfile(); |
206 |
minProfile = max(minProfile, problemProfile); |
207 |
} |
204 |
return Collections.<ProjectProblem>singleton( |
208 |
return Collections.<ProjectProblem>singleton( |
205 |
ProjectProblem.createError( |
209 |
ProjectProblem.createError( |
206 |
LBL_InvalidProfile(), |
210 |
LBL_InvalidProfile(), |
207 |
minProfile.isValid() |
211 |
minProfile != null |
208 |
? DESC_InvalidProfile(profile.getDisplayName(), minProfile.getDisplayName()) |
212 |
? DESC_InvalidProfile(profile.getDisplayName(), minProfile.getDisplayName()) |
209 |
: DESC_IllegalProfile(), |
213 |
: DESC_IllegalProfile(), |
210 |
new ProfileResolver( |
214 |
new ProfileResolver( |
Lines 322-329
Link Here
|
322 |
final String libName = rawEntry.substring(LIB_PREFIX.length(),rawEntry.lastIndexOf('.')); |
326 |
final String libName = rawEntry.substring(LIB_PREFIX.length(),rawEntry.lastIndexOf('.')); |
323 |
final Library lib = refHelper.findLibrary(libName); |
327 |
final Library lib = refHelper.findLibrary(libName); |
324 |
if (lib != null) { |
328 |
if (lib != null) { |
325 |
final Profile minProfile = findProfile(lib.getContent(VOL_CLASSPATH)); |
329 |
final Union2<Profile,String> minProfileOrName = findProfile(lib.getContent(VOL_CLASSPATH)); |
326 |
if (isBroken(requiredProfile, minProfile)) { |
330 |
final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null; |
|
|
331 |
if (isBroken(requiredProfile, minProfile)) { |
327 |
collector.add(new LibraryReference(classPathId, rawEntry, minProfile, lib)); |
332 |
collector.add(new LibraryReference(classPathId, rawEntry, minProfile, lib)); |
328 |
} |
333 |
} |
329 |
} |
334 |
} |
Lines 333-339
Link Here
|
333 |
AntArtifact artifact = (AntArtifact)ref[0]; |
338 |
AntArtifact artifact = (AntArtifact)ref[0]; |
334 |
final SourceLevelQuery.Result slRes = SourceLevelQuery.getSourceLevel2(artifact.getProject().getProjectDirectory()); |
339 |
final SourceLevelQuery.Result slRes = SourceLevelQuery.getSourceLevel2(artifact.getProject().getProjectDirectory()); |
335 |
slResCollector.add(slRes); |
340 |
slResCollector.add(slRes); |
336 |
final Profile minProfile = StandardProfile.forName(slRes.getProfile()); |
341 |
final Profile minProfile = slRes.getProfile(); |
337 |
if (isBroken(requiredProfile, minProfile)) { |
342 |
if (isBroken(requiredProfile, minProfile)) { |
338 |
collector.add(new ProjectReference(classPathId, rawEntry, minProfile, artifact.getProject())); |
343 |
collector.add(new ProjectReference(classPathId, rawEntry, minProfile, artifact.getProject())); |
339 |
} |
344 |
} |
Lines 345-351
Link Here
|
345 |
final File file = antProjectHelper.resolveFile(path); |
350 |
final File file = antProjectHelper.resolveFile(path); |
346 |
final URL root = FileUtil.urlForArchiveOrDir(file); |
351 |
final URL root = FileUtil.urlForArchiveOrDir(file); |
347 |
if (root != null) { |
352 |
if (root != null) { |
348 |
final Profile minProfile = findProfile(root); |
353 |
final Union2<Profile,String> minProfileOrName = findProfile(root); |
|
|
354 |
final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null; |
349 |
if (isBroken(requiredProfile, minProfile)) { |
355 |
if (isBroken(requiredProfile, minProfile)) { |
350 |
collector.add(new FileReference(classPathId, rawEntry, minProfile, file)); |
356 |
collector.add(new FileReference(classPathId, rawEntry, minProfile, file)); |
351 |
} |
357 |
} |
Lines 367-373
Link Here
|
367 |
final File file = antProjectHelper.resolveFile(propName); |
373 |
final File file = antProjectHelper.resolveFile(propName); |
368 |
final URL root = FileUtil.urlForArchiveOrDir(file); |
374 |
final URL root = FileUtil.urlForArchiveOrDir(file); |
369 |
if (root != null) { |
375 |
if (root != null) { |
370 |
final Profile minProfile = findProfile(root); |
376 |
final Union2<Profile,String> minProfileOrName = findProfile(root); |
|
|
377 |
final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null; |
371 |
if (isBroken(requiredProfile, minProfile)) { |
378 |
if (isBroken(requiredProfile, minProfile)) { |
372 |
collector.add(new FileReference(classPathId, rawEntry, minProfile, file)); |
379 |
collector.add(new FileReference(classPathId, rawEntry, minProfile, file)); |
373 |
} |
380 |
} |
Lines 379-390
Link Here
|
379 |
|
386 |
|
380 |
private static boolean isBroken( |
387 |
private static boolean isBroken( |
381 |
@NonNull final Profile requiredProfile, |
388 |
@NonNull final Profile requiredProfile, |
382 |
@NonNull final Profile profile) { |
389 |
@NullAllowed final Profile profile) { |
383 |
if (!profile.isValid()) { |
390 |
if (profile == null) { |
384 |
return true; |
391 |
return true; |
385 |
} |
392 |
} |
386 |
final Profile max = max(requiredProfile, profile); |
393 |
final Profile max = max(requiredProfile, profile); |
387 |
return !max.equals(StandardProfile.DEFAULT) && |
394 |
return !max.equals(Profile.DEFAULT) && |
388 |
!max.equals(requiredProfile); |
395 |
!max.equals(requiredProfile); |
389 |
} |
396 |
} |
390 |
|
397 |
|
Lines 398-420
Link Here
|
398 |
return reference; |
405 |
return reference; |
399 |
} |
406 |
} |
400 |
|
407 |
|
401 |
@CheckForNull |
408 |
@NonNull |
402 |
private static Profile findProfile(@NonNull final Iterable<? extends URL> roots) { |
409 |
private static Union2<Profile,String> findProfile(@NonNull final Iterable<? extends URL> roots) { |
403 |
Profile current = StandardProfile.DEFAULT; |
410 |
Profile current = Profile.DEFAULT; |
404 |
for (URL root : roots) { |
411 |
for (URL root : roots) { |
405 |
final Profile rootProfile = findProfile(root); |
412 |
final Union2<Profile,String> rootProfile = findProfile(root); |
406 |
if (!rootProfile.isValid()) { |
413 |
if (!rootProfile.hasFirst()) { |
407 |
//Broken profile - no need to continue |
414 |
//Broken profile - no need to continue |
408 |
return rootProfile; |
415 |
return rootProfile; |
409 |
} |
416 |
} |
410 |
current = max(current, rootProfile); |
417 |
current = max(current, rootProfile.first()); |
411 |
} |
418 |
} |
412 |
return current; |
419 |
return Union2.<Profile,String>createFirst(current); |
413 |
} |
420 |
} |
414 |
|
421 |
|
415 |
@NonNull |
422 |
@NonNull |
416 |
private static Profile findProfile(@NonNull URL root) { |
423 |
private static Union2<Profile,String> findProfile(@NonNull URL root) { |
417 |
Profile res; |
424 |
Union2<Profile,String> res; |
418 |
final ArchiveCache.Key key = ArchiveCache.createKey(root); |
425 |
final ArchiveCache.Key key = ArchiveCache.createKey(root); |
419 |
if (key != null) { |
426 |
if (key != null) { |
420 |
res = ArchiveCache.getProfile(key); |
427 |
res = ArchiveCache.getProfile(key); |
Lines 422-440
Link Here
|
422 |
return res; |
429 |
return res; |
423 |
} |
430 |
} |
424 |
} |
431 |
} |
425 |
res = StandardProfile.DEFAULT; |
432 |
String profileName = null; |
426 |
final FileObject rootFo = URLMapper.findFileObject(root); |
433 |
final FileObject rootFo = URLMapper.findFileObject(root); |
427 |
if (rootFo != null) { |
434 |
if (rootFo != null) { |
428 |
final FileObject manifestFile = rootFo.getFileObject(RES_MANIFEST); |
435 |
final FileObject manifestFile = rootFo.getFileObject(RES_MANIFEST); |
429 |
if (manifestFile != null) { |
436 |
if (manifestFile != null) { |
430 |
try { |
437 |
try { |
431 |
final InputStream in = manifestFile.getInputStream(); |
438 |
try (InputStream in = manifestFile.getInputStream()) { |
432 |
try { |
|
|
433 |
final Manifest manifest = new Manifest(in); |
439 |
final Manifest manifest = new Manifest(in); |
434 |
final Attributes attrs = manifest.getMainAttributes(); |
440 |
final Attributes attrs = manifest.getMainAttributes(); |
435 |
res = StandardProfile.forName(attrs.getValue(ATTR_PROFILE)); |
441 |
profileName = attrs.getValue(ATTR_PROFILE); |
436 |
} finally { |
|
|
437 |
in.close(); |
438 |
} |
442 |
} |
439 |
} catch (IOException ioe) { |
443 |
} catch (IOException ioe) { |
440 |
LOG.log( |
444 |
LOG.log( |
Lines 444-449
Link Here
|
444 |
} |
448 |
} |
445 |
} |
449 |
} |
446 |
} |
450 |
} |
|
|
451 |
final Profile profile = Profile.forName(profileName); |
452 |
res = profile != null ? |
453 |
Union2.<Profile,String>createFirst(profile) : |
454 |
Union2.<Profile,String>createSecond(profileName); |
447 |
if (key != null) { |
455 |
if (key != null) { |
448 |
ArchiveCache.putProfile(key, res); |
456 |
ArchiveCache.putProfile(key, res); |
449 |
} |
457 |
} |
Lines 451-585
Link Here
|
451 |
} |
459 |
} |
452 |
|
460 |
|
453 |
|
461 |
|
454 |
@NonNull |
462 |
@CheckForNull |
455 |
static Profile max (@NonNull Profile a, @NonNull Profile b) { |
463 |
static Profile max (@NullAllowed Profile a, @NullAllowed Profile b) { |
456 |
return a.getRank() >= b.getRank() ? |
464 |
if (b == null) { |
457 |
a : |
465 |
return a; |
458 |
b; |
466 |
} |
|
|
467 |
if (a == null) { |
468 |
return b; |
469 |
} |
470 |
return a.compareTo(b) <= 0 ? |
471 |
b : |
472 |
a; |
459 |
} |
473 |
} |
460 |
|
474 |
|
461 |
@NonNull |
475 |
@NonNull |
462 |
static Profile requiredProfile( |
476 |
static Profile requiredProfile( |
463 |
@NonNull final Collection<? extends Reference> state, |
477 |
@NonNull final Collection<? extends Reference> state, |
464 |
@NonNull Profile current) { |
478 |
@NonNull Profile initial) { |
|
|
479 |
Profile current = initial; |
465 |
for (ProfileProblemsProviderImpl.Reference re : state) { |
480 |
for (ProfileProblemsProviderImpl.Reference re : state) { |
466 |
current = max(current, re.getRequiredProfile()); |
481 |
current = max(current, re.getRequiredProfile()); |
467 |
} |
482 |
} |
468 |
return current; |
483 |
return current; |
469 |
} |
484 |
} |
470 |
|
485 |
|
471 |
static interface Profile { |
|
|
472 |
@NonNull |
473 |
String getAntName(); |
474 |
@NonNull |
475 |
String getDisplayName(); |
476 |
boolean isValid(); |
477 |
int getRank(); |
478 |
} |
479 |
|
480 |
@NbBundle.Messages({ |
481 |
"NAME_Compact1=Compact 1", |
482 |
"NAME_Compact2=Compact 2", |
483 |
"NAME_Compact3=Compact 3", |
484 |
"NAME_FullJRE=Full JRE" |
485 |
}) |
486 |
static enum StandardProfile implements Profile { |
487 |
|
488 |
COMPACT1(1, "compact1", Bundle.NAME_Compact1()), |
489 |
COMPACT2(2, "compact2", Bundle.NAME_Compact2()), |
490 |
COMPACT3(3, "compact3", Bundle.NAME_Compact3()), |
491 |
DEFAULT(Integer.MAX_VALUE, "default", Bundle.NAME_FullJRE()); |
492 |
|
493 |
private static final Map<String,StandardProfile> profilesByName = |
494 |
new HashMap<String, StandardProfile>(); |
495 |
static { |
496 |
for (StandardProfile sp : values()) { |
497 |
profilesByName.put(sp.getAntName(), sp); |
498 |
} |
499 |
} |
500 |
|
501 |
private final int rank; |
502 |
private final String antName; |
503 |
private final String displayName; |
504 |
|
505 |
private StandardProfile( |
506 |
final int rank, |
507 |
@NonNull final String antName, |
508 |
@NonNull final String displayName) { |
509 |
this.rank = rank; |
510 |
this.antName = antName; |
511 |
this.displayName = displayName; |
512 |
} |
513 |
|
514 |
|
515 |
@Override |
516 |
@NonNull |
517 |
public String getAntName() { |
518 |
return antName; |
519 |
} |
520 |
|
521 |
@Override |
522 |
@NonNull |
523 |
public String getDisplayName() { |
524 |
return displayName; |
525 |
} |
526 |
|
527 |
@Override |
528 |
public int getRank() { |
529 |
return rank; |
530 |
} |
531 |
|
532 |
@Override |
533 |
public boolean isValid() { |
534 |
return true; |
535 |
} |
536 |
|
537 |
@NonNull |
538 |
static Profile forName(@NullAllowed String antName) { |
539 |
if (antName == null) { |
540 |
antName = DEFAULT.getAntName(); |
541 |
} |
542 |
Profile res = profilesByName.get(antName); |
543 |
if (res == null) { |
544 |
res = new UnknownProfile(antName); |
545 |
} |
546 |
return res; |
547 |
} |
548 |
|
549 |
|
550 |
private static class UnknownProfile implements Profile { |
551 |
|
552 |
private final String antName; |
553 |
|
554 |
UnknownProfile(@NonNull final String antName) { |
555 |
Parameters.notEmpty("antName", antName); //NOI18N |
556 |
this.antName = antName; |
557 |
} |
558 |
|
559 |
@Override |
560 |
public String getAntName() { |
561 |
return antName; |
562 |
} |
563 |
|
564 |
@Override |
565 |
public String getDisplayName() { |
566 |
return antName; |
567 |
} |
568 |
|
569 |
@Override |
570 |
public int getRank() { |
571 |
return Integer.MIN_VALUE; |
572 |
} |
573 |
|
574 |
@Override |
575 |
public boolean isValid() { |
576 |
return false; |
577 |
} |
578 |
} |
579 |
|
580 |
|
581 |
} |
582 |
|
583 |
abstract static class Reference { |
486 |
abstract static class Reference { |
584 |
|
487 |
|
585 |
private final String classPathId; |
488 |
private final String classPathId; |
Lines 589-609
Link Here
|
589 |
private Reference( |
492 |
private Reference( |
590 |
@NonNull final String classPathId, |
493 |
@NonNull final String classPathId, |
591 |
@NonNull final String rawId, |
494 |
@NonNull final String rawId, |
592 |
@NonNull final Profile requiredProfile) { |
495 |
@NullAllowed final Profile requiredProfile) { |
593 |
Parameters.notNull("classPathId", classPathId); //NOI18N |
496 |
Parameters.notNull("classPathId", classPathId); //NOI18N |
594 |
Parameters.notNull("rawId", rawId); //NOI18N |
497 |
Parameters.notNull("rawId", rawId); //NOI18N |
595 |
Parameters.notNull("requiredProfile", requiredProfile); //NOI18N |
|
|
596 |
this.classPathId = classPathId; |
498 |
this.classPathId = classPathId; |
597 |
this.rawId = rawId; |
499 |
this.rawId = rawId; |
598 |
this.requiredProfile = requiredProfile; |
500 |
this.requiredProfile = requiredProfile; |
599 |
} |
501 |
} |
600 |
|
502 |
|
|
|
503 |
@NonNull |
601 |
abstract String getDisplayName(); |
504 |
abstract String getDisplayName(); |
602 |
|
505 |
|
|
|
506 |
@NonNull |
603 |
abstract String getToolTipText(); |
507 |
abstract String getToolTipText(); |
604 |
|
508 |
|
|
|
509 |
@NonNull |
605 |
abstract Icon getIcon(); |
510 |
abstract Icon getIcon(); |
606 |
|
511 |
|
|
|
512 |
@CheckForNull |
607 |
final Profile getRequiredProfile() { |
513 |
final Profile getRequiredProfile() { |
608 |
return requiredProfile; |
514 |
return requiredProfile; |
609 |
} |
515 |
} |
Lines 664-670
Link Here
|
664 |
private LibraryReference( |
570 |
private LibraryReference( |
665 |
@NonNull final String classPathId, |
571 |
@NonNull final String classPathId, |
666 |
@NonNull final String rawId, |
572 |
@NonNull final String rawId, |
667 |
@NonNull final Profile requiredProfile, |
573 |
@NullAllowed final Profile requiredProfile, |
668 |
@NonNull final Library lib) { |
574 |
@NonNull final Library lib) { |
669 |
super(classPathId, rawId, requiredProfile); |
575 |
super(classPathId, rawId, requiredProfile); |
670 |
Parameters.notNull("lib", lib); //NOI18N |
576 |
Parameters.notNull("lib", lib); //NOI18N |
Lines 693-699
Link Here
|
693 |
private ProjectReference( |
599 |
private ProjectReference( |
694 |
@NonNull final String classPathId, |
600 |
@NonNull final String classPathId, |
695 |
@NonNull final String rawId, |
601 |
@NonNull final String rawId, |
696 |
@NonNull final Profile requiredProfile, |
602 |
@NullAllowed final Profile requiredProfile, |
697 |
@NonNull final Project prj) { |
603 |
@NonNull final Project prj) { |
698 |
super(classPathId, rawId, requiredProfile); |
604 |
super(classPathId, rawId, requiredProfile); |
699 |
Parameters.notNull("prj", prj); //NOI18N |
605 |
Parameters.notNull("prj", prj); //NOI18N |
Lines 723-729
Link Here
|
723 |
private FileReference( |
629 |
private FileReference( |
724 |
@NonNull final String classPathId, |
630 |
@NonNull final String classPathId, |
725 |
@NonNull final String rawId, |
631 |
@NonNull final String rawId, |
726 |
@NonNull final Profile requiredProfile, |
632 |
@NullAllowed final Profile requiredProfile, |
727 |
@NonNull final File file) { |
633 |
@NonNull final File file) { |
728 |
super(classPathId, rawId, requiredProfile); |
634 |
super(classPathId, rawId, requiredProfile); |
729 |
Parameters.notNull("file", file); //NOI18N |
635 |
Parameters.notNull("file", file); //NOI18N |
Lines 806-815
Link Here
|
806 |
final Profile newProfile = panel.getProfile(); |
712 |
final Profile newProfile = panel.getProfile(); |
807 |
final EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
713 |
final EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
808 |
if (newProfile == null || |
714 |
if (newProfile == null || |
809 |
newProfile == StandardProfile.DEFAULT) { |
715 |
newProfile == Profile.DEFAULT) { |
810 |
props.remove(profileProperty); |
716 |
props.remove(profileProperty); |
811 |
} else { |
717 |
} else { |
812 |
props.put(profileProperty, newProfile.getAntName()); |
718 |
props.put(profileProperty, newProfile.getName()); |
813 |
} |
719 |
} |
814 |
antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
720 |
antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
815 |
} |
721 |
} |
Lines 848-856
Link Here
|
848 |
"ProfileProblemsProviderImpl.ArchiveCache.size", //NOI18N |
754 |
"ProfileProblemsProviderImpl.ArchiveCache.size", //NOI18N |
849 |
1<<10); |
755 |
1<<10); |
850 |
|
756 |
|
851 |
private static final Map<Key,Profile> cache = new LinkedHashMap<Key, Profile>(16, 0.75f, true) { |
757 |
private static final Map<Key,Union2<Profile,String>> cache = new LinkedHashMap<Key,Union2<Profile,String>>(16, 0.75f, true) { |
852 |
@Override |
758 |
@Override |
853 |
protected boolean removeEldestEntry(Map.Entry<Key, Profile> entry) { |
759 |
protected boolean removeEldestEntry(Map.Entry<Key, Union2<Profile,String>> entry) { |
854 |
return size() > MAX_CACHE_SIZE; |
760 |
return size() > MAX_CACHE_SIZE; |
855 |
} |
761 |
} |
856 |
}; |
762 |
}; |
Lines 858-886
Link Here
|
858 |
private ArchiveCache() {} |
764 |
private ArchiveCache() {} |
859 |
|
765 |
|
860 |
@CheckForNull |
766 |
@CheckForNull |
861 |
static Profile getProfile(@NonNull final Key key) { |
767 |
static Union2<Profile,String> getProfile(@NonNull final Key key) { |
862 |
final Profile res = cache.get(key); |
768 |
final Union2<Profile,String> res = cache.get(key); |
863 |
LOG.log( |
769 |
if (LOG.isLoggable(Level.FINER)) { |
864 |
Level.FINER, |
770 |
LOG.log( |
865 |
"cache[{0}]->{1}", //NOI18N |
771 |
Level.FINER, |
866 |
new Object[]{ |
772 |
"cache[{0}]->{1}", //NOI18N |
867 |
key, |
773 |
new Object[]{ |
868 |
res |
774 |
key, |
869 |
}); |
775 |
res.hasFirst() ? res.first() : res.second() |
|
|
776 |
}); |
777 |
} |
870 |
return res; |
778 |
return res; |
871 |
} |
779 |
} |
872 |
|
780 |
|
873 |
static void putProfile( |
781 |
static void putProfile( |
874 |
@NonNull final Key key, |
782 |
@NonNull final Key key, |
875 |
@NonNull final Profile profile) { |
783 |
@NonNull final Union2<Profile,String> profile) { |
876 |
LOG.log( |
784 |
if (LOG.isLoggable(Level.FINER)) { |
877 |
Level.FINER, |
785 |
LOG.log( |
878 |
"cache[{0}]<-{1}", //NOI18N |
786 |
Level.FINER, |
879 |
new Object[]{ |
787 |
"cache[{0}]<-{1}", //NOI18N |
880 |
key, |
788 |
new Object[]{ |
881 |
profile |
789 |
key, |
882 |
}); |
790 |
profile.hasFirst() ? profile.first() : profile.second() |
883 |
cache.put(key, profile); |
791 |
}); |
|
|
792 |
} |
793 |
cache.put(key,profile); |
884 |
} |
794 |
} |
885 |
|
795 |
|
886 |
@CheckForNull |
796 |
@CheckForNull |