List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:org.apache.hadoop.hdfs.security.token.block.TestBlockToken.java
@Test public void collectionOfBlocksActsSanely() { final long[][] testBlockIds = new long[][] { { 99l, 7l, -32l, 0l }, {}, { 42l }, { -5235l, 2352 } }; final long[] notBlockIds = new long[] { 32l, 1l, -23423423l }; for (long[] bids : testBlockIds) { BlockTokenIdentifier bti = new BlockTokenIdentifier("Madame Butterfly", bids, EnumSet.noneOf(BlockTokenSecretManager.AccessMode.class)); for (long bid : bids) assertTrue(bti.isBlockIncluded(bid)); for (long nbid : notBlockIds) assertFalse(bti.isBlockIncluded(nbid)); // BlockTokenIdentifiers maintain a sorted array of the block Ids. long[] sorted = Arrays.copyOf(bids, bids.length); Arrays.sort(sorted);/*from w w w .j a v a 2 s . c o m*/ assertTrue(Arrays.toString(bids) + " doesn't equal " + Arrays.toString(sorted), Arrays.equals(bti.getBlockIds(), sorted)); } }
From source file:org.apache.falcon.regression.ui.search.SearchPage.java
public Set<Button> getButtons(boolean active) { List<WebElement> buttons = resultBlock.findElement(By.className("buttonsRow")) .findElements(By.className("btn")); Set<Button> result = EnumSet.noneOf(Button.class); for (WebElement button : buttons) { if ((button.getAttribute("disabled") == null) == active) { result.add(Button.valueOf(button.getText())); }//from w w w . j a va 2 s . co m } return result; }
From source file:com.quinsoft.zeidon.SerializeOi.java
public SerializeOi setFlags(EnumSet<WriteOiFlags> flags) { if (flags == null) flags = EnumSet.noneOf(WriteOiFlags.class); this.flags = flags; return this; }
From source file:org.mozilla.gecko.home.TopSitesPanel.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mEditPinnedSiteListener = new EditPinnedSiteListener(); mList.setTag(HomePager.LIST_TAG_TOP_SITES); mList.setHeaderDividersEnabled(false); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/* w w w .j a v a 2 s. c om*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ListView list = (ListView) parent; final int headerCount = list.getHeaderViewsCount(); if (position < headerCount) { // The click is on a header, don't do anything. return; } // Absolute position for the adapter. position += (mGridAdapter.getCount() - headerCount); final Cursor c = mListAdapter.getCursor(); if (c == null || !c.moveToPosition(position)) { return; } final String url = c.getString(c.getColumnIndexOrThrow(TopSites.URL)); Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM); // This item is a TwoLinePageRow, so we allow switch-to-tab. mUrlOpenListener.onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)); } }); mList.setContextMenuInfoFactory(new HomeContextMenuInfo.Factory() { @Override public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor) { final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id); info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL)); info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE)); info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID)); info.itemType = RemoveItemType.HISTORY; final int bookmarkIdCol = cursor.getColumnIndexOrThrow(TopSites.BOOKMARK_ID); if (cursor.isNull(bookmarkIdCol)) { // If this is a combined cursor, we may get a history item without a // bookmark, in which case the bookmarks ID column value will be null. info.bookmarkId = -1; } else { info.bookmarkId = cursor.getInt(bookmarkIdCol); } return info; } }); mGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TopSitesGridItemView item = (TopSitesGridItemView) view; // Decode "user-entered" URLs before loading them. String url = StringUtils.decodeUserEnteredUrl(item.getUrl()); int type = item.getType(); // If the url is empty, the user can pin a site. // If not, navigate to the page given by the url. if (type != TopSites.TYPE_BLANK) { if (mUrlOpenListener != null) { final TelemetryContract.Method method; if (type == TopSites.TYPE_SUGGESTED) { method = TelemetryContract.Method.SUGGESTION; } else { method = TelemetryContract.Method.GRID_ITEM; } Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, method, Integer.toString(position)); // Record tile click events on non-private tabs. final Tab tab = Tabs.getInstance().getSelectedTab(); if (!tab.isPrivate()) { final Locale locale = Locale.getDefault(); final String localeTag = Locales.getLanguageTag(locale); TilesRecorder.recordAction(tab, TilesRecorder.ACTION_CLICK, position, getTilesSnapshot(), localeTag); } mUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(OnUrlOpenListener.Flags.class)); } } else { if (mEditPinnedSiteListener != null) { mEditPinnedSiteListener.onEditPinnedSite(position, ""); } } } }); mGrid.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor cursor = (Cursor) parent.getItemAtPosition(position); TopSitesGridItemView item = (TopSitesGridItemView) view; if (cursor == null || item.getType() == TopSites.TYPE_BLANK) { mGrid.setContextMenuInfo(null); return false; } TopSitesGridContextMenuInfo contextMenuInfo = new TopSitesGridContextMenuInfo(view, position, id); updateContextMenuFromCursor(contextMenuInfo, cursor); mGrid.setContextMenuInfo(contextMenuInfo); return mGrid.showContextMenuForChild(mGrid); } /* * Update the fields of a TopSitesGridContextMenuInfo object * from a cursor. * * @param info context menu info object to be updated * @param cursor used to update the context menu info object */ private void updateContextMenuFromCursor(TopSitesGridContextMenuInfo info, Cursor cursor) { info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL)); info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE)); info.type = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.TYPE)); info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID)); } }); registerForContextMenu(mList); registerForContextMenu(mGrid); }
From source file:org.apache.accumulo.core.util.shell.commands.SetIterCommand.java
protected void setTableProperties(final CommandLine cl, final Shell shellState, final int priority, final Map<String, String> options, final String classname, final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException { // remove empty values final String tableName = OptUtil.getTableOpt(cl, shellState); if (!shellState.getConnector().tableOperations().testClassLoad(tableName, classname, SortedKeyValueIterator.class.getName())) { throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + classname + " as type " + SortedKeyValueIterator.class.getName()); }/*from w w w . j a v a 2 s .c om*/ final String aggregatorClass = options.get("aggregatorClass"); @SuppressWarnings("deprecation") String deprecatedAggregatorClassName = org.apache.accumulo.core.iterators.aggregation.Aggregator.class .getName(); if (aggregatorClass != null && !shellState.getConnector().tableOperations().testClassLoad(tableName, aggregatorClass, deprecatedAggregatorClassName)) { throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + aggregatorClass + " as type " + deprecatedAggregatorClassName); } for (Iterator<Entry<String, String>> i = options.entrySet().iterator(); i.hasNext();) { final Entry<String, String> entry = i.next(); if (entry.getValue() == null || entry.getValue().isEmpty()) { i.remove(); } } final EnumSet<IteratorScope> scopes = EnumSet.noneOf(IteratorScope.class); if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(mincScopeOpt.getOpt())) { scopes.add(IteratorScope.minc); } if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(majcScopeOpt.getOpt())) { scopes.add(IteratorScope.majc); } if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(scanScopeOpt.getOpt())) { scopes.add(IteratorScope.scan); } if (scopes.isEmpty()) { throw new IllegalArgumentException("You must select at least one scope to configure"); } final IteratorSetting setting = new IteratorSetting(priority, name, classname, options); shellState.getConnector().tableOperations().attachIterator(tableName, setting, scopes); }
From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java
private EnumSet<FieldEncapsulationOptions> getFieldEncapsulationOptions() { EnumSet<FieldEncapsulationOptions> fieldEncapsulationOptions = EnumSet .noneOf(FieldEncapsulationOptions.class); if (makeFieldsPrivate.isSelected()) fieldEncapsulationOptions.add(FieldEncapsulationOptions.PROVIDE_PRIVATE_FIELD); if (provideGetter.isSelected()) fieldEncapsulationOptions.add(FieldEncapsulationOptions.PROVIDE_GETTER); if (provideSetter.isSelected()) fieldEncapsulationOptions.add(FieldEncapsulationOptions.PROVIDE_SETTER); return fieldEncapsulationOptions; }
From source file:de.schildbach.pte.NegentweeProvider.java
private EnumSet<Product> productSetFromTypeString(String type) { switch (type.toLowerCase()) { case "train": return EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN); case "subway": return EnumSet.of(Product.SUBWAY); case "tram": return EnumSet.of(Product.TRAM); case "bus": return EnumSet.of(Product.BUS); case "ferry": return EnumSet.of(Product.FERRY); case "walk": return EnumSet.of(Product.ON_DEMAND); default:/* w ww . j av a 2 s. c o m*/ return EnumSet.noneOf(Product.class); } }
From source file:org.wikipedia.nirvana.statistics.Rating.java
private void calcProgress() { Path startingDir = Paths.get(Statistics.cacheFolder); String pattern = FileTools.normalizeFileName(portal) + "." + this.type + ".????-??-??.js"; Finder finder = new Finder(pattern); //Files.w/*from www .jav a2 s . co m*/ try { Files.walkFileTree(startingDir, EnumSet.noneOf(FileVisitOption.class), 1, finder); } catch (IOException e) { log.error(e.toString()); e.printStackTrace(); } String file = finder.getNewestFile(); Map<String, Integer> data = new HashMap<String, Integer>(30); if (file != null) { ObjectMapper mapper = new ObjectMapper(); //List<ArchiveItem> list = null; // File file = new File(prevResultFile); // if(!file.exists()) { // log.warn("file "+dbPath+" does not exist"); // return; // } try { data = mapper.readValue(new File(startingDir + "\\" + file), new TypeReference<Map<String, Integer>>() { }); } catch (JsonParseException e) { log.error(e); } catch (JsonMappingException e) { log.error(e); } catch (IOException e) { log.error(e); } if (data != null) { for (StatItem item : this.items) { Integer n = data.get(item.user); if (n != null) { item.progress = -(item.number - n); /// smaller value means progress } } } } data.clear(); for (StatItem item : this.items) { data.put(item.user, item.number); } file = Statistics.cacheFolder + "\\" + String.format("%1$s.%2$s.%3$tF.js", FileTools.normalizeFileName(Statistics.portal), type, Calendar.getInstance()); ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(new File(file), data); } catch (JsonParseException e) { log.error(e); return; } catch (JsonMappingException e) { log.error(e); return; } catch (IOException e) { log.error(e); return; } }
From source file:org.apache.nifi.admin.service.action.AuthorizeUserActionTest.java
@Before public void setup() throws Exception { // mock the user dao userDao = Mockito.mock(UserDAO.class); Mockito.doAnswer(new Answer<NiFiUser>() { @Override//w w w . jav a2 s . co m public NiFiUser answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String id = (String) args[0]; NiFiUser user = null; if (USER_ID_7.equals(id)) { user = new NiFiUser(); user.setId(USER_ID_7); user.setIdentity(USER_IDENTITY_7); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); } else if (USER_ID_8.equals(id)) { user = new NiFiUser(); user.setId(USER_ID_8); user.setIdentity(USER_IDENTITY_8); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setLastVerified(new Date()); } else if (USER_ID_11.equals(id)) { user = new NiFiUser(); user.setId(USER_ID_11); user.setIdentity(USER_IDENTITY_11); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setStatus(AccountStatus.ACTIVE); } return user; } }).when(userDao).findUserById(Mockito.anyString()); Mockito.doAnswer(new Answer<NiFiUser>() { @Override public NiFiUser answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; NiFiUser user = null; switch (dn) { case USER_IDENTITY_7: user = new NiFiUser(); user.setId(USER_ID_7); user.setIdentity(USER_IDENTITY_7); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); break; case USER_IDENTITY_8: user = new NiFiUser(); user.setId(USER_ID_8); user.setIdentity(USER_IDENTITY_8); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setLastVerified(new Date()); break; case USER_IDENTITY_9: user = new NiFiUser(); user.setId(USER_ID_9); user.setIdentity(USER_IDENTITY_9); user.setStatus(AccountStatus.PENDING); break; case USER_IDENTITY_10: user = new NiFiUser(); user.setId(USER_ID_10); user.setIdentity(USER_IDENTITY_10); user.setStatus(AccountStatus.DISABLED); break; case USER_IDENTITY_11: user = new NiFiUser(); user.setId(USER_ID_11); user.setIdentity(USER_IDENTITY_11); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setStatus(AccountStatus.ACTIVE); break; } return user; } }).when(userDao).findUserByDn(Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); NiFiUser user = (NiFiUser) args[0]; switch (user.getIdentity()) { case USER_IDENTITY_5: throw new DataAccessException(); case USER_IDENTITY_6: user.setId(USER_ID_6); break; } // do nothing return null; } }).when(userDao).createUser(Mockito.any(NiFiUser.class)); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); NiFiUser user = (NiFiUser) args[0]; // do nothing return null; } }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); // mock the authority dao authorityDao = Mockito.mock(AuthorityDAO.class); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Set<Authority> authorities = (Set<Authority>) args[0]; String id = (String) args[1]; // do nothing return null; } }).when(authorityDao).createAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Set<Authority> authorities = (Set<Authority>) args[0]; String id = (String) args[1]; // do nothing return null; } }).when(authorityDao).deleteAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); // mock the dao factory daoFactory = Mockito.mock(DAOFactory.class); Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); // mock the authority provider authorityProvider = Mockito.mock(AuthorityProvider.class); Mockito.doAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; switch (dn) { case USER_IDENTITY_1: throw new AuthorityAccessException(StringUtils.EMPTY); case USER_IDENTITY_2: return false; } return true; } }).when(authorityProvider).doesDnExist(Mockito.anyString()); Mockito.doAnswer(new Answer<Set<Authority>>() { @Override public Set<Authority> answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; Set<Authority> authorities = EnumSet.noneOf(Authority.class); switch (dn) { case USER_IDENTITY_3: throw new UnknownIdentityException(StringUtils.EMPTY); case USER_IDENTITY_4: throw new AuthorityAccessException(StringUtils.EMPTY); case USER_IDENTITY_6: authorities.add(Authority.ROLE_MONITOR); break; case USER_IDENTITY_7: authorities.add(Authority.ROLE_DFM); break; case USER_IDENTITY_9: throw new UnknownIdentityException(StringUtils.EMPTY); case USER_IDENTITY_10: throw new UnknownIdentityException(StringUtils.EMPTY); case USER_IDENTITY_11: throw new UnknownIdentityException(StringUtils.EMPTY); } return authorities; } }).when(authorityProvider).getAuthorities(Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; Set<Authority> authorites = (Set<Authority>) args[1]; // do nothing return null; } }).when(authorityProvider).setAuthorities(Mockito.anyString(), Mockito.anySet()); }