List of usage examples for com.google.gwt.user.client Random nextInt
public static native int nextInt(int upperBound) ;
int
between 0 (inclusive) and upperBound
(exclusive) with roughly equal probability of returning any particular int
in this range. From source file:org.objectfabric.GWTPlatform.java
License:Apache License
@Override int randomInt(int limit) { return Random.nextInt(limit); }
From source file:org.pepstock.jem.gwt.client.ColorsHex.java
License:Open Source License
/** * @return a random color :) /*from ww w .j a v a 2 s . c o m*/ */ public static final ColorsHex randomColor() { ColorsHex[] allColors = ColorsHex.values(); return allColors[Random.nextInt(allColors.length)]; }
From source file:org.primordion.xholon.util.XholonCollections.java
License:Open Source License
/** * Randomly permutes the specified list using a default source of randomness. * All permutations occur with approximately equal likelihood. * This implementation traverses the list backwards, from the last element up to the second, * repeatedly swapping a randomly selected element into the "current position". * Elements are randomly selected from the portion of the list that runs from the first * element to the current position, inclusive. * This method runs in linear time./*from ww w. j a v a2 s. c o m*/ * @param list - the list to be shuffled. * The performance will degrade if the list does not implement RandomAccess. * ArrayList and Vector do implement RandomAccess. */ public static void shuffle(List<?> list) { for (int i = list.size(); i > 1; i--) { Collections.swap(list, i - 1, Random.nextInt(i)); } }
From source file:org.roda.wui.client.common.lists.utils.AsyncTableCell.java
public AsyncTableCell(final Class<T> classToReturn, final Filter filter, final boolean justActive, final Facets facets, final String summary, final boolean selectable, final int initialPageSize, final int pageSizeIncrement, final O object, List<String> fieldsToReturn) { super();//from w w w. ja v a 2s . co m this.classToReturn = classToReturn; this.initialPageSize = initialPageSize; this.pageSizeIncrement = pageSizeIncrement; this.object = object; final String notNullSummary = StringUtils.isNotBlank(summary) ? summary : "summary" + Random.nextInt(1000); this.filter = filter; this.justActive = justActive; this.facets = facets; this.selectable = selectable; this.fieldsToReturn = fieldsToReturn; display = new AccessibleCellTable<>(getInitialPageSize(), (MyCellTableResources) GWT.create(MyCellTableResources.class), getKeyProvider(), summary); display.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); display.setLoadingIndicator(new HTML(HtmlSnippetUtils.LOADING)); configure(display); this.dataProvider = new MyAsyncDataProvider<T>(display, fieldsToReturn, new IndexResultDataProvider<T>() { @Override public void getData(Sublist sublist, Sorter sorter, List<String> fieldsToReturn, final AsyncCallback<IndexResult<T>> callback) { AsyncTableCell.this.getData(AsyncTableCell.this.getFilter(), sublist, sorter, fieldsToReturn, new AsyncCallback<IndexResult<T>>() { @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } @Override public void onSuccess(IndexResult<T> result) { setResult(result); callback.onSuccess(result); } }); } @Override public Sorter getSorter(ColumnSortList columnSortList) { return AsyncTableCell.this.getSorter(columnSortList); } }) { @Override protected void fireChangeEvent(IndexResult<T> result) { ValueChangeEvent.fire(AsyncTableCell.this, result); } }; dataProvider.addDataDisplay(display); resultsPager = new AccessibleSimplePager(AccessibleSimplePager.TextLocation.LEFT, (SimplePager.Resources) GWT.create(SimplePager.Resources.class), false, initialPageSize, false, false, (SimplePager.ImageButtonsConstants) GWT.create(SimplePager.ImageButtonsConstants.class)); resultsPager.setDisplay(display); pageSizePager = new RodaPageSizePager(getPageSizePagerIncrement()); pageSizePager.setDisplay(display); csvDownloadButton = new Button(messages.tableDownloadCSV()); csvDownloadButton.addStyleName("btn btn-link csvDownloadButton"); actionsButton = new Button(messages.tableAction()); actionsButton.addStyleName("btn btn-link actionsButton"); actionsButton.setVisible(actionable != null); createSelectAllPanel(); add(selectAllPanel); add(display); add(resultsPager); add(pageSizePager); add(csvDownloadButton); add(actionsButton); csvDownloadButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { RestUtils.requestCSVExport(getClassToReturn(), getFilter(), dataProvider.getSorter(), dataProvider.getSublist(), getFacets(), getJustActive(), false, notNullSummary + ".csv"); } }); actionsButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { showActions(); } }); selectionModel = new SingleSelectionModel<>(getKeyProvider()); Handler<T> selectionEventManager = getSelectionEventManager(); if (selectionEventManager != null) { display.setSelectionModel(selectionModel, selectionEventManager); } else { display.setSelectionModel(selectionModel); } columnSortHandler = new AsyncHandler(display); display.addColumnSortHandler(columnSortHandler); addStyleName("my-asyncdatagrid"); resultsPager.addStyleName("my-asyncdatagrid-pager-results"); pageSizePager.addStyleName("my-asyncdatagrid-pager-pagesize"); display.addStyleName("my-asyncdatagrid-display"); addValueChangeHandler(new ValueChangeHandler<IndexResult<T>>() { @Override public void onValueChange(ValueChangeEvent<IndexResult<T>> event) { selected = new HashSet<>(); hideSelectAllPanel(); } }); updateEmptyTableWidget(); }
From source file:org.roda.wui.common.client.widgets.wcag.AccessibleTextBox.java
public AccessibleTextBox(Label label) { super();//w w w .j ava 2 s . co m if (this.getElement().getId() == null) { this.getElement().setId("id_" + Random.nextInt(99999)); } Label textLabel = label; if (textLabel == null) { textLabel = new Label("label"); textLabel.setVisible(false); } textLabel.getElement().setAttribute("for", this.getElement().getId()); this.getParent().getParent().getElement().appendChild(textLabel.getElement()); }
From source file:org.roda.wui.common.client.widgets.wcag.WCAGUtilities.java
public void makeAccessible(Element element) { String alignAttribute = element.getAttribute("align"); if (alignAttribute != null) { String className;//from w w w . j a va2 s .c o m if ("right".equals(alignAttribute)) { className = "alignRight"; } else if ("left".equals(alignAttribute)) { className = "alignLeft"; } else if ("center".equals(alignAttribute)) { className = "alignCenter"; } else { className = "alignJustify"; } element.removeAttribute("align"); element.addClassName(className); } if (INPUT_TAGNAMES.contains(element.getTagName())) { addAttributeIfNonExistent(element, "title", "t_" + Random.nextInt(1000)); } if (IMG_TAGNAME.equalsIgnoreCase(element.getTagName())) { addAttributeIfNonExistent(element, "alt", "img_" + Random.nextInt(10000)); } if (element.getChildCount() > 0) { for (int i = 0; i < element.getChildCount(); i++) { if (element.getChild(i).getNodeType() == Node.ELEMENT_NODE) { makeAccessible((Element) element.getChild(i)); } } } }
From source file:org.sigmah.client.offline.dao.GuidGenerator.java
License:Open Source License
/** * Generates a GUID in compact form./*from www .java 2s.c o m*/ * * Examples: length = "VcydxgltxrVZSTV" * * @param length The number of digits (characters) * @param radix Radix (maximum 62) * @return GUID in compact form */ public static String generateCompact(int length, int radix) { char[] uuid = new char[36]; for (int i = 0; i != length; ++i) { uuid[i] = CHARS[Random.nextInt(radix)]; } return new String(uuid); }
From source file:org.sigmah.client.offline.dao.GuidGenerator.java
License:Open Source License
public static String generateV4() { char[] uuid = new char[36]; // rfc4122 requires these characters uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; // Fill in random data. At i==19 set the high bits of clock sequence as // per rfc4122, sec. 4.1.5 for (int i = 0; i != 36; i++) { if (uuid[i] == 0) { int r = Random.nextInt(16); uuid[i] = CHARS[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; }/*from ww w . j a va2 s.co m*/ } return new String(uuid); }
From source file:org.smartsnip.persistence.blackhole.BlackholePersistenceImpl.java
/** * @see org.smartsnip.persistence.IPersistence#getCodeFile(java.lang.Long) *///from w w w .ja v a 2s . c o m @Override public File getCodeFile(Long codeId) throws IOException { checkFail(); Byte[] content = new Byte[10000]; Byte data; for (int i = 0; i < content.length; ++i) { data = new Integer(Random.nextInt(255) - 128).byteValue(); content[i] = data; } return helper.createCodeFile("testfile.bin", content); }
From source file:org.thechiselgroup.biomixer.client.core.development.BenchmarkResourceSetFactory.java
License:Apache License
private static Date createRandomDate(int numberOfDaysIntoPast, long timestamp) { int intervalLength = numberOfDaysIntoPast * MILLISECONDS_PER_DAY; int randomValue = Random.nextInt(intervalLength); return new Date(timestamp - randomValue); }