java.util.AbstractList Java Examples

The following examples show how to use java.util.AbstractList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastArray.java    From groovy with Apache License 2.0 7 votes vote down vote up
public List toList () {
    if (size==0) {
        return Collections.emptyList();
    } else if (size==1) {
        return Collections.singletonList(data[0]);
    }
    return new AbstractList() {

        public Object get(int index) {
            return FastArray.this.get(index);
        }

        public int size() {
            return size;
        }
    };
}
 
Example #2
Source File: SqlParserPos.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Combines a list of parser positions to create a position which spans
 * from the beginning of the first to the end of the last.
 */
private static SqlParserPos sum_(final List<SqlParserPos> positions) {
  switch (positions.size()) {
  case 0:
    throw new AssertionError();
  case 1:
    return positions.get(0);
  default:
    final List<SqlParserPos> poses = new AbstractList<SqlParserPos>() {
      public SqlParserPos get(int index) {
        return positions.get(index + 1);
      }
      public int size() {
        return positions.size() - 1;
      }
    };
    final SqlParserPos p = positions.get(0);
    return sum(poses, p.lineNumber, p.columnNumber, p.endLineNumber,
        p.endColumnNumber);
  }
}
 
Example #3
Source File: JsonUtils.java    From flow with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a stream from a JSON array.
 *
 * @param <T>
 *            the stream type
 * @param array
 *            the JSON array to create a stream from
 * @return a stream of JSON values
 */
public static <T extends JsonValue> Stream<T> stream(JsonArray array) {
    if (array == null) {
        return Stream.empty();
    }

    return new AbstractList<T>() {
        @Override
        public T get(int index) {
            return array.get(index);
        }

        @Override
        public int size() {
            return array.length();
        }
    }.stream();
}
 
Example #4
Source File: IntPair.java    From Quicksql with MIT License 6 votes vote down vote up
/**
 * Converts two lists into a list of {@link IntPair}s.
 *
 * <p>The length of the combined list is the lesser of the lengths of the
 * source lists. But typically the source lists will be the same length.</p>
 *
 * @param lefts Left list
 * @param rights Right list
 * @param strict Whether to fail if lists have different size
 * @return List of pairs
 */
public static List<IntPair> zip(
    final List<? extends Number> lefts,
    final List<? extends Number> rights,
    boolean strict) {
  final int size;
  if (strict) {
    if (lefts.size() != rights.size()) {
      throw new AssertionError();
    }
    size = lefts.size();
  } else {
    size = Math.min(lefts.size(), rights.size());
  }
  return new AbstractList<IntPair>() {
    public IntPair get(int index) {
      return IntPair.of(lefts.get(index).intValue(),
          rights.get(index).intValue());
    }

    public int size() {
      return size;
    }
  };
}
 
Example #5
Source File: ImmutableBitSet.java    From Quicksql with MIT License 6 votes vote down vote up
/** Creates a view onto this bit set as a list of integers.
 *
 * <p>The {@code cardinality} and {@code get} methods are both O(n), but
 * the iterator is efficient. The list is memory efficient, and the CPU cost
 * breaks even (versus {@link #toList}) if you intend to scan it only once. */
public List<Integer> asList() {
  return new AbstractList<Integer>() {
    @Override public Integer get(int index) {
      return nth(index);
    }

    @Override public int size() {
      return cardinality();
    }

    @Nonnull @Override public Iterator<Integer> iterator() {
      return ImmutableBitSet.this.iterator();
    }
  };
}
 
Example #6
Source File: StringLib.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
@TLFunctionAnnotation("Tries to match entire input with specified pattern.")
public static final List<String> matchGroups(TLFunctionCallContext context, String input, String pattern) {
	if(input == null){
		return null;
	}
	final Matcher m = ((TLRegexpCache)context.getCache()).getCachedPattern(context, pattern).matcher(input);
	if (m.matches()) {
		return new AbstractList<String>() {

			@Override
			public String get(int index) {
				return m.group(index);
			}

			@Override
			public int size() {
				return m.groupCount() + 1; // group 0 is not included in groupCount()
			}
			
		};
	} else {
		return null;
	}
}
 
Example #7
Source File: EditorDetailsProvider.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List getValues() {
    final List origValues = buffer.getValues();

    return new AbstractList() {

        @Override
        public Object get(int index) {
            return origValues.get(rawOffset(index));
        }

        @Override
        public int size() {
            return getLength();
        }
    };
}
 
Example #8
Source File: GruntParser.java    From spork with Apache License 2.0 6 votes vote down vote up
@Override
protected void processFsCommand(String[] cmdTokens) throws IOException {
    filter.validate(PigCommandFilter.Command.FS);
    if(mExplain == null) { // process only if not in "explain" mode

        executeBatch();

        int retCode = -1;

        try {
            retCode = shell.run(cmdTokens);
        } catch (Exception e) {
            throw new IOException(e);
        }

        if (retCode != 0 && !mInteractive) {
            String s = LoadFunc.join(
                    (AbstractList<String>) Arrays.asList(cmdTokens), " ");
            throw new IOException("fs command '" + s
                    + "' failed. Please check output logs for details");
        }
    } else {
        log.warn("'fs' statement is ignored while processing 'explain -script' or '-check'");
    }
}
 
Example #9
Source File: VTableFactory.java    From diirt with MIT License 6 votes vote down vote up
public static VTable select(final VTable table, final ListInt indexes) {
    List<String> names = columnNames(table);
    List<Class<?>> types = columnTypes(table);
    List<Object> data = new AbstractList<Object>() {

        @Override
        public Object get(int index) {
            return selectColumnData(table, index, indexes);
        }

        @Override
        public int size() {
            return table.getColumnCount();
        }
    };
    return ValueFactory.newVTable(types, names, data);
}
 
Example #10
Source File: Throwables.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@GwtIncompatible // invokeAccessibleNonThrowingMethod
private static List<StackTraceElement> jlaStackTrace(final Throwable t) {
  checkNotNull(t);
  /*
   * TODO(cpovirk): Consider optimizing iterator() to catch IOOBE instead of doing bounds checks.
   *
   * TODO(cpovirk): Consider the UnsignedBytes pattern if it performs faster and doesn't cause
   * AOSP grief.
   */
  return new AbstractList<StackTraceElement>() {
    @Override
    public StackTraceElement get(int n) {
      return (StackTraceElement) invokeAccessibleNonThrowingMethod(getStackTraceElementMethod, jla, t, n);
    }

    @Override
    public int size() {
      return (Integer) invokeAccessibleNonThrowingMethod(getStackTraceDepthMethod, jla, t);
    }
  };
}
 
Example #11
Source File: EnumerableDefaults.java    From Quicksql with MIT License 6 votes vote down vote up
/**
 * Inverts the order of the elements in a
 * sequence.
 */
public static <TSource> Enumerable<TSource> reverse(
    Enumerable<TSource> source) {
  final List<TSource> list = toList(source);
  final int n = list.size();
  return Linq4j.asEnumerable(
      new AbstractList<TSource>() {
        public TSource get(int index) {
          return list.get(n - 1 - index);
        }

        public int size() {
          return n;
        }
      });
}
 
Example #12
Source File: DataTable.java    From cucumber with MIT License 6 votes vote down vote up
@Override
public List<String> get(final int row) {
    rangeCheckRow(row, size());
    return new AbstractList<String>() {
        @Override
        public String get(final int column) {
            rangeCheckColumn(column, size());
            return raw.get(column).get(row);
        }

        @Override
        public int size() {
            return height();
        }
    };
}
 
Example #13
Source File: Joiner.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Iterable<Object> iterable(final Object first, final Object second, final Object[] rest) {
  checkNotNull(rest);
  return new AbstractList<Object>() {
    @Override
    public int size() {
      return rest.length + 2;
    }

    @Override
    public Object get(int index) {
      switch (index) {
        case 0:
          return first;
        case 1:
          return second;
        default:
          return rest[index - 2];
      }
    }
  };
}
 
Example #14
Source File: ListUtils.java    From JSAT with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a new unmodifiable view that is the merging of two lists
 * @param <T> the type the lists hold
 * @param left the left portion of the merged view
 * @param right the right portion of the merged view
 * @return a list view that contains bot the left and right lists
 */
public static <T> List<T> mergedView(final List<T> left, final List<T> right)
{
    List<T> merged = new AbstractList<T>() 
    {

        @Override
        public T get(int index)
        {
            if(index < left.size())
                return left.get(index);
            else if(index-left.size() < right.size())
                return right.get(index-left.size());
            else
                throw new IndexOutOfBoundsException("List of lengt " + size() + " has no index " + index);
        }

        @Override
        public int size()
        {
            return left.size() + right.size();
        }
    };
    return merged;
}
 
Example #15
Source File: Util.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a list that returns every {@code n}th element of a list,
 * starting at element {@code k}.
 *
 * <p>It is OK if the list is empty or its size is not a multiple of
 * {@code n}.</p>
 *
 * <p>For instance, {@code quotientList(list, 2, 0)} returns the even
 * elements of a list, and {@code quotientList(list, 2, 1)} returns the odd
 * elements. Those lists are the same length only if list has even size.</p>
 */
public static <E> List<E> quotientList(
    final List<E> list, final int n, final int k) {
  if (n <= 0 || k < 0 || k >= n) {
    throw new IllegalArgumentException(
        "n must be positive; k must be between 0 and n - 1");
  }
  final int size = (list.size() + n - k - 1) / n;
  return new AbstractList<E>() {
    public E get(int index) {
      return list.get(index * n + k);
    }

    public int size() {
      return size;
    }
  };
}
 
Example #16
Source File: ClassInfoImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example #17
Source File: Throwables.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@GwtIncompatible // invokeAccessibleNonThrowingMethod
private static List<StackTraceElement> jlaStackTrace(final Throwable t) {
  checkNotNull(t);
  /*
   * TODO(cpovirk): Consider optimizing iterator() to catch IOOBE instead of doing bounds checks.
   *
   * TODO(cpovirk): Consider the UnsignedBytes pattern if it performs faster and doesn't cause
   * AOSP grief.
   */
  return new AbstractList<StackTraceElement>() {
    @Override
    public StackTraceElement get(int n) {
      return (StackTraceElement) invokeAccessibleNonThrowingMethod(getStackTraceElementMethod, jla, t, n);
    }

    @Override
    public int size() {
      return (Integer) invokeAccessibleNonThrowingMethod(getStackTraceDepthMethod, jla, t);
    }
  };
}
 
Example #18
Source File: ReflectionMethod.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final java.lang.reflect.Method method = this.method;
    return new AbstractList<MethodParameter>() {
        private final Class[] parameters = method.getParameterTypes();

        @Override public MethodParameter get(final int index) {
            return new BaseMethodParameter() {
                @Nonnull @Override public Set<? extends Annotation> getAnnotations() {
                    return ImmutableSet.of();
                }

                @Nullable @Override public String getName() {
                    return null;
                }

                @Nonnull @Override public String getType() {
                    return ReflectionUtils.javaToDexName(parameters[index].getName());
                }
            };
        }

        @Override public int size() {
            return parameters.length;
        }
    };
}
 
Example #19
Source File: DataTable.java    From cucumber with MIT License 6 votes vote down vote up
@Override
public List<String> get(final int row) {
    rangeCheckRow(row, size());
    return new AbstractList<String>() {
        @Override
        public String get(final int column) {
            rangeCheckColumn(column, size());
            return raw.get(fromRow + row).get(fromColumn + column);
        }

        @Override
        public int size() {
            return toColumn - fromColumn;
        }
    };
}
 
Example #20
Source File: IntPair.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Converts two lists into a list of {@link IntPair}s.
 *
 * <p>The length of the combined list is the lesser of the lengths of the
 * source lists. But typically the source lists will be the same length.</p>
 *
 * @param lefts Left list
 * @param rights Right list
 * @param strict Whether to fail if lists have different size
 * @return List of pairs
 */
public static List<IntPair> zip(
    final List<? extends Number> lefts,
    final List<? extends Number> rights,
    boolean strict) {
  final int size;
  if (strict) {
    if (lefts.size() != rights.size()) {
      throw new AssertionError();
    }
    size = lefts.size();
  } else {
    size = Math.min(lefts.size(), rights.size());
  }
  return new AbstractList<IntPair>() {
    public IntPair get(int index) {
      return IntPair.of(lefts.get(index).intValue(),
          rights.get(index).intValue());
    }

    public int size() {
      return size;
    }
  };
}
 
Example #21
Source File: DataNode.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize global settings for DN
 */
protected void initGlobalSetting(Configuration conf,
    AbstractList<File> dataDirs) throws IOException {
  this.dataDirs = dataDirs;
  this.conf = conf;
  storage = new DataStorage(this);
  
  // global DN settings
  initConfig(conf);
  registerMXBean();
  initDataXceiver(conf);
  startInfoServer(conf);
  initIpcServer(conf);

  myMetrics = new DataNodeMetrics(conf, storage.getStorageID());
}
 
Example #22
Source File: Util.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a list that returns every {@code n}th element of a list,
 * starting at element {@code k}.
 *
 * <p>It is OK if the list is empty or its size is not a multiple of
 * {@code n}.</p>
 *
 * <p>For instance, {@code quotientList(list, 2, 0)} returns the even
 * elements of a list, and {@code quotientList(list, 2, 1)} returns the odd
 * elements. Those lists are the same length only if list has even size.</p>
 */
public static <E> List<E> quotientList(
    final List<E> list, final int n, final int k) {
  if (n <= 0 || k < 0 || k >= n) {
    throw new IllegalArgumentException(
        "n must be positive; k must be between 0 and n - 1");
  }
  final int size = (list.size() + n - k - 1) / n;
  return new AbstractList<E>() {
    public E get(int index) {
      return list.get(index * n + k);
    }

    public int size() {
      return size;
    }
  };
}
 
Example #23
Source File: RelOptTableImpl.java    From Quicksql with MIT License 6 votes vote down vote up
/** Helper for {@link #getColumnStrategies()}. */
public static List<ColumnStrategy> columnStrategies(final RelOptTable table) {
  final int fieldCount = table.getRowType().getFieldCount();
  final InitializerExpressionFactory ief =
      Util.first(table.unwrap(InitializerExpressionFactory.class),
          NullInitializerExpressionFactory.INSTANCE);
  return new AbstractList<ColumnStrategy>() {
    public int size() {
      return fieldCount;
    }

    public ColumnStrategy get(int index) {
      return ief.generationStrategy(table, index);
    }
  };
}
 
Example #24
Source File: HeadersUtils.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}.
 * @param name the name of the header to retrieve
 * @return a {@link List} of header values or an empty {@link List} if no values are found.
 */
public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) {
    final List<V> allNames = headers.getAll(name);
    return new AbstractList<String>() {
        @Override
        public String get(int index) {
            V value = allNames.get(index);
            return value != null ? value.toString() : null;
        }

        @Override
        public int size() {
            return allNames.size();
        }
    };
}
 
Example #25
Source File: ReflectionMethod.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final java.lang.reflect.Method method = this.method;
    return new AbstractList<MethodParameter>() {
        private final Class[] parameters = method.getParameterTypes();

        @Override public MethodParameter get(final int index) {
            return new BaseMethodParameter() {
                @Nonnull @Override public Set<? extends Annotation> getAnnotations() {
                    return ImmutableSet.of();
                }

                @Nullable @Override public String getName() {
                    return null;
                }

                @Nonnull @Override public String getType() {
                    return ReflectionUtils.javaToDexName(parameters[index].getName());
                }
            };
        }

        @Override public int size() {
            return parameters.length;
        }
    };
}
 
Example #26
Source File: MotionDisplayer.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
public void addExperimentalDataObjectsToJson(AbstractList<ExperimentalDataObject> expObjects) {
    
    createDefaultMotionObjects();
    // create default top Group for motion
    JSONObject topJson = motionObjectsRoot;
    if (topJson.get("children") == null) {
        topJson.put("children", new JSONArray());
    }
    JSONArray motObjectsChildren = (JSONArray) topJson.get("children");
    for (ExperimentalDataObject nextExpObject : expObjects) {
        if (mapComponentToUUID.get(nextExpObject)!= null)
            continue;
        ArrayList<UUID> comp_uuids = new ArrayList<UUID>();
        motObjectsChildren.add(nextExpObject.createDecorationJson(comp_uuids, this));
        mapComponentToUUID.put(nextExpObject, comp_uuids);
        mapUUIDToComponent.put(comp_uuids.get(0), nextExpObject);
    }
}
 
Example #27
Source File: ClassUtilTest.java    From common-utils with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void getAllSuperclasses() {
    assertEquals(null, ClassUtil.getAllSuperclasses(null));
    assertTrue(ClassUtil.getAllSuperclasses(Object.class).isEmpty());

    assertTrue(ClassUtil.getAllSuperclasses(String.class).isEmpty());

    List<Class<?>> supers = ClassUtil.getAllSuperclasses(ArrayList.class);
    assertTrue(supers.contains(AbstractList.class));
    assertTrue(supers.contains(AbstractCollection.class));

    assertFalse(supers.contains(List.class));
    assertFalse(supers.contains(Object.class));

    assertTrue(ClassUtil.getAllSuperclasses(int.class).isEmpty());
    assertTrue(ClassUtil.getAllSuperclasses(int[].class).isEmpty());
    assertTrue(ClassUtil.getAllSuperclasses(Integer.class).contains(Number.class));

    assertTrue(ClassUtil.getAllSuperclasses(Integer[].class).isEmpty());

}
 
Example #28
Source File: Window.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Presents a view of the {@link RexWinAggCall} list as a list of
 * {@link AggregateCall}.
 */
public List<AggregateCall> getAggregateCalls(Window windowRel) {
  final List<String> fieldNames =
      Util.skip(windowRel.getRowType().getFieldNames(),
          windowRel.getInput().getRowType().getFieldCount());
  return new AbstractList<AggregateCall>() {
    public int size() {
      return aggCalls.size();
    }

    public AggregateCall get(int index) {
      final RexWinAggCall aggCall = aggCalls.get(index);
      final SqlAggFunction op = (SqlAggFunction) aggCall.getOperator();
      return AggregateCall.create(op, aggCall.distinct, false,
          aggCall.ignoreNulls, getProjectOrdinals(aggCall.getOperands()),
          -1, RelCollations.EMPTY,
          aggCall.getType(), fieldNames.get(aggCall.ordinal));
    }
  };
}
 
Example #29
Source File: FileDownloader.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    @SuppressWarnings("unchecked")
    AbstractList<String> requestedDownloads = (AbstractList<String>) msg.obj;
    if (msg.obj != null) {
        Iterator<String> it = requestedDownloads.iterator();
        while (it.hasNext()) {
            String next = it.next();
            mService.downloadFile(next);
        }
    }
    Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
    mService.stopSelf(msg.arg1);
}
 
Example #30
Source File: Pair.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static <K, V> List<K> left(
    final List<? extends Map.Entry<K, V>> pairs) {
  return new AbstractList<K>() {
    public K get(int index) {
      return pairs.get(index).getKey();
    }

    public int size() {
      return pairs.size();
    }
  };
}