public static WaveViewData buildWaveViewData(WaveId waveId, Set<WaveletId> waveletIds, Function<ReadableWaveletData, Boolean> matchesFunction, WaveMap waveMap) { WaveViewData view = WaveViewDataImpl.create(waveId); // Copy of the wave built up for search hits. for (WaveletId waveletId : waveletIds) { WaveletContainer waveletContainer = null; WaveletName waveletname = WaveletName.of(waveId, waveletId); // TODO (Yuri Z.) This loop collects all the wavelets that match the // query, so the view is determined by the query. Instead we should // look at the user's wave view and determine if the view matches the // query. try { waveletContainer = waveMap.getWavelet(waveletname); if ((waveletContainer == null) || !waveletContainer.applyFunction(matchesFunction)) { continue; } // Just keep adding all the relevant wavelets in this wave. view.addWavelet(waveletContainer.copyWaveletData()); } catch (WaveletStateException e) { LOG.warning("Failed to access wavelet " + waveletContainer.getWaveletName(), e); } } return view; }