de.codesourcery.versiontracker.common.QueryRequest Maven / Gradle / Ivy
/**
* Copyright 2018 Tobias Gierke
*
* 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.
*/
package de.codesourcery.versiontracker.common;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* API request that looks for updates for a given set of artifacts.
*
* @author [email protected]
*/
public class QueryRequest extends APIRequest
{
public List artifacts = new ArrayList<>();
public Blacklist blacklist;
public QueryRequest()
{
super(Command.QUERY);
}
public boolean equals(Object obj)
{
if ( obj instanceof QueryRequest o ) {
if ( this.artifacts.size() != o.artifacts.size() ) {
return false;
}
for ( Artifact a1 : this.artifacts ) {
if ( o.artifacts.stream().noneMatch( x -> x.equals(a1) ) ) {
return false;
}
}
if ( this.blacklist == null || o.blacklist == null ) {
return this.blacklist == o.blacklist;
}
return this.blacklist.equals( o.blacklist );
}
return false;
}
@Override
protected void doSerialize(BinarySerializer serializer) throws IOException
{
serializer.writeInt( artifacts.size() );
for ( Artifact a : artifacts ) {
a.serialize( serializer );
}
// TODO: Serialize blacklist
blacklist.serialize( serializer );
}
static QueryRequest doDeserialize(BinarySerializer serializer) throws IOException {
final QueryRequest result = new QueryRequest();
for ( int count = serializer.readInt() ; count > 0 ; count--)
{
final Artifact artifact = Artifact.deserialize( serializer );
result.artifacts.add( artifact );
}
result.blacklist = Blacklist.deserialize(serializer);
return result;
}
}