当前位置: 首页>>代码示例>>Java>>正文


Java SortedSet.last方法代码示例

本文整理汇总了Java中java.util.SortedSet.last方法的典型用法代码示例。如果您正苦于以下问题:Java SortedSet.last方法的具体用法?Java SortedSet.last怎么用?Java SortedSet.last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.SortedSet的用法示例。


在下文中一共展示了SortedSet.last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractFormToChatCondition

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * Extract form content to taskListContent.
    *
    * @param request
    * @param form
    * @throws ChatException
    */
   private void extractFormToChatCondition(HttpServletRequest request, ChatConditionForm form) throws Exception {

SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<ChatCondition> conditionSet = getChatConditionSet(sessionMap);
int orderId = form.getOrderId();
ChatCondition condition = null;

if (orderId == -1) { // add
    String properConditionName = getChatService().createConditionName(conditionSet);
    condition = form.extractCondition();
    condition.setName(properConditionName);
    int maxSeq = 1;
    if (conditionSet != null && conditionSet.size() > 0) {
	ChatCondition last = conditionSet.last();
	maxSeq = last.getOrderId() + 1;
    }
    condition.setOrderId(maxSeq);
    conditionSet.add(condition);
} else { // edit
    List<ChatCondition> conditionList = new ArrayList<ChatCondition>(conditionSet);
    condition = conditionList.get(orderId - 1);
    form.extractCondition(condition);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:AuthoringChatConditionAction.java

示例2: create

import java.util.SortedSet; //导入方法依赖的package包/类
@Override
protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  if (set.isEmpty()) {
    /*
     * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
     * greater than tooHigh.
     */
    return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1);
  }
  int tooHigh = set.last() + 1;
  int tooLow = set.first() - 1;
  set.add(tooHigh);
  set.add(tooLow);
  return checkedCreate(set).subSet(tooLow + 1, tooHigh);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:17,代码来源:SetGenerators.java

示例3: getMaxValueInList

import java.util.SortedSet; //导入方法依赖的package包/类
private static int getMaxValueInList(final SortedSet<Integer> tagPositions) {
    final int result = 0;

    if (tagPositions != null) {
        return tagPositions.last();
    }
    return result;
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:9,代码来源:RollUpBitMask.java

示例4: last

import java.util.SortedSet; //导入方法依赖的package包/类
@Override
public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
    E element = sortedUnfiltered.last();
    if (predicate.apply(element)) {
      return element;
    }
    sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:Sets.java

示例5: create

import java.util.SortedSet; //导入方法依赖的package包/类
@Override
protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  int tooHigh = (set.isEmpty()) ? 0 : set.last() + 1;
  set.add(tooHigh);
  return checkedCreate(set).headSet(tooHigh);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:SetGenerators.java

示例6: extractFormToQaCondition

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * Extract form content to QaCondition.
    *
    * @param request
    * @param form
    * @throws QaException
    */
   private void extractFormToQaCondition(HttpServletRequest request, QaConditionForm form) throws Exception {

SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<QaCondition> conditionSet = getQaConditionSet(sessionMap);
int orderId = form.getOrderId();
QaCondition condition = null;

if (orderId == -1) { // add
    String properConditionName = getQaService().createConditionName(conditionSet);
    condition = form.extractCondition();
    condition.setName(properConditionName);
    int maxOrderId = 1;
    if (conditionSet != null && conditionSet.size() > 0) {
	QaCondition last = conditionSet.last();
	maxOrderId = last.getOrderId() + 1;
    }
    condition.setOrderId(maxOrderId);
    conditionSet.add(condition);
} else { // edit
    List<QaCondition> conditionList = new ArrayList<QaCondition>(conditionSet);
    condition = conditionList.get(orderId - 1);
    form.extractCondition(condition);
}

Integer[] selectedItems = form.getSelectedItems();
List<QaQuestionDTO> questions = getQuestionList(sessionMap);

condition.temporaryQuestionDTOSet.clear();
for (Integer selectedItem : selectedItems) {
    for (QaQuestionDTO question : questions) {
	if (selectedItem.equals(new Integer(question.getDisplayOrder()))) {
	    condition.temporaryQuestionDTOSet.add(question);
	}
    }
}

   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:QaAuthoringConditionAction.java

示例7: chooseOptimalSize

import java.util.SortedSet; //导入方法依赖的package包/类
/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
Size chooseOptimalSize(Size[] choices, int textureViewWidth,
                       int textureViewHeight, int maxWidth, int maxHeight) {
    mPreviewSizes.clear();
    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = mAspectRatio.getX();
    int h = mAspectRatio.getY();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight) {
            mPreviewSizes.add(new cn.lytcom.cameraview.Size(option.getWidth(), option.getHeight()));
            if (option.getHeight() == option.getWidth() * h / w) {
                if (option.getWidth() >= textureViewWidth &&
                    option.getHeight() >= textureViewHeight) {
                    bigEnough.add(option);
                } else {
                    notBigEnough.add(option);
                }
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        mAspectRatio = AspectRatio.of(4, 3);
        SortedSet<cn.lytcom.cameraview.Size> sortedSet = mPreviewSizes.sizes(mAspectRatio);
        if (sortedSet != null) {
            cn.lytcom.cameraview.Size lastSize = sortedSet.last();
            return new Size(lastSize.getWidth(), lastSize.getHeight());
        }
        mAspectRatio = AspectRatio.of(choices[0].getWidth(), choices[0].getHeight());
        return choices[0];
    }
}
 
开发者ID:lytcom,项目名称:CameraKitView,代码行数:57,代码来源:Camera2Fragment.java

示例8: saveQTI

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * Parses questions extracted from IMS QTI file and adds them as new items.
    */
   @SuppressWarnings("rawtypes")
   private ActionForward saveQTI(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws UnsupportedEncodingException {
// big part of code was taken from saveItem() method
String sessionMapId = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapId);
String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID);
SortedSet<ScratchieItem> itemList = getItemList(sessionMap);

Question[] questions = QuestionParser.parseQuestionChoiceForm(request);
for (Question question : questions) {
    ScratchieItem item = new ScratchieItem();
    item.setCreateDate(new Timestamp(new Date().getTime()));
    int maxSeq = 1;
    if (itemList != null && itemList.size() > 0) {
	ScratchieItem last = itemList.last();
	maxSeq = last.getOrderId() + 1;
    }
    item.setOrderId(maxSeq);
    item.setTitle(question.getTitle());
    item.setDescription(QuestionParser.processHTMLField(question.getText(), false, contentFolderID,
	    question.getResourcesFolderPath()));

    TreeSet<ScratchieAnswer> answerList = new TreeSet<ScratchieAnswer>(new ScratchieAnswerComparator());
    String correctAnswer = null;
    int orderId = 1;
    if (question.getAnswers() != null) {
	for (Answer answer : question.getAnswers()) {
	    String answerText = QuestionParser.processHTMLField(answer.getText(), false, contentFolderID,
		    question.getResourcesFolderPath());
	    if (correctAnswer != null && correctAnswer.equals(answerText)) {
		log.warn("Skipping an answer with same text as the correct answer: " + answerText);
		continue;
	    }
	    ScratchieAnswer scratchieAnswer = new ScratchieAnswer();
	    scratchieAnswer.setDescription(answerText);
	    scratchieAnswer.setOrderId(orderId++);

	    if ((answer.getScore() != null) && (answer.getScore() > 0)) {
		if (correctAnswer == null) {
		    scratchieAnswer.setCorrect(true);
		    correctAnswer = answerText;
		} else {
		    log.warn(
			    "Choosing only first correct answer, despite another one was found: " + answerText);
		    scratchieAnswer.setCorrect(false);
		}
	    } else {
		scratchieAnswer.setCorrect(false);
	    }

	    answerList.add(scratchieAnswer);
	}
    }

    if (correctAnswer == null) {
	log.warn("No correct answer found for question: " + question.getText());
	continue;
    }

    item.setAnswers(answerList);
    itemList.add(item);
    if (log.isDebugEnabled()) {
	log.debug("Added question: " + question.getText());
    }
}

request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapId);
return mapping.findForward(ScratchieConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:75,代码来源:AuthoringAction.java

示例9: performRender

import java.util.SortedSet; //导入方法依赖的package包/类
@Override
protected void performRender ( final Graphics g, final Rectangle clientRect )
{
    final XAxis xAxis = this.seriesData.getXAxis ();
    final YAxis yAxis = this.seriesData.getYAxis ();

    g.setBackground ( this.color );
    g.setAlpha ( 128 );

    final SortedSet<DataEntry> entries = this.seriesData.getViewData ().getEntries ();
    if ( entries.isEmpty () )
    {
        g.fillRectangle ( clientRect );
        return;
    }

    g.setClipping ( clientRect );

    final DataPoint point = new DataPoint ();

    Integer lastPosition = null;
    Integer lastValidPosition = null;

    final DataEntry first = entries.first ();
    translateToPoint ( clientRect, xAxis, yAxis, point, first );
    if ( point.x > 0 )
    {
        g.fillRectangle ( clientRect.x, clientRect.y, (int)point.x - clientRect.x, clientRect.height );
    }

    final DataEntry last = entries.last ();
    translateToPoint ( clientRect, xAxis, yAxis, point, last );
    if ( point.x >= 0 && point.x < clientRect.width )
    {
        g.fillRectangle ( (int)point.x, clientRect.y, (int) ( clientRect.width - ( point.x - 1 - clientRect.x ) ), clientRect.height );
    }
    else if ( point.x < 0 )
    {
        g.fillRectangle ( clientRect );
    }

    for ( final DataEntry entry : entries )
    {
        final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry );

        final boolean qualityOk = checkQuality ( hasData, entry.getValue () );

        if ( lastPosition != null )
        {
            g.fillRectangle ( lastPosition, clientRect.y, (int)point.x - lastPosition, clientRect.height );
        }

        if ( !qualityOk )
        {
            if ( lastValidPosition != null && lastPosition == null )
            {
                g.fillRectangle ( lastValidPosition, clientRect.y, (int)point.x - lastValidPosition, clientRect.height );
            }
            lastPosition = (int)point.x;
        }
        else
        {
            lastValidPosition = (int)point.x;
            lastPosition = null;
        }
    }

    g.setClipping ( clientRect );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:70,代码来源:QualityRenderer.java

示例10: saveItem

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * This method will get necessary information from assessment question form and save or update into
    * <code>HttpSession</code> AssessmentQuestionList. Notice, this save is not persist them into database, just save
    * <code>HttpSession</code> temporarily. Only they will be persist when the entire authoring page is being
    * persisted.
    */
   private ActionForward saveItem(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {

ScratchieItemForm itemForm = (ScratchieItemForm) form;
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(itemForm.getSessionMapID());
// check whether it is "edit(old Question)" or "add(new Question)"
SortedSet<ScratchieItem> itemList = getItemList(sessionMap);
int itemIdx = NumberUtils.toInt(itemForm.getItemIndex(), -1);
ScratchieItem item = null;

if (itemIdx == -1) { // add
    item = new ScratchieItem();
    item.setCreateDate(new Timestamp(new Date().getTime()));
    int maxSeq = 1;
    if (itemList != null && itemList.size() > 0) {
	ScratchieItem last = itemList.last();
	maxSeq = last.getOrderId() + 1;
    }
    item.setOrderId(maxSeq);
    itemList.add(item);
} else { // edit
    List<ScratchieItem> rList = new ArrayList<ScratchieItem>(itemList);
    item = rList.get(itemIdx);
}

item.setTitle(itemForm.getTitle());
item.setDescription(itemForm.getDescription());

// set options
Set<ScratchieAnswer> answerList = getAnswersFromRequest(request, true);
Set<ScratchieAnswer> answers = new LinkedHashSet<ScratchieAnswer>();
int orderId = 0;
for (ScratchieAnswer answer : answerList) {
    answer.setOrderId(orderId++);
    answers.add(answer);
}
item.setAnswers(answers);

// set session map ID so that itemlist.jsp can get sessionMAP
request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, itemForm.getSessionMapID());
return mapping.findForward(ScratchieConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:AuthoringAction.java

示例11: chooseOptimalSize

import java.util.SortedSet; //导入方法依赖的package包/类
/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
android.util.Size chooseOptimalSize(android.util.Size[] choices, int textureViewWidth,
                                    int textureViewHeight, int maxWidth, int maxHeight) {
    mPreviewSizes.clear();
    // Collect the supported resolutions that are at least as big as the preview Surface
    List<android.util.Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<android.util.Size> notBigEnough = new ArrayList<>();
    int w = mAspectRatio.getX();
    int h = mAspectRatio.getY();
    for (android.util.Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight) {
            mPreviewSizes.add(new cn.lytcom.cameraview.Size(option.getWidth(), option.getHeight()));
            if (option.getHeight() == option.getWidth() * h / w) {
                if (option.getWidth() >= textureViewWidth &&
                    option.getHeight() >= textureViewHeight) {
                    bigEnough.add(option);
                } else {
                    notBigEnough.add(option);
                }
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        mAspectRatio = AspectRatio.of(4, 3);
        SortedSet<Size> sortedSet = mPreviewSizes.sizes(mAspectRatio);
        if (sortedSet != null) {
            cn.lytcom.cameraview.Size lastSize = sortedSet.last();
            return new android.util.Size(lastSize.getWidth(), lastSize.getHeight());
        }
        mAspectRatio = AspectRatio.of(choices[0].getWidth(), choices[0].getHeight());
        return choices[0];
    }
}
 
开发者ID:lytcom,项目名称:CameraKitView,代码行数:57,代码来源:Camera2.java

示例12: process

import java.util.SortedSet; //导入方法依赖的package包/类
@Override
public boolean process(AudioEvent audioEvent) {
		float[] buffer = audioEvent.getFloatBuffer().clone();
	float[] magnitudes = new float[buffer.length/2];
	float[] chroma = new float[12];
	fft.forwardTransform(buffer);
	fft.modulus(buffer, magnitudes);
	
	//make chroma with C as starting point (MIDI key 0) 
	for(int i = 0 ; i < magnitudes.length ;i++){
		//only process from MIDI key 29 (43Hz) to 107 (3951Hz) 
		if(binStartingPointsInCents[i] > 2900 && binStartingPointsInCents[i] < 10700){
			magnitudes[i] = (float) Math.log1p(magnitudes[i]);
			int  chromaIndex = Math.round(binStartingPointsInCents[i]/100) % 12;
			chroma[chromaIndex] += magnitudes[i];
		}
	}
	
	//normalize on the euclidean norm
	float squares = 0;
	for(int i = 0 ; i < chroma.length ; i++){
		squares += chroma[i] * chroma[i];
	}
	squares = (float) Math.sqrt(squares);
	for(int i = 0 ; i < chroma.length ; i++){
		chroma[i] = chroma[i]/squares;
	}
	
	//keep a running median
	for(int i = 0 ; i < chroma.length ; i++){
		orderedMagnitudes.add(chroma[i]);
		if(orderedMagnitudes.size()==1){
			currentMedian = chroma[i];
		}else{
			SortedSet<Float> h = orderedMagnitudes.headSet(currentMedian,true);
            SortedSet<Float> t = orderedMagnitudes.tailSet(currentMedian,false);
            int x = 1 - orderedMagnitudes.size() % 2;
            if (h.size() < t.size() + x)
            	currentMedian = t.first();
            else if (h.size() > t.size() + x)
            	currentMedian = h.last();
		}
	}
	
	
	//use the running median to binarize chroma
	for(int i = 0 ; i < chroma.length ; i++){
		if(chroma[i] > currentMedian)
			chroma[i] = 1;
		else
			chroma[i] = 0;
	}
	
	
			
	float timeStamp = (float) audioEvent.getTimeStamp();
	this.magnitudes.put(timeStamp , magnitudes);
	this.chromaMagnitudes.put(timeStamp, chroma);
			
	return true;
}
 
开发者ID:JorenSix,项目名称:Panako,代码行数:62,代码来源:ChromaPrintExtractor.java

示例13: add

import java.util.SortedSet; //导入方法依赖的package包/类
/**
 * Add the range indices. It is ensured that the added range 
 * doesn't overlap the existing ranges. If it overlaps, the 
 * existing overlapping ranges are removed and a single range 
 * having the superset of all the removed ranges and this range 
 * is added. 
 * If the range is of 0 length, doesn't do anything.
 * @param range Range to be added.
 */
synchronized void add(Range range){
  if(range.isEmpty()) {
    return;
  }
  
  long startIndex = range.getStartIndex();
  long endIndex = range.getEndIndex();
  //make sure that there are no overlapping ranges
  SortedSet<Range> headSet = ranges.headSet(range);
  if(headSet.size()>0) {
    Range previousRange = headSet.last();
    LOG.debug("previousRange "+previousRange);
    if(startIndex<previousRange.getEndIndex()) {
      //previousRange overlaps this range
      //remove the previousRange
      if(ranges.remove(previousRange)) {
        indicesCount-=previousRange.getLength();
      }
      //expand this range
      startIndex = previousRange.getStartIndex();
      endIndex = endIndex>=previousRange.getEndIndex() ?
                        endIndex : previousRange.getEndIndex();
    }
  }
  
  Iterator<Range> tailSetIt = ranges.tailSet(range).iterator();
  while(tailSetIt.hasNext()) {
    Range nextRange = tailSetIt.next();
    LOG.debug("nextRange "+nextRange +"   startIndex:"+startIndex+
        "  endIndex:"+endIndex);
    if(endIndex>=nextRange.getStartIndex()) {
      //nextRange overlaps this range
      //remove the nextRange
      tailSetIt.remove();
      indicesCount-=nextRange.getLength();
      if(endIndex<nextRange.getEndIndex()) {
        //expand this range
        endIndex = nextRange.getEndIndex();
        break;
      }
    } else {
      break;
    }
  }
  add(startIndex,endIndex);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:56,代码来源:SortedRanges.java

示例14: addQuestionReference

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * Remove assessment question from HttpSession list and update page display. As authoring rule, all persist only
    * happen when user submit whole page. So this remove is just impact HttpSession values.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */
   private ActionForward addQuestionReference(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, AssessmentConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
updateQuestionReferencesGrades(request, sessionMap, false);

SortedSet<QuestionReference> references = getQuestionReferences(sessionMap);
int questionIdx = NumberUtils.toInt(request.getParameter(AssessmentConstants.PARAM_QUESTION_INDEX), -1);

// set SequenceId
QuestionReference reference = new QuestionReference();
int maxSeq = 1;
if ((references != null) && (references.size() > 0)) {
    QuestionReference last = references.last();
    maxSeq = last.getSequenceId() + 1;
}
reference.setSequenceId(maxSeq);

// set isRandomQuestion
boolean isRandomQuestion = (questionIdx == -1);
reference.setRandomQuestion(isRandomQuestion);

if (isRandomQuestion) {
    reference.setDefaultGrade(1);
} else {
    SortedSet<AssessmentQuestion> questionList = getQuestionList(sessionMap);
    AssessmentQuestion question = null;
    for (AssessmentQuestion questionFromList : questionList) {
	if (questionFromList.getSequenceId() == questionIdx) {
	    question = questionFromList;
	    break;
	}
    }
    reference.setQuestion(question);

    reference.setDefaultGrade(question.getDefaultGrade());
}
references.add(reference);

reinitializeAvailableQuestions(sessionMap);

request.setAttribute(AssessmentConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return mapping.findForward(AssessmentConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:AuthoringAction.java

示例15: extractFormToTaskListCondition

import java.util.SortedSet; //导入方法依赖的package包/类
/**
    * Extract form content to taskListContent.
    *
    * @param request
    * @param form
    * @throws TaskListException
    */
   private void extractFormToTaskListCondition(HttpServletRequest request, TaskListConditionForm form)
    throws Exception {
/*
 * BE CAREFUL: This method will copy necessary info from request form to a old or new TaskListItem instance. It
 * gets all info EXCEPT TaskListItem.createDate and TaskListItem.createBy, which need be set when persisting
 * this taskList item.
 */

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(form.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<TaskListCondition> conditionList = getTaskListConditionList(sessionMap);
int sequenceId = NumberUtils.stringToInt(form.getSequenceId(), -1);
TaskListCondition condition = null;

if (sequenceId == -1) { // add
    condition = new TaskListCondition();
    int maxSeq = 1;
    if (conditionList != null && conditionList.size() > 0) {
	TaskListCondition last = conditionList.last();
	maxSeq = last.getSequenceId() + 1;
    }
    condition.setSequenceId(maxSeq);
    conditionList.add(condition);
} else { // edit
    List<TaskListCondition> rList = new ArrayList<TaskListCondition>(conditionList);
    condition = rList.get(sequenceId);
}

condition.setName(form.getName());

String[] selectedItems = form.getSelectedItems();
SortedSet<TaskListItem> itemList = getTaskListItemList(sessionMap);
SortedSet<TaskListItem> conditionItemList = new TreeSet<TaskListItem>(new TaskListItemComparator());

for (String selectedItem : selectedItems) {
    for (TaskListItem item : itemList) {
	if (selectedItem.equals((new Integer(item.getSequenceId())).toString())) {
	    conditionItemList.add(item);
	}
    }
}
condition.setTaskListItems(conditionItemList);

   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:AuthoringTaskListConditionAction.java


注:本文中的java.util.SortedSet.last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。