From 61c1e67ccca2e31ff375c50acb5f4529eab998b9 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Mon, 11 May 2015 14:29:01 +0200 Subject: [PATCH] extracted FileChunkKey --- .../com/intellij/util/io/FileChunkKey.java | 65 +++++++++++++++++++ .../src/com/intellij/util/io/PoolPageKey.java | 41 +----------- 2 files changed, 67 insertions(+), 39 deletions(-) create mode 100644 platform/util/src/com/intellij/util/io/FileChunkKey.java diff --git a/platform/util/src/com/intellij/util/io/FileChunkKey.java b/platform/util/src/com/intellij/util/io/FileChunkKey.java new file mode 100644 index 000000000000..d1f834b26b21 --- /dev/null +++ b/platform/util/src/com/intellij/util/io/FileChunkKey.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * 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 com.intellij.util.io; + +import com.intellij.util.containers.ShareableKey; +import org.jetbrains.annotations.NotNull; + +class FileChunkKey implements Comparable>, ShareableKey { + private OwnerType owner; + private long offset; + + public FileChunkKey(OwnerType owner, long offset) { + this.owner = owner; + this.offset = offset; + } + + public int hashCode() { + return (int)(owner.hashCode() * 31 + offset); + } + + public OwnerType getOwner() { + return owner; + } + + public long getOffset() { + return offset; + } + + public boolean equals(final Object obj) { + if (getClass() != obj.getClass()) return false; + FileChunkKey k = (FileChunkKey)obj; + return k.owner == owner && k.offset == offset; + } + + public void setup(OwnerType owner, long offset) { + this.owner = owner; + this.offset = offset; + } + + @Override + public int compareTo(@NotNull final FileChunkKey o) { + if (owner != o.owner) { + return owner.hashCode() - o.owner.hashCode(); + } + return offset == o.offset ? 0 : offset - o.offset < 0 ? -1 : 1; + } + + @Override + public ShareableKey getStableCopy() { + return new FileChunkKey(owner, offset); + } +} diff --git a/platform/util/src/com/intellij/util/io/PoolPageKey.java b/platform/util/src/com/intellij/util/io/PoolPageKey.java index 3918bfd3dbd2..91ce0f3595c8 100644 --- a/platform/util/src/com/intellij/util/io/PoolPageKey.java +++ b/platform/util/src/com/intellij/util/io/PoolPageKey.java @@ -19,45 +19,8 @@ */ package com.intellij.util.io; -import org.jetbrains.annotations.NotNull; - -class PoolPageKey implements Comparable { - private RandomAccessDataFile owner; - private long offset; - +class PoolPageKey extends FileChunkKey { public PoolPageKey(final RandomAccessDataFile owner, final long offset) { - this.owner = owner; - this.offset = offset; - } - - public int hashCode() { - return (int)(owner.hashCode() * 31 + offset); - } - - public RandomAccessDataFile getOwner() { - return owner; - } - - public long getOffset() { - return offset; - } - - @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) - public boolean equals(final Object obj) { - PoolPageKey k = (PoolPageKey)obj; - return k.owner == owner && k.offset == offset; - } - - public void setup(RandomAccessDataFile owner, long offset) { - this.owner = owner; - this.offset = offset; - } - - @Override - public int compareTo(@NotNull final PoolPageKey o) { - if (owner != o.owner) { - return owner.hashCode() - o.owner.hashCode(); - } - return offset == o.offset ? 0 : offset - o.offset < 0 ? -1 : 1; + super(owner, offset); } } \ No newline at end of file