List of usage examples for java.util EnumMap get
public V get(Object key)
From source file:it.unimi.di.big.mg4j.index.DiskBasedIndex.java
/** Returns a new disk-based index, loading exactly the specified parts and using preloaded {@link Properties}. * /* w ww . j a va 2s.co m*/ * @param ioFactory the factory that will be used to perform I/O. * @param basename the basename of the index. * @param properties the properties obtained from the given basename. * @param termMap the term map for this index, or <code>null</code> for no term map. * @param prefixMap the prefix map for this index, or <code>null</code> for no prefix map. * @param randomAccess whether the index should be accessible randomly (e.g., if it will * be possible to call {@link IndexReader#documents(long)} on the index readers returned by the index). * @param documentSizes if true, document sizes will be loaded (note that sometimes document sizes * might be loaded anyway because the compression method for positions requires it). * @param queryProperties a map containing associations between {@link Index.UriKeys} and values, or <code>null</code>. */ @SuppressWarnings("resource") public static Index getInstance(final IOFactory ioFactory, final CharSequence basename, Properties properties, final StringMap<? extends CharSequence> termMap, final PrefixMap<? extends CharSequence> prefixMap, final boolean randomAccess, final boolean documentSizes, final EnumMap<UriKeys, String> queryProperties) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException { // This could be null if old indices contain SkipIndex Class<?> indexClass = null; try { // Compatibility with previous versions indexClass = Class.forName(properties.getString(Index.PropertyKeys.INDEXCLASS, "(missing index class)") .replace(".dsi.", ".di.")); } catch (Exception ignore) { } final long numberOfDocuments = properties.getLong(Index.PropertyKeys.DOCUMENTS); final long numberOfTerms = properties.getLong(Index.PropertyKeys.TERMS); final long numberOfPostings = properties.getLong(Index.PropertyKeys.POSTINGS); final long numberOfOccurrences = properties.getLong(Index.PropertyKeys.OCCURRENCES, -1); final int maxCount = properties.getInt(Index.PropertyKeys.MAXCOUNT, -1); final String field = properties.getString(Index.PropertyKeys.FIELD, new File(basename.toString()).getName()); if (termMap != null && termMap.size64() != numberOfTerms) throw new IllegalArgumentException("The size of the term map (" + termMap.size64() + ") is not equal to the number of terms (" + numberOfTerms + ")"); if (prefixMap != null && prefixMap.size64() != numberOfTerms) throw new IllegalArgumentException("The size of the prefix map (" + prefixMap.size64() + ") is not equal to the number of terms (" + numberOfTerms + ")"); final Payload payload = (Payload) (properties.containsKey(Index.PropertyKeys.PAYLOADCLASS) ? Class.forName(properties.getString(Index.PropertyKeys.PAYLOADCLASS)).newInstance() : null); final int skipQuantum = properties.getInt(BitStreamIndex.PropertyKeys.SKIPQUANTUM, -1); final int bufferSize = properties.getInt(BitStreamIndex.PropertyKeys.BUFFERSIZE, BitStreamIndex.DEFAULT_BUFFER_SIZE); final int offsetStep = queryProperties != null && queryProperties.get(UriKeys.OFFSETSTEP) != null ? Integer.parseInt(queryProperties.get(UriKeys.OFFSETSTEP)) : DEFAULT_OFFSET_STEP; final boolean highPerformance = indexClass != null && FileHPIndex.class.isAssignableFrom(indexClass); final boolean inMemory = queryProperties != null && queryProperties.containsKey(UriKeys.INMEMORY); final TermProcessor termProcessor = Index.getTermProcessor(properties); // Load document sizes if forced to do so, or if the pointer/position compression methods make it necessary. IntBigList sizes = null; if (queryProperties != null && queryProperties.containsKey(UriKeys.SUCCINCTSIZES) && ioFactory != IOFactory.FILESYSTEM_FACTORY) throw new IllegalArgumentException( "Succinct sizes are deprecated and available only using the file system I/O factory."); if (QuasiSuccinctIndex.class == indexClass) { if (ioFactory != IOFactory.FILESYSTEM_FACTORY && !inMemory) throw new IllegalArgumentException( "Memory-mapped quasi-succinct indices require the file system I/O factory."); final Map<Component, Coding> flags = CompressionFlags.valueOf( properties.getStringArray(Index.PropertyKeys.CODING), CompressionFlags.DEFAULT_QUASI_SUCCINCT_INDEX); final File pointersFile = new File(basename + POINTERS_EXTENSIONS); if (!pointersFile.exists()) throw new FileNotFoundException("Cannot find pointers file " + pointersFile.getName()); if (documentSizes) { sizes = queryProperties != null && queryProperties.containsKey(UriKeys.SUCCINCTSIZES) ? readSizesSuccinct(basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments) : readSizes(ioFactory, basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments); if (sizes.size64() != numberOfDocuments) throw new IllegalStateException("The length of the size list (" + sizes.size64() + ") is not equal to the number of documents (" + numberOfDocuments + ")"); } final ByteOrder byteOrder = byteOrder(properties.getString(PropertyKeys.BYTEORDER)); final boolean hasCounts = flags.containsKey(Component.COUNTS); final boolean hasPositions = flags.containsKey(Component.POSITIONS); return new QuasiSuccinctIndex( inMemory ? loadLongBigList(ioFactory, basename + POINTERS_EXTENSIONS, byteOrder) : ByteBufferLongBigList.map( new FileInputStream(basename + POINTERS_EXTENSIONS).getChannel(), byteOrder, MapMode.READ_ONLY), hasCounts ? (inMemory ? loadLongBigList(ioFactory, basename + COUNTS_EXTENSION, byteOrder) : ByteBufferLongBigList.map( new FileInputStream(basename + COUNTS_EXTENSION).getChannel(), byteOrder, MapMode.READ_ONLY)) : null, hasPositions ? (inMemory ? loadLongBigList(ioFactory, basename + POSITIONS_EXTENSION, byteOrder) : ByteBufferLongBigList.map( new FileInputStream(basename + POSITIONS_EXTENSION).getChannel(), byteOrder, MapMode.READ_ONLY)) : null, numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, Fast.mostSignificantBit(skipQuantum), hasCounts, hasPositions, Index.getTermProcessor(properties), field, properties, termMap, prefixMap, sizes, DiskBasedIndex.offsets(ioFactory, basename + POINTERS_EXTENSIONS + OFFSETS_POSTFIX, numberOfTerms, offsetStep), hasCounts ? DiskBasedIndex.offsets(ioFactory, basename + COUNTS_EXTENSION + OFFSETS_POSTFIX, numberOfTerms, offsetStep) : null, hasPositions ? DiskBasedIndex.offsets(ioFactory, basename + POSITIONS_EXTENSION + OFFSETS_POSTFIX, numberOfTerms, offsetStep) : null); } final Map<Component, Coding> flags = CompressionFlags .valueOf(properties.getStringArray(Index.PropertyKeys.CODING), null); final Coding frequencyCoding = flags.get(Component.FREQUENCIES); final Coding pointerCoding = flags.get(Component.POINTERS); final Coding countCoding = flags.get(Component.COUNTS); final Coding positionCoding = flags.get(Component.POSITIONS); if (countCoding == null && positionCoding != null) throw new IllegalArgumentException( "Index " + basename + " has positions but no counts (this can't happen)"); if (payload == null && (documentSizes || positionCoding == Coding.GOLOMB || positionCoding == Coding.INTERPOLATIVE)) { sizes = queryProperties != null && queryProperties.containsKey(UriKeys.SUCCINCTSIZES) ? readSizesSuccinct(basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments) : readSizes(basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments); if (sizes.size64() != numberOfDocuments) throw new IllegalStateException("The length of the size list (" + sizes.size64() + ") is not equal to the number of documents (" + numberOfDocuments + ")"); } final int height = properties.getInt(BitStreamIndex.PropertyKeys.SKIPHEIGHT, -1); // Load offsets if forced to do so. Depending on a property, we use the core-memory or the semi-external version. final LongBigList offsets = payload == null && randomAccess ? offsets(ioFactory, basename + OFFSETS_EXTENSION, numberOfTerms, offsetStep) : null; final String indexFile = basename + INDEX_EXTENSION; if (!ioFactory.exists(indexFile)) throw new FileNotFoundException("Cannot find index file " + indexFile); if (inMemory) { /*if ( SqrtSkipIndex.class.isAssignableFrom( indexClass ) ) return new SqrtSkipInMemoryIndex( BinIO.loadBytes( indexFile.toString() ), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, frequencyCoding, pointerCoding, countCoding, positionCoding, termProcessor, field, properties, termMap, prefixMap, sizes, offsets );*/ return highPerformance ? new InMemoryHPIndex(IOFactories.loadBytes(ioFactory, indexFile), IOFactories.loadBytes(ioFactory, basename + POSITIONS_EXTENSION), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, termProcessor, field, properties, termMap, prefixMap, sizes, offsets) : new InMemoryIndex(IOFactories.loadBytes(ioFactory, indexFile.toString()), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, termProcessor, field, properties, termMap, prefixMap, sizes, offsets); } else if (queryProperties != null && queryProperties.containsKey(UriKeys.MAPPED)) { if (ioFactory != IOFactory.FILESYSTEM_FACTORY) throw new IllegalArgumentException("Mapped indices require the file system I/O factory."); final File positionsFile = new File(basename + POSITIONS_EXTENSION); final ByteBufferInputStream index = ByteBufferInputStream .map(new FileInputStream(indexFile).getChannel(), MapMode.READ_ONLY); return highPerformance ? new MemoryMappedHPIndex(index, ByteBufferInputStream.map(new FileInputStream(positionsFile).getChannel(), MapMode.READ_ONLY), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, termProcessor, field, properties, termMap, prefixMap, sizes, offsets) : new MemoryMappedIndex(index, numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, termProcessor, field, properties, termMap, prefixMap, sizes, offsets); } /*if ( SqrtSkipIndex.class.isAssignableFrom( indexClass ) ) return new SqrtSkipFileIndex( basename.toString(), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, frequencyCoding, pointerCoding, countCoding, positionCoding, termProcessor, field, properties, termMap, prefixMap, sizes, offsets, indexFile );*/ return highPerformance ? new FileHPIndex(basename.toString(), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, bufferSize, termProcessor, field, properties, termMap, prefixMap, sizes, offsets) : new FileIndex(ioFactory, basename.toString(), numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount, payload, frequencyCoding, pointerCoding, countCoding, positionCoding, skipQuantum, height, bufferSize, termProcessor, field, properties, termMap, prefixMap, sizes, offsets); }
From source file:tasly.greathealth.oms.inventory.facades.DefaultItemQuantityFacade.java
@Override public boolean updateItemQuantity() { EnumMap<HandleReturn, Object> handleReturn = new EnumMap<HandleReturn, Object>(HandleReturn.class); boolean updateStatus = true; final List<String> errorSkus = new ArrayList<>(); final List<ItemInfoData> itemInfoDatas = itemInfoService.getAll(); if (itemInfoDatas != null && itemInfoDatas.size() > 0) { for (int i = 0; i < itemInfoDatas.size(); i++) { final String sku = itemInfoDatas.get(i).getSku(); final int totalNumber = itemInfoDatas.get(i).getQuantity(); final int flag = itemInfoDatas.get(i).getStockManageFlag(); final Date nowDay = new Date(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssZ"); final String nowDate = sdf.format(nowDay); final String nowDateString = nowDate.substring(0, 8); final String modifyDay = itemInfoDatas.get(i).getExt1(); String modifyDayString = null; if (StringUtils.isEmpty(modifyDay)) { modifyDayString = ""; } else { modifyDayString = modifyDay.substring(0, 8); }//from w w w.j a va 2 s .co m if ("".equals(modifyDayString) || nowDateString.equals(modifyDayString) || flag == 0) { final List<TaslyItemLocationData> checkTaslyItemLocationDatas = taslyItemLocationService .getByItemID(sku); if (checkTaslyItemLocationDatas == null || checkTaslyItemLocationDatas.size() == 0) { omsLOG.error("sku:" + sku + ",no ItemLocation data!"); continue; } else { try { handleReturn = itemQuantityService.handleUpdateMethod(checkTaslyItemLocationDatas, sku, flag, totalNumber); } catch (final Exception e) { omsLOG.error("handle sku:" + sku + " failed and error is " + e); handleReturn.put(HandleReturn.handleStatus, false); } if ((boolean) handleReturn.get(HandleReturn.handleStatus)) { if ((boolean) handleReturn.get(HandleReturn.errorStatus)) { errorSkus.add(sku); } try { updateStatus = itemQuantityService.updateMethod(sku, flag, (int) handleReturn.get(HandleReturn.availableNumber)); if (flag == 0 && updateStatus) { omsLOG.debug("sku:" + sku + ",flag=0 allocated ok!"); } else if (flag == 1 && updateStatus) { omsLOG.debug("sku:" + sku + ",flag=1 allocated ok!"); } } catch (final Exception e) { omsLOG.error("update sku:" + sku + " failed and error is " + e); } } else { continue; } } } else if (!nowDateString.equals(modifyDayString) && flag == 1) { omsLOG.error("sku:" + sku + ",modifyTime:" + modifyDayString + ",nowday:" + nowDateString + ".The modifyTime not equal currentdate,current sku skip allocated"); continue; } } if (errorSkus.size() > 0) { final StringBuffer skulist = new StringBuffer(); for (final String errorSku : errorSkus) { skulist.append(errorSku + ","); } omsSkuLog.error("???SKU" + skulist.toString()); } return true; } else { omsLOG.error("get iteminfos failed!"); return false; } }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java
public VerticalToolbar generateToolbar(final Context context, final Fragment fragmentParent, final SideToolbarOverlay overlay) { final VerticalToolbar toolbar = new VerticalToolbar(context); final EnumSet<Action> itemsPref = PrefsUtility.pref_menus_post_toolbar_items(context, PreferenceManager.getDefaultSharedPreferences(context)); final Action[] possibleItems = { Action.ACTION_MENU, fragmentParent instanceof CommentListingFragment ? Action.LINK_SWITCH : Action.COMMENTS_SWITCH, Action.UPVOTE, Action.DOWNVOTE, Action.SAVE, Action.HIDE, Action.REPLY, Action.EXTERNAL, Action.SAVE_IMAGE, Action.SHARE, Action.COPY, Action.USER_PROFILE, Action.PROPERTIES }; // TODO make static final EnumMap<Action, Integer> iconsDark = new EnumMap<Action, Integer>(Action.class); iconsDark.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsDark.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_dark); iconsDark.put(Action.LINK_SWITCH, imageUrl != null ? R.drawable.ic_action_image_dark : R.drawable.ic_action_page_dark); iconsDark.put(Action.UPVOTE, R.drawable.action_upvote_dark); iconsDark.put(Action.DOWNVOTE, R.drawable.action_downvote_dark); iconsDark.put(Action.SAVE, R.drawable.ic_action_star_filled_dark); iconsDark.put(Action.HIDE, R.drawable.ic_action_cross_dark); iconsDark.put(Action.REPLY, R.drawable.ic_action_reply_dark); iconsDark.put(Action.EXTERNAL, R.drawable.ic_action_globe_dark); iconsDark.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_dark); iconsDark.put(Action.SHARE, R.drawable.ic_action_share_dark); iconsDark.put(Action.COPY, R.drawable.ic_action_copy_dark); iconsDark.put(Action.USER_PROFILE, R.drawable.ic_action_person_dark); iconsDark.put(Action.PROPERTIES, R.drawable.ic_action_info_dark); final EnumMap<Action, Integer> iconsLight = new EnumMap<Action, Integer>(Action.class); iconsLight.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsLight.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_light); iconsLight.put(Action.LINK_SWITCH, imageUrl != null ? R.drawable.ic_action_image_light : R.drawable.ic_action_page_light); iconsLight.put(Action.UPVOTE, R.drawable.action_upvote_light); iconsLight.put(Action.DOWNVOTE, R.drawable.action_downvote_light); iconsLight.put(Action.SAVE, R.drawable.ic_action_star_filled_light); iconsLight.put(Action.HIDE, R.drawable.ic_action_cross_light); iconsLight.put(Action.REPLY, R.drawable.ic_action_reply_light); iconsLight.put(Action.EXTERNAL, R.drawable.ic_action_globe_light); iconsLight.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_light); iconsLight.put(Action.SHARE, R.drawable.ic_action_share_light); iconsLight.put(Action.COPY, R.drawable.ic_action_copy_light); iconsLight.put(Action.USER_PROFILE, R.drawable.ic_action_person_light); iconsLight.put(Action.PROPERTIES, R.drawable.ic_action_info_light); for (final Action action : possibleItems) { if (action == Action.SAVE_IMAGE && imageUrl == null) continue; if (itemsPref.contains(action)) { final FlatImageButton ib = new FlatImageButton(context); final int buttonPadding = General.dpToPixels(context, 10); ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding); if (action == Action.UPVOTE && isUpvoted() || action == Action.DOWNVOTE && isDownvoted() || action == Action.SAVE && isSaved() || action == Action.HIDE && isHidden()) { ib.setBackgroundColor(Color.WHITE); ib.setImageResource(iconsLight.get(action)); } else { ib.setImageResource(iconsDark.get(action)); // TODO highlight on click }/* w ww . java 2s . c o m*/ ib.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Action actionToTake; switch (action) { case UPVOTE: actionToTake = isUpvoted() ? Action.UNVOTE : Action.UPVOTE; break; case DOWNVOTE: actionToTake = isDownvoted() ? Action.UNVOTE : Action.DOWNVOTE; break; case SAVE: actionToTake = isSaved() ? Action.UNSAVE : Action.SAVE; break; case HIDE: actionToTake = isHidden() ? Action.UNHIDE : Action.HIDE; break; default: actionToTake = action; break; } onActionMenuItemSelected(RedditPreparedPost.this, fragmentParent, actionToTake); overlay.hide(); } }); toolbar.addItem(ib); } } return toolbar; }
From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java
public VerticalToolbar generateToolbar(final Activity activity, boolean isComments, final SideToolbarOverlay overlay) { final VerticalToolbar toolbar = new VerticalToolbar(activity); final EnumSet<Action> itemsPref = PrefsUtility.pref_menus_post_toolbar_items(activity, PreferenceManager.getDefaultSharedPreferences(activity)); final Action[] possibleItems = { Action.ACTION_MENU, isComments ? Action.LINK_SWITCH : Action.COMMENTS_SWITCH, Action.UPVOTE, Action.DOWNVOTE, Action.SAVE, Action.HIDE, Action.REPLY, Action.EXTERNAL, Action.SAVE_IMAGE, Action.SHARE, Action.COPY, Action.USER_PROFILE, Action.PROPERTIES }; // TODO make static final EnumMap<Action, Integer> iconsDark = new EnumMap<Action, Integer>(Action.class); iconsDark.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsDark.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_dark); iconsDark.put(Action.LINK_SWITCH, imageUrl != null ? R.drawable.ic_action_image_dark : R.drawable.ic_action_page_dark); iconsDark.put(Action.UPVOTE, R.drawable.action_upvote_dark); iconsDark.put(Action.DOWNVOTE, R.drawable.action_downvote_dark); iconsDark.put(Action.SAVE, R.drawable.ic_action_star_filled_dark); iconsDark.put(Action.HIDE, R.drawable.ic_action_cross_dark); iconsDark.put(Action.REPLY, R.drawable.ic_action_reply_dark); iconsDark.put(Action.EXTERNAL, R.drawable.ic_action_globe_dark); iconsDark.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_dark); iconsDark.put(Action.SHARE, R.drawable.ic_action_share_dark); iconsDark.put(Action.COPY, R.drawable.ic_action_copy_dark); iconsDark.put(Action.USER_PROFILE, R.drawable.ic_action_person_dark); iconsDark.put(Action.PROPERTIES, R.drawable.ic_action_info_dark); final EnumMap<Action, Integer> iconsLight = new EnumMap<Action, Integer>(Action.class); iconsLight.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsLight.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_light); iconsLight.put(Action.LINK_SWITCH, imageUrl != null ? R.drawable.ic_action_image_light : R.drawable.ic_action_page_light); iconsLight.put(Action.UPVOTE, R.drawable.action_upvote_light); iconsLight.put(Action.DOWNVOTE, R.drawable.action_downvote_light); iconsLight.put(Action.SAVE, R.drawable.ic_action_star_filled_light); iconsLight.put(Action.HIDE, R.drawable.ic_action_cross_light); iconsLight.put(Action.REPLY, R.drawable.ic_action_reply_light); iconsLight.put(Action.EXTERNAL, R.drawable.ic_action_globe_light); iconsLight.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_light); iconsLight.put(Action.SHARE, R.drawable.ic_action_share_light); iconsLight.put(Action.COPY, R.drawable.ic_action_copy_light); iconsLight.put(Action.USER_PROFILE, R.drawable.ic_action_person_light); iconsLight.put(Action.PROPERTIES, R.drawable.ic_action_info_light); for (final Action action : possibleItems) { if (action == Action.SAVE_IMAGE && imageUrl == null) continue; if (itemsPref.contains(action)) { final FlatImageButton ib = new FlatImageButton(activity); final int buttonPadding = General.dpToPixels(activity, 10); ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding); if (action == Action.UPVOTE && isUpvoted() || action == Action.DOWNVOTE && isDownvoted() || action == Action.SAVE && isSaved() || action == Action.HIDE && isHidden()) { ib.setBackgroundColor(Color.WHITE); ib.setImageResource(iconsLight.get(action)); } else { ib.setImageResource(iconsDark.get(action)); // TODO highlight on click }/*from w ww . j a va 2 s . co m*/ ib.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Action actionToTake; switch (action) { case UPVOTE: actionToTake = isUpvoted() ? Action.UNVOTE : Action.UPVOTE; break; case DOWNVOTE: actionToTake = isDownvoted() ? Action.UNVOTE : Action.DOWNVOTE; break; case SAVE: actionToTake = isSaved() ? Action.UNSAVE : Action.SAVE; break; case HIDE: actionToTake = isHidden() ? Action.UNHIDE : Action.HIDE; break; default: actionToTake = action; break; } onActionMenuItemSelected(RedditPreparedPost.this, activity, actionToTake); overlay.hide(); } }); toolbar.addItem(ib); } } return toolbar; }
From source file:org.alfresco.solr.SolrInformationServer.java
private void categorizeNodes(List<Node> nodes, Map<Long, Node> nodeIdsToNodes, EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds) { for (Node node : nodes) { nodeIdsToNodes.put(node.getId(), node); List<Long> nodeIds = nodeStatusToNodeIds.get(node.getStatus()); if (nodeIds == null) { nodeIds = new LinkedList<>(); nodeStatusToNodeIds.put(node.getStatus(), nodeIds); }/*from ww w. j av a 2 s .co m*/ nodeIds.add(node.getId()); } }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
public VerticalToolbar generateToolbar(final Activity activity, boolean isComments, final SideToolbarOverlay overlay) { final VerticalToolbar toolbar = new VerticalToolbar(activity); final EnumSet<Action> itemsPref = PrefsUtility.pref_menus_post_toolbar_items(activity, PreferenceManager.getDefaultSharedPreferences(activity)); final Action[] possibleItems = { Action.ACTION_MENU, isComments ? Action.LINK_SWITCH : Action.COMMENTS_SWITCH, Action.UPVOTE, Action.DOWNVOTE, Action.SAVE, Action.HIDE, Action.DELETE, Action.REPLY, Action.EXTERNAL, Action.SAVE_IMAGE, Action.SHARE, Action.COPY, Action.USER_PROFILE, Action.PROPERTIES }; // TODO make static final EnumMap<Action, Integer> iconsDark = new EnumMap<Action, Integer>(Action.class); iconsDark.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsDark.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_dark); iconsDark.put(Action.LINK_SWITCH, mIsProbablyAnImage ? R.drawable.ic_action_image_dark : R.drawable.ic_action_page_dark); iconsDark.put(Action.UPVOTE, R.drawable.action_upvote_dark); iconsDark.put(Action.DOWNVOTE, R.drawable.action_downvote_dark); iconsDark.put(Action.SAVE, R.drawable.ic_action_star_filled_dark); iconsDark.put(Action.HIDE, R.drawable.ic_action_cross_dark); iconsDark.put(Action.REPLY, R.drawable.ic_action_reply_dark); iconsDark.put(Action.EXTERNAL, R.drawable.ic_action_globe_dark); iconsDark.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_dark); iconsDark.put(Action.SHARE, R.drawable.ic_action_share_dark); iconsDark.put(Action.COPY, R.drawable.ic_action_copy_dark); iconsDark.put(Action.USER_PROFILE, R.drawable.ic_action_person_dark); iconsDark.put(Action.PROPERTIES, R.drawable.ic_action_info_dark); final EnumMap<Action, Integer> iconsLight = new EnumMap<Action, Integer>(Action.class); iconsLight.put(Action.ACTION_MENU, R.drawable.ic_action_overflow); iconsLight.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_light); iconsLight.put(Action.LINK_SWITCH, mIsProbablyAnImage ? R.drawable.ic_action_image_light : R.drawable.ic_action_page_light); iconsLight.put(Action.UPVOTE, R.drawable.action_upvote_light); iconsLight.put(Action.DOWNVOTE, R.drawable.action_downvote_light); iconsLight.put(Action.SAVE, R.drawable.ic_action_star_filled_light); iconsLight.put(Action.HIDE, R.drawable.ic_action_cross_light); iconsLight.put(Action.REPLY, R.drawable.ic_action_reply_light); iconsLight.put(Action.EXTERNAL, R.drawable.ic_action_globe_light); iconsLight.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_light); iconsLight.put(Action.SHARE, R.drawable.ic_action_share_light); iconsLight.put(Action.COPY, R.drawable.ic_action_copy_light); iconsLight.put(Action.USER_PROFILE, R.drawable.ic_action_person_light); iconsLight.put(Action.PROPERTIES, R.drawable.ic_action_info_light); for (final Action action : possibleItems) { if (action == Action.SAVE_IMAGE && !mIsProbablyAnImage) continue; if (itemsPref.contains(action)) { final FlatImageButton ib = new FlatImageButton(activity); final int buttonPadding = General.dpToPixels(activity, 10); ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding); if (action == Action.UPVOTE && isUpvoted() || action == Action.DOWNVOTE && isDownvoted() || action == Action.SAVE && isSaved() || action == Action.HIDE && isHidden()) { ib.setBackgroundColor(Color.WHITE); ib.setImageResource(iconsLight.get(action)); } else { ib.setImageResource(iconsDark.get(action)); // TODO highlight on click }/*w w w . j a v a 2 s . co m*/ ib.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Action actionToTake; switch (action) { case UPVOTE: actionToTake = isUpvoted() ? Action.UNVOTE : Action.UPVOTE; break; case DOWNVOTE: actionToTake = isDownvoted() ? Action.UNVOTE : Action.DOWNVOTE; break; case SAVE: actionToTake = isSaved() ? Action.UNSAVE : Action.SAVE; break; case HIDE: actionToTake = isHidden() ? Action.UNHIDE : Action.HIDE; break; default: actionToTake = action; break; } onActionMenuItemSelected(RedditPreparedPost.this, activity, actionToTake); overlay.hide(); } }); toolbar.addItem(ib); } } return toolbar; }
From source file:org.alfresco.solr.SolrInformationServer.java
@Override public void indexNodes(List<Node> nodes, boolean overwrite) throws IOException, AuthenticationException, JSONException { SolrQueryRequest request = null;/*from w ww . j a v a2 s . c om*/ UpdateRequestProcessor processor = null; try { request = getLocalSolrQueryRequest(); processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse()); Map<Long, Node> nodeIdsToNodes = new HashMap<>(); EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds = new EnumMap<SolrApiNodeStatus, List<Long>>( SolrApiNodeStatus.class); categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds); List<Long> deletedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED)); List<Long> shardDeletedNodeIds = mapNullToEmptyList( nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED)); List<Long> shardUpdatedNodeIds = mapNullToEmptyList( nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_UPDATED)); List<Long> unknownNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UNKNOWN)); List<Long> updatedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UPDATED)); if (!deletedNodeIds.isEmpty() || !shardDeletedNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty() || !unknownNodeIds.isEmpty()) { // Delete any cached SOLR content documents appropriate for this shard List<NodeMetaData> nodeMetaDatas = new ArrayList<>(); // For all deleted nodes, fake the node metadata for (Long deletedNodeId : deletedNodeIds) { Node node = nodeIdsToNodes.get(deletedNodeId); NodeMetaData nodeMetaData = createDeletedNodeMetaData(node); nodeMetaDatas.add(nodeMetaData); } if (!unknownNodeIds.isEmpty()) { NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); nmdp.setNodeIds(unknownNodeIds); nodeMetaDatas.addAll(repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE)); } for (NodeMetaData nodeMetaData : nodeMetaDatas) { Node node = nodeIdsToNodes.get(nodeMetaData.getId()); if (nodeMetaData.getTxnId() > node.getTxnId()) { // the node has moved on to a later transaction // it will be indexed later continue; } if (nodeMetaData != null) { this.removeDocFromContentStore(nodeMetaData); } } // Delete the nodes from the index if (log.isDebugEnabled()) { log.debug(".. deleting"); } DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request); String query = this.cloud.getQuery(FIELD_DBID, OR, deletedNodeIds, shardDeletedNodeIds, shardUpdatedNodeIds, unknownNodeIds); delDocCmd.setQuery(query); processor.processDelete(delDocCmd); } if (!updatedNodeIds.isEmpty() || !unknownNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty()) { log.info(".. updating"); NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); List<Long> nodeIds = new LinkedList<>(); nodeIds.addAll(updatedNodeIds); nodeIds.addAll(unknownNodeIds); nodeIds.addAll(shardUpdatedNodeIds); nmdp.setNodeIds(nodeIds); // Fetches bulk metadata List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE); NEXT_NODE: for (NodeMetaData nodeMetaData : nodeMetaDatas) { long start = System.nanoTime(); Node node = nodeIdsToNodes.get(nodeMetaData.getId()); if (nodeMetaData.getTxnId() > node.getTxnId()) { // the node has moved on to a later transaction // it will be indexed later continue; } // All do potential cascade if (mayHaveChildren(nodeMetaData)) { cascadeUpdate(nodeMetaData, overwrite, request, processor); } // NON_SHARD_UPDATED do not index just cascade if (nodeIdsToNodes.get(nodeMetaData.getId()) .getStatus() == SolrApiNodeStatus.NON_SHARD_UPDATED) { continue; } AddUpdateCommand addDocCmd = new AddUpdateCommand(request); addDocCmd.overwrite = overwrite; // check index control Map<QName, PropertyValue> properties = nodeMetaData.getProperties(); StringPropertyValue pValue = (StringPropertyValue) properties.get(ContentModel.PROP_IS_INDEXED); if (pValue != null) { Boolean isIndexed = Boolean.valueOf(pValue.getValue()); if (!isIndexed.booleanValue()) { if (log.isDebugEnabled()) { log.debug(".. clearing unindexed"); } deleteNode(processor, request, node); SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_UNINDEXED_NODE); storeDocOnSolrContentStore(nodeMetaData, doc); addDocCmd.solrDoc = doc; if (recordUnindexedNodes) { processor.processAdd(addDocCmd); } long end = System.nanoTime(); this.trackerStats.addNodeTime(end - start); continue NEXT_NODE; } } // Make sure any unindexed or error doc is removed. if (log.isDebugEnabled()) { log.debug(".. deleting node " + node.getId()); } deleteNode(processor, request, node); SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_NODE); addToNewDocAndCache(nodeMetaData, doc); addDocCmd.solrDoc = doc; processor.processAdd(addDocCmd); long end = System.nanoTime(); this.trackerStats.addNodeTime(end - start); } // Ends iteration over nodeMetadatas } // Ends checking for the existence of updated or unknown node ids } catch (Exception e) { // Bulk version failed, so do one at a time. for (Node node : nodes) { this.indexNode(node, true); } } finally { if (processor != null) { processor.finish(); } if (request != null) { request.close(); } } }
From source file:sg.ncl.MainController.java
@RequestMapping(path = "/password_reset") public String resetPassword(@ModelAttribute("passwordResetForm") PasswordResetForm passwordResetForm) throws IOException { if (!passwordResetForm.isPasswordOk()) { return FORGET_PSWD_NEW_PSWD_PAGE; }/*from w w w. j av a 2s. c o m*/ JSONObject obj = new JSONObject(); obj.put("key", passwordResetForm.getKey()); obj.put("new", passwordResetForm.getPassword1()); log.info("Connecting to sio for password reset, key = {}", passwordResetForm.getKey()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(obj.toString(), headers); restTemplate.setErrorHandler(new MyResponseErrorHandler()); ResponseEntity response = null; try { response = restTemplate.exchange(properties.getPasswordResetURI(), HttpMethod.PUT, request, String.class); } catch (RestClientException e) { log.warn("Error connecting to sio for password reset! {}", e); passwordResetForm.setErrMsg("Cannot connect to server! Please try again later."); return FORGET_PSWD_NEW_PSWD_PAGE; } if (RestUtil.isError(response.getStatusCode())) { EnumMap<ExceptionState, String> exceptionMessageMap = new EnumMap<>(ExceptionState.class); exceptionMessageMap.put(PASSWORD_RESET_REQUEST_TIMEOUT_EXCEPTION, "Password reset request timed out. Please request a new reset email."); exceptionMessageMap.put(PASSWORD_RESET_REQUEST_NOT_FOUND_EXCEPTION, "Invalid password reset request. Please request a new reset email."); exceptionMessageMap.put(ADAPTER_CONNECTION_EXCEPTION, "Server-side error. Please contact " + CONTACT_EMAIL); MyErrorResource error = objectMapper.readValue(response.getBody().toString(), MyErrorResource.class); ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError()); final String errMsg = exceptionMessageMap.get(exceptionState) == null ? ERR_SERVER_OVERLOAD : exceptionMessageMap.get(exceptionState); passwordResetForm.setErrMsg(errMsg); log.warn("Server responded error for password reset: {}", exceptionState.toString()); return FORGET_PSWD_NEW_PSWD_PAGE; } log.info("Password was reset, key = {}", passwordResetForm.getKey()); return "password_reset_success"; }