• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ben-manes / caffeine / #5156

03 Dec 2025 03:21AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5156

push

github

ben-manes
add loading type to parameterized test dimensions to reduce task size

0 of 3834 branches covered (0.0%)

0 of 7848 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LinkedDeque.java
1
/*
2
 * Copyright 2014 Ben Manes. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.benmanes.caffeine.cache;
17

18
import java.util.Comparator;
19
import java.util.ConcurrentModificationException;
20
import java.util.Deque;
21
import java.util.Iterator;
22
import java.util.NoSuchElementException;
23

24
import org.jspecify.annotations.Nullable;
25

26
/**
27
 * A linked list extension of the {@link Deque} interface where the link pointers are tightly
28
 * integrated with the element. Linked deques have no capacity restrictions; they grow as necessary
29
 * to support usage. They are not thread-safe; in the absence of external synchronization, they do
30
 * not support concurrent access by multiple threads. Null elements are prohibited.
31
 * <p>
32
 * Most {@code LinkedDeque} operations run in constant time by assuming that the element parameter
33
 * is associated with the deque instance. Any usage that violates this assumption will result in
34
 * non-deterministic behavior.
35
 * <p>
36
 * An element can exist in only one instance of a deque implementation, but may exist in multiple
37
 * implementations. Each implementation must define unique names for accessing and modifying its
38
 * link pointers.
39
 * <p>
40
 * The iterators returned by this class are <i>fail-fast</i>: If the deque is structurally modified
41
 * at any time after the iterator is created, in any way except through the iterator's own
42
 * {@link Iterator#remove() remove} method, then the iterator will throw a
43
 * {@link ConcurrentModificationException}. Thus, in the face of concurrent modification, the
44
 * iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at
45
 * an undetermined time in the future. Note that the fail-fast behavior of an iterator cannot be
46
 * guaranteed and should be used only to detect bugs.
47
 *
48
 * @author ben.manes@gmail.com (Ben Manes)
49
 * @param <E> the type of elements held in this collection
50
 */
51
interface LinkedDeque<E> extends Deque<E> {
52

53
  /**
54
   * Returns if the element is at the front of the deque.
55
   *
56
   * @param e the linked element
57
   */
58
  boolean isFirst(@Nullable E e);
59

60
  /**
61
   * Returns if the element is at the back of the deque.
62
   *
63
   * @param e the linked element
64
   */
65
  boolean isLast(@Nullable E e);
66

67
  /**
68
   * Moves the element to the front of the deque so that it becomes the first element.
69
   *
70
   * @param e the linked element
71
   */
72
  void moveToFront(E e);
73

74
  /**
75
   * Moves the element to the back of the deque so that it becomes the last element.
76
   *
77
   * @param e the linked element
78
   */
79
  void moveToBack(E e);
80

81
  /**
82
   * Retrieves the previous element or {@code null} if either the element is unlinked or the first
83
   * element on the deque.
84
   */
85
  @Nullable E getPrevious(E e);
86

87
  /** Sets the previous element or {@code null} if there is no link. */
88
  void setPrevious(E e, @Nullable E prev);
89

90
  /**
91
   * Retrieves the next element or {@code null} if either the element is unlinked or the last
92
   * element on the deque.
93
   */
94
  @Nullable E getNext(E e);
95

96
  /** Sets the next element or {@code null} if there is no link. */
97
  void setNext(E e, @Nullable E next);
98

99
  @Override
100
  PeekingIterator<E> iterator();
101

102
  @Override
103
  PeekingIterator<E> descendingIterator();
104

105
  interface PeekingIterator<E> extends Iterator<E> {
106

107
    /** Returns the next element in the iteration, without advancing the iteration. */
108
    @Nullable E peek();
109

110
    /** Returns an iterator that returns the first iteration followed by the second iteration. */
111
    static <E> PeekingIterator<E> concat(PeekingIterator<E> first, PeekingIterator<E> second) {
112
      return new PeekingIterator<>() {
×
113
        @Override public boolean hasNext() {
114
          return first.hasNext() || second.hasNext();
×
115
        }
116
        @Override public E next() {
117
          if (first.hasNext()) {
×
118
            return first.next();
×
119
          } else if (second.hasNext()) {
×
120
            return second.next();
×
121
          }
122
          throw new NoSuchElementException();
×
123
        }
124
        @Override public @Nullable E peek() {
125
          return first.hasNext() ? first.peek() : second.peek();
×
126
        }
127
      };
128
    }
129

130
    /** Returns an iterator that selects the greater element from the backing iterators. */
131
    static <E> PeekingIterator<E> comparing(PeekingIterator<E> first,
132
          PeekingIterator<E> second, Comparator<E> comparator) {
133
      return new PeekingIterator<>() {
×
134
        @Override public boolean hasNext() {
135
          return first.hasNext() || second.hasNext();
×
136
        }
137
        @Override public E next() {
138
          if (!first.hasNext()) {
×
139
            return second.next();
×
140
          } else if (!second.hasNext()) {
×
141
            return first.next();
×
142
          }
143
          E o1 = first.peek();
×
144
          E o2 = second.peek();
×
145
          boolean greaterOrEqual = (comparator.compare(o1, o2) >= 0);
×
146
          return greaterOrEqual ? first.next() : second.next();
×
147
        }
148
        @Override public @Nullable E peek() {
149
          if (!first.hasNext()) {
×
150
            return second.peek();
×
151
          } else if (!second.hasNext()) {
×
152
            return first.peek();
×
153
          }
154
          E o1 = first.peek();
×
155
          E o2 = second.peek();
×
156
          boolean greaterOrEqual = (comparator.compare(o1, o2) >= 0);
×
157
          return greaterOrEqual ? o1 : o2;
×
158
        }
159
      };
160
    }
161
  }
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc