Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1615 remove guava part 2 #112

Merged
@@ -0,0 +1,160 @@
/*
* Copyright 2020-2022 Equinix, Inc
* Copyright 2014-2022 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.commons.util.collect;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;
import java.util.stream.Collectors;

import org.killbill.commons.utils.Preconditions;

/**
* Replacement of Guava {@code EvictingQueue}, some behavior may different from original one.
*/
public class EvictingQueue<E> implements Queue<E> {
xsalefter marked this conversation as resolved.
Show resolved Hide resolved

private final int maxSize;
private final Queue<E> delegate;

public EvictingQueue(final int maxSize) {
this.maxSize = maxSize;
this.delegate = new ArrayDeque<>();
}

/**
* Returns the number of additional elements that this queue can accept without evicting; zero if
* the queue is currently full.
*/
public int remainingCapacity() {
return maxSize - size();
}

@Override
public int size() {
return delegate.size();
}

@Override
public boolean isEmpty() {
return delegate.isEmpty();
}

@Override
public boolean contains(final Object o) {
return delegate.contains(o);
}

@Override
public Iterator<E> iterator() {
return delegate.iterator();
}

@Override
public Object[] toArray() {
return delegate.toArray();
}

@Override
public <T> T[] toArray(final T[] array) {
return delegate.toArray(array);
}

@Override
public boolean add(final E element) {
Preconditions.checkNotNull(element);
if (maxSize == 0) {
return true;
}
if (size() == maxSize) {
delegate.remove();
}
delegate.add(element);
return true;
}

@Override
public boolean remove(final Object o) {
return delegate.remove(o);
}

@Override
public boolean containsAll(final Collection<?> collection) {
return delegate.containsAll(collection);
}

// Different implementation from original EvictingQueue.
@Override
public boolean addAll(final Collection<? extends E> collection) {
if (collection.isEmpty()) {
return false;
}
final int size = collection.size();
if (size >= maxSize) {
clear();
collection.stream()
.skip(size - maxSize)
.collect(Collectors.toUnmodifiableList())
.forEach(this::add);
} else {
collection.forEach(this::add);
}
return true;
}

@Override
public boolean removeAll(final Collection<?> c) {
return delegate.removeAll(c);
}

@Override
public boolean retainAll(final Collection<?> c) {
return delegate.retainAll(c);
}

@Override
public void clear() {
delegate.clear();
}

@Override
public boolean offer(final E e) {
return add(e);
}

@Override
public E remove() {
return delegate.remove();
}

@Override
public E poll() {
return delegate.poll();
}

@Override
public E element() {
return delegate.element();
}

@Override
public E peek() {
return delegate.peek();
}
}
38 changes: 0 additions & 38 deletions base/src/main/java/org/killbill/commons/util/io/Files.java

This file was deleted.

This file was deleted.

Expand Up @@ -40,7 +40,7 @@
import org.killbill.commons.utils.cache.Cache;
import org.killbill.commons.utils.cache.DefaultCache;
import org.killbill.commons.utils.cache.DefaultSynchronizedCache;
import org.killbill.commons.util.reflect.AbstractInvocationHandler;
import org.killbill.commons.utils.reflect.AbstractInvocationHandler;

public class ContextClassLoaderHelper {

Expand Down
Expand Up @@ -19,6 +19,7 @@

package org.killbill.billing.osgi.glue;

import javax.inject.Provider;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
Expand Down Expand Up @@ -54,7 +55,6 @@
import org.osgi.service.http.HttpService;
import org.skife.config.ConfigurationObjectFactory;

import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down
Expand Up @@ -19,15 +19,13 @@

package org.killbill.billing.osgi.pluginconf;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.killbill.billing.osgi.api.config.PluginConfig;
import org.killbill.commons.util.io.Files;
import org.killbill.commons.utils.io.Files;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down