use of java.util.Map.Entry in project tapestry5-hotel-booking by ccordenier.
the class HibernateCrudServiceDAO method findUniqueWithNamedQuery.
@SuppressWarnings("unchecked")
public <T> T findUniqueWithNamedQuery(String queryName, Map<String, Object> params) {
Set<Entry<String, Object>> rawParameters = params.entrySet();
Query query = session.getNamedQuery(queryName);
for (Entry<String, Object> entry : rawParameters) {
query.setParameter(entry.getKey(), entry.getValue());
}
return (T) query.uniqueResult();
}
use of java.util.Map.Entry in project SimplifyReader by chentao0707.
the class DownloadManager method getDownloadedList.
@SuppressWarnings("rawtypes")
public ArrayList<DownloadInfo> getDownloadedList() {
ArrayList<DownloadInfo> list = new ArrayList<DownloadInfo>();
// 获得map的Iterator
Iterator iter = getDownloadedData().entrySet().iterator();
while (iter.hasNext()) {
Entry entry = (Entry) iter.next();
list.add((DownloadInfo) entry.getValue());
}
return list;
}
use of java.util.Map.Entry in project SimplifyReader by chentao0707.
the class DownloadManager method getDownloadInfoListById.
@SuppressWarnings("rawtypes")
public ArrayList<DownloadInfo> getDownloadInfoListById(String videoIdOrShowId) {
if (videoIdOrShowId == null) {
return null;
}
ArrayList<DownloadInfo> list = null;
if (getDownloadedData().containsKey(videoIdOrShowId)) {
if (list == null)
list = new ArrayList<DownloadInfo>();
list.add(getDownloadedData().get(videoIdOrShowId));
} else {
// 获得map的Iterator
Iterator iter = getDownloadedData().entrySet().iterator();
while (iter.hasNext()) {
Entry entry = (Entry) iter.next();
DownloadInfo info = (DownloadInfo) entry.getValue();
if (videoIdOrShowId.equals(info.showid)) {
if (list == null)
list = new ArrayList<DownloadInfo>();
list.add(info);
}
}
if (list != null && list.size() > 1) {
// 按剧集排序
DownloadInfo.compareBySeq = true;
// 排序
Collections.sort(list);
}
}
return list;
}
use of java.util.Map.Entry in project cogtool by cogtool.
the class DesignEditorController method setBackgroundImageOnFrames.
/**
* Sets the background image for the array of frames
*
* @param frames an array of IFrames
* @param imageData the new image, or null if none
* @param imageURL the file path of the new image, or
* <code>WidgetAttributes.NO_IMAGE</code>
*/
protected void setBackgroundImageOnFrames(final Frame[] frames, final byte[] imageData, final String imageURL, CogToolLID editLID) {
try {
// compute the size of the new image.
final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
// save previous data for undo/redo
final Map<Frame, ImageData> previousImageData = getBackgroundImageData(frames);
// do operation on all frames
for (Frame frame : frames) {
frame.setBackgroundImage(imageData, imageSize);
frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
}
// Add the undo edit
IUndoableEdit edit = new AUndoableEdit(editLID) {
@Override
public String getPresentationName() {
return (imageData == null) ? removeBackgroundImage : setBackgroundImage;
}
@Override
public void redo() {
super.redo();
// selected frames
try {
for (Frame frame : frames) {
frame.setBackgroundImage(imageData, imageSize);
frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
}
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Redo set background image failed", ex);
}
}
@Override
public void undo() {
super.undo();
try {
// iterate through frames
Iterator<Entry<Frame, ImageData>> imageEntryIterator = previousImageData.entrySet().iterator();
while (imageEntryIterator.hasNext()) {
Entry<Frame, ImageData> imageEntry = imageEntryIterator.next();
Frame f = imageEntry.getKey();
ImageData id = imageEntry.getValue();
f.setBackgroundImage(id.data, id.bounds);
f.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, id.imageURL);
}
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Undo set background image failed", ex);
}
}
};
undoMgr.addEdit(edit);
for (Frame frame : frames) {
UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
frameMgr.addEdit(edit);
}
} catch (GraphicsUtil.ImageException e) {
// setBackgroundImage and GraphicsUtil.getImageBounds may
// throw ImageException, translating any other exception.
interaction.protestInvalidImageFile();
}
}
use of java.util.Map.Entry in project cogtool by cogtool.
the class DesignEditorController method spaceFramesEqually.
/**
* Spaces the selected frames equally along a certain axis
* @param vertical true for vertical axis; false for horizontal
*/
protected boolean spaceFramesEqually(Map<Frame, DoubleRectangle> frameMap, final boolean vertical) {
final String undoRedoLabel = vertical ? SPACE_VERTICALLY : SPACE_HORIZONTALLY;
CogToolLID lid = vertical ? DesignEditorLID.SpaceVertically : DesignEditorLID.SpaceHorizontally;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
// Order the widgets according to location
// (either from the left or from the top)
Comparator<Map.Entry<Frame, DoubleRectangle>> c = vertical ? frameVerticalComparator : frameHorizontalComparator;
@SuppressWarnings("unchecked") Map.Entry<Frame, DoubleRectangle>[] entries = new Map.Entry[frameMap.size()];
frameMap.entrySet().toArray(entries);
Arrays.sort(entries, c);
// Calculate the spacing between widgets
double sum = 0;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
// this can then be used to do spacing.
for (Entry<Frame, DoubleRectangle> entrie : entries) {
DoubleRectangle bounds = entrie.getValue();
double size = vertical ? bounds.height : bounds.width;
double position = vertical ? bounds.y : bounds.x;
sum += size;
min = Math.min(min, position);
max = Math.max(max, size + position);
}
// Get the spacing to use between each item.
double spacing = ((max - min) - sum) / (entries.length - 1);
// Adjust the spacings to the correct values
for (Entry<Frame, DoubleRectangle> entrie : entries) {
// go through each frame and set the frame's origin
final Frame f = entrie.getKey();
final DoubleRectangle bounds = entrie.getValue();
// TODO (dfm) this is probably the place to walk over the design pre-flighting
// problems we want to warn the user about, and give the opportunity
// to skip the export if desired
// Determine the old point...
final double p_old = vertical ? bounds.y : bounds.x;
final double p_new = min;
// Set the new location
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
// Advance the pointer to the next location
min += spacing + (vertical ? bounds.height : bounds.width);
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return undoRedoLabel;
}
@Override
public void redo() {
super.redo();
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
}
@Override
public void undo() {
super.undo();
f.setFrameOrigin(vertical ? bounds.x : p_old, vertical ? p_old : bounds.y);
}
};
editSequence.addEdit(edit);
}
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
Aggregations