/** * Gets an unmodifiable wrapper around this list. * May or may not wrap this list itself. */ public static <E> List<E> unmodifiable(List<E> list) { if(list==null) { // Empty return Collections.emptyList(); } return AoCollections.optimalUnmodifiableList(list); } }
private Country(int since, String[] states) { this.since = since; this.states = AoCollections.optimalUnmodifiableList(Arrays.asList(states)); }
/** * Gets an unmodifiable, unique set of exceptions. */ private static List<Throwable> getUniqueCauses(Throwable ... causes) { int len = causes.length; List<Throwable> uniqueCauses = new ArrayList<Throwable>(len); for(Throwable cause : causes) { if(cause!=null && !uniqueCauses.contains(cause)) uniqueCauses.add(cause); } return AoCollections.optimalUnmodifiableList(uniqueCauses); }
protected Index( Table table, String name, IndexType type, List<Column> columns ) { this.table = table; this.name = name; this.type = type; if(columns.isEmpty()) throw new IllegalArgumentException("columns.isEmpty()"); this.columns = AoCollections.optimalUnmodifiableList(new ArrayList<>(columns)); }
@Override final public List<Short> executeShortListQuery(String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(Connection.TRANSACTION_READ_COMMITTED, true, new ArrayList<Short>(), RuntimeException.class, shortObjectFactory, sql, params) ); }
@Override final public List<String> executeStringListQuery(int isolationLevel, boolean readOnly, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(isolationLevel, readOnly, new ArrayList<String>(), RuntimeException.class, stringObjectFactory, sql, params) ); }
@Override final public <T,E extends Exception> List<T> executeObjectListQuery(Class<E> eClass, ObjectFactoryE<T,E> objectFactory, String sql, Object ... params) throws SQLException, E { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(Connection.TRANSACTION_READ_COMMITTED, true, new ArrayList<T>(), eClass, objectFactory, sql, params) ); }
@Override final public List<Short> executeShortListQuery(int isolationLevel, boolean readOnly, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(isolationLevel, readOnly, new ArrayList<Short>(), RuntimeException.class, shortObjectFactory, sql, params) ); }
@Override final public <T> List<T> executeObjectListQuery(ObjectFactory<T> objectFactory, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(Connection.TRANSACTION_READ_COMMITTED, true, new ArrayList<T>(), RuntimeException.class, objectFactory, sql, params) ); }
@Override final public <T> List<T> executeObjectListQuery(int isolationLevel, boolean readOnly, ObjectFactory<T> objectFactory, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(isolationLevel, readOnly, new ArrayList<T>(), RuntimeException.class, objectFactory, sql, params) ); }
@Override final public <T,E extends Exception> List<T> executeObjectListQuery(int isolationLevel, boolean readOnly, Class<E> eClass, ObjectFactoryE<T,E> objectFactory, String sql, Object ... params) throws SQLException, E { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(isolationLevel, readOnly, new ArrayList<T>(), eClass, objectFactory, sql, params) ); }
@Override final public List<String> executeStringListQuery(String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(Connection.TRANSACTION_READ_COMMITTED, true, new ArrayList<String>(), RuntimeException.class, stringObjectFactory, sql, params) ); }
@Override final public <T> List<T> executeObjectListQuery(Class<T> clazz, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(Connection.TRANSACTION_READ_COMMITTED, true, new ArrayList<T>(), RuntimeException.class, new ClassObjectFactory<>(clazz), sql, params) ); }
@Override final public <T> List<T> executeObjectListQuery(int isolationLevel, boolean readOnly, Class<T> clazz, String sql, Object ... params) throws SQLException { return AoCollections.optimalUnmodifiableList( executeObjectCollectionQuery(isolationLevel, readOnly, new ArrayList<T>(), RuntimeException.class, new ClassObjectFactory<>(clazz), sql, params) ); }
/** * Gets all columns for this schema in their ordinal position order. * Column with ordinal position one is at index zero. * * @see #getColumnMap() */ public List<Column> getColumns() throws SQLException { synchronized(getColumnsLock) { if(getColumnsCache==null) { SortedMap<String,Column> columnMap = getColumnMap(); List<Column> newColumns = new ArrayList<>(columnMap.size()); for(int i=0; i<columnMap.size(); i++) newColumns.add(null); for(Column column : columnMap.values()) { int ordinalPosition = column.getOrdinalPosition(); if(newColumns.set(ordinalPosition-1, column)!=null) throw new SQLException("Duplicate ordinal position: "+ordinalPosition); } for(int i=0; i<newColumns.size(); i++) { if(newColumns.get(i)==null) throw new SQLException("Missing ordinal position: "+(i+1)); } getColumnsCache = AoCollections.optimalUnmodifiableList(newColumns); } return getColumnsCache; } }
List<LinuxGroupAccount> getLinuxGroupAccounts( GroupId groupName, UserId username ) throws IOException, SQLException { synchronized(hash) { if(!hashBuilt) { hash.clear(); for(LinuxGroupAccount lga : getRows()) { Tuple2<GroupId,UserId> key = new Tuple2<>(lga.group_name, lga.username); List<LinuxGroupAccount> list = hash.get(key); if(list == null) hash.put(key, list = new ArrayList<>()); list.add(lga); } // Make entries unmodifiable for(Map.Entry<Tuple2<GroupId,UserId>,List<LinuxGroupAccount>> entry : hash.entrySet()) { entry.setValue( AoCollections.optimalUnmodifiableList(entry.getValue()) ); } hashBuilt = true; } List<LinuxGroupAccount> lgas = hash.get(new Tuple2<>(groupName, username)); if(lgas == null) return Collections.emptyList(); return lgas; } }
@Override public List<V> sortGraph() throws CycleException, EX { Set<V> vertices = graph.getVertices(); final int size = vertices.size(); Set<V> visited = new HashSet<V>(size*4/3+1); LinkedHashSet<V> sequence = new LinkedHashSet<V>(); //L ← Empty list that will contain the sorted nodes List<V> L = new ArrayList<V>(size); //S ← Set of all nodes with no incoming edges //for each node n in S do for(V n : vertices) { if( // Getting edges can be expensive, while checking visited should always be cheap !visited.contains(n) // This check is looking for starting nodes && (isForward ? graph.getEdgesTo(n) : graph.getEdgesFrom(n)).isEmpty() ) { topologicalSortVisit(n, L, visited, sequence); } } return AoCollections.optimalUnmodifiableList(L); }
private void topologicalSortVisit(V n, List<V> L, Set<V> visited, LinkedHashSet<V> sequence) throws CycleException, EX { // if n has not been visited yet then // mark n as visited if(visited.add(n)) { // for each node m with an edge from n to m do for(Edge<V> e : (isForward ? graph.getEdgesFrom(n) : graph.getEdgesTo(n))) { V m = isForward ? e.getTo() : e.getFrom(); // visit(m) if(!sequence.add(m)) { List<V> vertices = new ArrayList<V>(); boolean found = false; for(V seq : sequence) { if(!found && seq.equals(m)) found = true; if(found) vertices.add(seq); } vertices.add(m); throw new CycleException(AoCollections.optimalUnmodifiableList(vertices)); } topologicalSortVisit(m, L, visited, sequence); sequence.remove(m); } // add n to L L.add(n); } } }
pred = pred.equals(connected) ? null : predecessors.get(pred); throw new CycleException(AoCollections.optimalUnmodifiableList(vertices));
public UnmodifiableCopyServletRequest(ServletRequest req) { this.req = req; attributes = ServletSubRequest.getAllAttributes(req); characterEncoding = req.getCharacterEncoding(); contentLength = req.getContentLength(); contentType = req.getContentType(); parameterMap = new LinkedHashMap<String,String[]>(req.getParameterMap()); protocol = req.getProtocol(); scheme = req.getScheme(); serverName = req.getServerName(); serverPort = req.getServerPort(); remoteAddr = req.getRemoteAddr(); locale = req.getLocale(); List<Locale> newLocales = new ArrayList<Locale>(); Enumeration<Locale> e = req.getLocales(); while(e.hasMoreElements()) newLocales.add(e.nextElement()); locales = AoCollections.optimalUnmodifiableList(newLocales); secure = req.isSecure(); remotePort = req.getRemotePort(); localAddr = req.getLocalAddr(); localPort = req.getLocalPort(); servletContext = req.getServletContext(); dispatcherType = req.getDispatcherType(); }