it.tidalwave.integritychecker.archive.impl.InMemoryScanArchive Maven / Gradle / Ivy
/*
* #%L
* *********************************************************************************************************************
*
* SolidBlue - open source safe data
* http://solidblue.tidalwave.it - hg clone https://bitbucket.org/tidalwave/solidblue-src
* %%
* Copyright (C) 2011 - 2014 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* $Id$
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.integritychecker.archive.impl;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.joda.time.DateTime;
import org.openide.util.lookup.ServiceProvider;
import it.tidalwave.util.Finder;
import it.tidalwave.util.spi.FinderSupport;
import it.tidalwave.integritychecker.archive.Scan;
import it.tidalwave.integritychecker.archive.ScanArchive;
/***********************************************************************************************************************
*
* An implementation of {@link ScanArchive} based on an in-memory representation.
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@ServiceProvider(service=ScanArchive.class)
public class InMemoryScanArchive implements ScanArchive
{
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
class InMemoryScanFinder extends FinderSupport implements ScanFinder
{
@CheckForNull
private DateTime dateTime;
@Override @Nonnull
public InMemoryScanFinder clone()
{
final InMemoryScanFinder clone = (InMemoryScanFinder)super.clone();
clone.dateTime = this.dateTime;
return clone;
}
@Override @Nonnull
public ScanFinder withDateTime (@Nonnull DateTime dateTime)
{
final InMemoryScanFinder clone = clone();
clone.dateTime = dateTime;
return clone;
}
@Override @Nonnull
protected List extends Scan> computeNeededResults()
{
final List result = new ArrayList<>();
if (dateTime != null)
{
final Scan scan = scanMapByDateTime.get(dateTime);
if (scan != null)
{
result.add(scan);
}
}
else
{
result.addAll(scanMapByDateTime.values());
}
return result;
}
}
private final Map scanMapByDateTime = new HashMap<>();
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public Scan.Builder addScan()
{
return new Scan.Builder(new Scan.Builder.ScanFactory()
{
@Override
public Scan create (final @Nonnull DateTime beginScanDateTime)
{
final Scan scan = new InMemoryScan();
scanMapByDateTime.put(scan.getBeginScanDateTime(), scan);
return scan;
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Finder find()
{
return new InMemoryScanFinder();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy