fix eol-style

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1523477 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-09-15 19:00:54 +00:00
parent 71eacd238c
commit 4b1a7ebc7c
2 changed files with 1130 additions and 1130 deletions

View File

@ -1,84 +1,84 @@
package org.apache.lucene.util; package org.apache.lucene.util;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/** /**
* Manages reference counting for a given object. Extensions can override * Manages reference counting for a given object. Extensions can override
* {@link #release()} to do custom logic when reference counting hits 0. * {@link #release()} to do custom logic when reference counting hits 0.
*/ */
public class RefCount<T> { public class RefCount<T> {
private final AtomicInteger refCount = new AtomicInteger(1); private final AtomicInteger refCount = new AtomicInteger(1);
protected final T object; protected final T object;
public RefCount(T object) { public RefCount(T object) {
this.object = object; this.object = object;
} }
/** /**
* Called when reference counting hits 0. By default this method does nothing, * Called when reference counting hits 0. By default this method does nothing,
* but extensions can override to e.g. release resources attached to object * but extensions can override to e.g. release resources attached to object
* that is managed by this class. * that is managed by this class.
*/ */
protected void release() throws IOException {} protected void release() throws IOException {}
/** /**
* Decrements the reference counting of this object. When reference counting * Decrements the reference counting of this object. When reference counting
* hits 0, calls {@link #release()}. * hits 0, calls {@link #release()}.
*/ */
public final void decRef() throws IOException { public final void decRef() throws IOException {
final int rc = refCount.decrementAndGet(); final int rc = refCount.decrementAndGet();
if (rc == 0) { if (rc == 0) {
boolean success = false; boolean success = false;
try { try {
release(); release();
success = true; success = true;
} finally { } finally {
if (!success) { if (!success) {
// Put reference back on failure // Put reference back on failure
refCount.incrementAndGet(); refCount.incrementAndGet();
} }
} }
} else if (rc < 0) { } else if (rc < 0) {
throw new IllegalStateException("too many decRef calls: refCount is " + rc + " after decrement"); throw new IllegalStateException("too many decRef calls: refCount is " + rc + " after decrement");
} }
} }
public final T get() { public final T get() {
return object; return object;
} }
/** Returns the current reference count. */ /** Returns the current reference count. */
public final int getRefCount() { public final int getRefCount() {
return refCount.get(); return refCount.get();
} }
/** /**
* Increments the reference count. Calls to this method must be matched with * Increments the reference count. Calls to this method must be matched with
* calls to {@link #decRef()}. * calls to {@link #decRef()}.
*/ */
public final void incRef() { public final void incRef() {
refCount.incrementAndGet(); refCount.incrementAndGet();
} }
} }