List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:org.polymap.rhei.um.ui.UsersTableViewer.java
public UsersTableViewer(Composite parent, final Iterable<User> content, int style) { super(parent, SWT.VIRTUAL /*| SWT.V_SCROLL | SWT.FULL_SELECTION |*/ | style); this.repo = UserRepository.instance(); this.content = content; ColumnViewerToolTipSupport.enableFor(this); getTable().setLinesVisible(true);//from ww w . j a v a 2 s .co m getTable().setHeaderVisible(true); getTable().setLayout(new TableLayout()); TableViewerColumn vcolumn = new TableViewerColumn(this, SWT.CENTER); vcolumn.getColumn().setResizable(true); vcolumn.getColumn().setText("Name"); final ColumnLabelProvider nameLabelProvider = new ColumnLabelProvider() { public String getText(Object elm) { User user = (User) elm; String firstname = user.firstname().get(); return firstname != null && firstname.length() > 0 ? user.name().get() + ", " + firstname : user.name().get(); } }; vcolumn.setLabelProvider(nameLabelProvider); ((TableLayout) getTable().getLayout()).addColumnData(new ColumnWeightData(2, 100, true)); setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { String name1 = nameLabelProvider.getText(e1); String name2 = nameLabelProvider.getText(e2); return name1.compareToIgnoreCase(name2); } }); getTable().setSortColumn(vcolumn.getColumn()); getTable().setSortDirection(SWT.UP); vcolumn = new TableViewerColumn(this, SWT.LEFT); vcolumn.getColumn().setResizable(true); vcolumn.getColumn().setText("Adresse"); vcolumn.setLabelProvider(new ColumnLabelProvider() { public String getText(Object elm) { Address address = ((User) elm).address().get(); return Joiner.on(' ').skipNulls().join(address.postalCode().get(), address.city().get()); } }); ((TableLayout) getTable().getLayout()).addColumnData(new ColumnWeightData(2, 100, true)); setContentProvider(new ArrayContentProvider()); setInput(Iterables.toArray(content, User.class)); // setContentProvider( new DeferredContentProvider( new Comparator<User>() { // public int compare( User left, User right ) { // return left.name().get().compareToIgnoreCase( right.name().get() ); // } // })); // setInput( model = new SetModel() ); // // // content loader // new UIJob( "Nutzer laden" ) { // protected void runWithException( IProgressMonitor monitor ) throws Exception { // for (User user : content) { // Thread.sleep( 1000 ); // model.addAll( new Object[] { user } ); // } // } // }.schedule(); // model.addAll( ImmutableList.copyOf( content ) ); }
From source file:com.google.idea.blaze.base.lang.buildfile.globbing.UnixGlob.java
/** * Checks that each pattern is valid, splits it into segments and checks that each segment * contains only valid wildcards./* w ww . j a va2 s .com*/ * * @return list of segment arrays */ private static List<String[]> checkAndSplitPatterns(Collection<String> patterns) { List<String[]> list = Lists.newArrayListWithCapacity(patterns.size()); for (String pattern : patterns) { String error = GlobPatternValidator.validate(pattern); if (error != null) { throw new IllegalArgumentException(error); } Iterable<String> segments = Splitter.on('/').split(pattern); list.add(Iterables.toArray(segments, String.class)); } return list; }
From source file:be.nbb.demetra.dotstat.FixedDbBean.java
static String[] getDimArray(String dimColumns) { return Iterables.toArray(DIM_ARRAY_SPLITTER.split(dimColumns), String.class); }
From source file:org.openengsb.core.edb.jpa.internal.util.QueryRequestCriteriaBuilder.java
/** * Converts a query request parameter map for a query operation into a list of predicates which need to be added to * the criteria query.// www. j a va2 s . c o m */ @SuppressWarnings({ "unchecked" }) private Predicate convertParametersToPredicate(Root<?> from, CriteriaQuery<?> query) { List<Predicate> predicates = new ArrayList<>(); for (Map.Entry<String, Set<Object>> value : request.getParameters().entrySet()) { Subquery<JPAEntry> subquery = buildJPAEntrySubquery(value.getKey(), value.getValue(), from, query); predicates.add(builder.exists(subquery)); } if (request.isAndJoined()) { return builder.and(Iterables.toArray(predicates, Predicate.class)); } else { return builder.or(Iterables.toArray(predicates, Predicate.class)); } }
From source file:org.eclipse.xtext.ui.refactoring.impl.RefactoringUpdateAcceptor.java
@Override public Change createCompositeChange(String name, IProgressMonitor monitor) { if (document2change.isEmpty() && document2textEdits.isEmpty()) return null; CompositeChange compositeChange = new CompositeChange(name); for (IRefactoringDocument document : document2textEdits.keySet()) { if (monitor.isCanceled()) { throw new OperationCanceledException(); }//from w ww . ja va2 s . com Iterable<TextEdit> textEdits = document2textEdits.get(document); MultiTextEdit multiTextEdit = new MultiTextEdit(); for (TextEdit textEdit : textEdits) { multiTextEdit.addChild(textEdit); } Change change = document.createChange(name, multiTextEdit); compositeChange.add(change); } for (IRefactoringDocument document : document2change.keySet()) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } Iterable<Change> documentChanges = document2change.get(document); CompositeChange documentCompositeChange = new CompositeChange(name); documentCompositeChange.addAll(Iterables.toArray(documentChanges, Change.class)); compositeChange.add(documentCompositeChange); } return compositeChange; }
From source file:com.android.common.ide.common.res2.MergingException.java
public static void throwIfNonEmpty(Collection<Message> messages) throws MergingException { if (!messages.isEmpty()) { throw new MergingException(null, Iterables.toArray(messages, Message.class)); }// w ww . java2s.c om }
From source file:com.comphenix.protocol.events.PacketAdapter.java
/** * Initialize a packet listener with the given parameters. * @param plugin - the plugin./*from ww w .jav a 2 s . c o m*/ * @param listenerPriority - the priority. * @param types - the packet types. * @param options - the options. */ public PacketAdapter(Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types, ListenerOptions... options) { this(params(plugin, Iterables.toArray(types, PacketType.class)).listenerPriority(listenerPriority) .options(options)); }
From source file:org.apache.mailet.base.StringUtils.java
public static String listToString(List<String> strings) { return arrayToString(Iterables.toArray(strings, String.class)); }
From source file:org.datahack.parkingdb.api.BayEventFacadeREST.java
@GET @Produces({ "application/json" }) public List<BayEvent> find(@QueryParam("bayId") Integer bayId, @QueryParam("minTime") String minTimeString, @QueryParam("maxTime") String maxTimeString) { if (bayId != null) { CriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder(); CriteriaQuery<BayEvent> q = cb.createQuery(BayEvent.class); Root<BayEvent> bE = q.from(BayEvent.class); List<Predicate> predicates = new ArrayList(); predicates.add(cb.equal((bE.get(BayEvent_.bay)).get(Bay_.id), bayId)); if (minTimeString != null) { Date minTime = this.convertToDate(minTimeString); if (minTime != null) { predicates.add(cb.greaterThanOrEqualTo(bE.get(BayEvent_.eventTime), minTime)); }//w w w . ja v a2s . c o m } if (maxTimeString != null) { Date maxTime = this.convertToDate(maxTimeString); if (maxTime != null) { predicates.add(cb.lessThanOrEqualTo(bE.get(BayEvent_.eventTime), maxTime)); } } Predicate[] arr = Iterables.toArray(predicates, Predicate.class); q = q.where(arr); TypedQuery<BayEvent> pzQuery = em.createQuery(q); return pzQuery.getResultList(); } return Lists.newArrayList(); }
From source file:com.samskivert.depot.Ops.java
/** * Adds the supplied expressions together. *//*from w ww . java2 s .co m*/ public static <T extends Number> FluentExp<T> add(Iterable<SQLExpression<T>> exprs) { return new Add<T>(Iterables.toArray(exprs, SQLExpression.class)); }