예제 #1
0
 @Override
 public ImmoXmlVersion getPreviousVersion() {
   ImmoXmlVersion[] versions = ImmoXmlVersion.values();
   int pos = ArrayUtils.indexOf(versions, this);
   pos--;
   return (pos >= 0) ? versions[pos] : null;
 }
  /**
   * Adds cosimilarities to the matrix for a set of row ids and col ids.
   *
   * @param rowIds
   * @param colIds
   * @param cosims
   * @param transpose If true, the cosims matrix is transposed.
   * @throws IOException
   */
  private void addCosims(int rowIds[], int colIds[], float cosims[][], boolean transpose)
      throws IOException {
    // Compute dense indexes for sparse column ids
    int colIndexes[] = new int[colIds.length];
    for (int i = 0; i < colIds.length; i++) {
      colIndexes[i] = ArrayUtils.indexOf(similarityMatrix.getColIds(), colIds[i]);
    }

    for (int i = 0; i < rowIds.length; i++) {
      DenseMatrixRow row = similarityMatrix.getRow(rowIds[i]);
      if (row == null) continue;
      for (int j = 0; j < colIds.length; j++) {
        int col = colIndexes[j];
        if (col >= 0) {
          assert (row.getColIndex(col) == colIds[j]);
          float sim = row.getColValue(col);

          // Add half of sim to each symmetric entry in the matrix .
          // The other half comes from the transpose entry.
          if (transpose) {
            cosims[j][i] += sim * 0.5;
          } else {
            cosims[i][j] += sim * 0.5;
          }
        }
      }
    }
  }
예제 #3
0
 @Override
 public ImmoXmlVersion getNextVersion() {
   ImmoXmlVersion[] versions = ImmoXmlVersion.values();
   int pos = ArrayUtils.indexOf(versions, this);
   pos++;
   return (versions.length > pos) ? versions[pos] : null;
 }
예제 #4
0
 @Override
 public boolean isNewerThen(XmlVersion v) {
   ImmoXmlVersion[] versions = ImmoXmlVersion.values();
   return ArrayUtils.indexOf(versions, this) > ArrayUtils.indexOf(versions, v);
 }
  /**
   * 處理確定加選學生選課內容之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward add(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
    HttpSession session = request.getSession(false);
    DynaActionForm aForm = (DynaActionForm) form;
    Seld seld = processSeldByForm(aForm);
    session.setAttribute("seldInfoForOnline", seld);
    Dtime dtime = cm.findDtimeBy(seld.getDtimeOid());

    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {
      try {
        // 會以紙本作業完成加選,無需考慮衝堂問題
        // 選課人數上線於前端JavaScript判斷
        // 跨選設定不允許須阻擋並顯示訊息
        // 會顯示衝堂訊息
        MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
        ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
        Student student = mm.findStudentByNo(seld.getStudentNo());
        ScoreHist scoreHist = new ScoreHist(student.getStudentNo());
        List<ScoreHist> scoreHistList = sm.findScoreHistBy(scoreHist);
        String[] cscodeHist = new String[0];
        Float[] scoreList = new Float[0];
        float passScore = Toolket.getPassScoreByDepartClass(student.getDepartClass());
        for (ScoreHist hist : scoreHistList) {
          cscodeHist = (String[]) ArrayUtils.add(cscodeHist, hist.getCscode().toUpperCase());
          // 抵免要給分數,不然就會被當做無修課記錄而被加選成功
          if ("6".equals(hist.getEvgrType()))
            scoreList =
                (Float[])
                    ArrayUtils.add(
                        scoreList, hist.getScore() != null ? hist.getScore() : passScore);
          else scoreList = (Float[]) ArrayUtils.add(scoreList, hist.getScore());
        }

        int ind = 0, startIndex = 0;
        boolean isHist = false;
        do {
          ind = ArrayUtils.indexOf(cscodeHist, seld.getCscode().toUpperCase(), startIndex);
          startIndex = ind + 1;
          // 判斷是否選過且及格
          isHist =
              ind != StringUtils.INDEX_NOT_FOUND
                  && scoreList[ind] != null
                  && scoreList[ind] >= passScore;
        } while (!isHist && ind != StringUtils.INDEX_NOT_FOUND);

        // 特殊班級(跨校生等)無條件加選
        String[] specialDepartClass = {"1152A", "1220", "122A", "122B", "2220"};
        String[] addGrade = {"42", "52"}; // 2技學生年級要+2
        int stuGrade =
            ArrayUtils.contains(specialDepartClass, student.getDepartClass())
                ? 9
                : Integer.parseInt(StringUtils.substring(student.getDepartClass(), 4, 5));
        stuGrade =
            ArrayUtils.contains(addGrade, StringUtils.substring(student.getDepartClass(), 1, 3))
                ? stuGrade + 2
                : stuGrade;
        int dtimeGrade = Integer.parseInt(StringUtils.substring(dtime.getDepartClass(), 4, 5));

        if (isHist) {
          messages.add(
              ActionMessages.GLOBAL_MESSAGE,
              new ActionMessage("Course.errorN1", "歷年資料查詢到已修過該科目,請確認,謝謝!!"));
          saveErrors(request, messages);
        } else if (stuGrade >= dtimeGrade) {
          // 判斷學生年級與課程所開班級年級
          cm.txAddSelectedSeld(seld, student, "1", true);
          String idno = getUserCredential(request.getSession(false)).getMember().getIdno();
          cm.txSaveAdcdHistory(seld.getDtimeOid(), student.getStudentNo().toUpperCase(), idno, "A");
          if (ind != StringUtils.INDEX_NOT_FOUND)
            messages.add(
                ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("Course.errorN1", "該科目於歷年資料有查詢到,但該科目未及格,所以加選成功。"));
          else
            messages.add(
                ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.CreateSuccessful"));
          saveMessages(request, messages);
        } else {
          messages.add(
              ActionMessages.GLOBAL_MESSAGE,
              new ActionMessage(
                  "Course.messageN1",
                  "注意:學生低修高年級課程,加選作業尚未完成!<br/>"
                      + "&nbsp;&nbsp;&nbsp;&nbsp;按下[再次確定]鍵後課程才會加入學生選課資料中。"));
          saveErrors(request, messages);
          setContentPage(request.getSession(false), "course/OnlineAddHigherCourse.jsp");
          return mapping.findForward(IConstants.ACTION_MAIN_NAME);
        }

        Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
        return list(mapping, form, request, response);
      } catch (SeldException se) {
        ActionMessages errors = new ActionMessages();
        errors.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.errorN1", se.getMessage()));
        saveErrors(request, errors);
        if (se.getMessage().indexOf("衝堂") != StringUtils.INDEX_NOT_FOUND) {
          // 目前會拒絕衝堂課程進行加選
          dtime = cm.findDtimeBy(seld.getDtimeOid());
          Csno csno = cm.findCourseInfoByCscode(dtime.getCscode());
          request.setAttribute("csnoInfo", csno);
          request.setAttribute("classInfo", Toolket.getClassFullName(dtime.getDepartClass()));
          setContentPage(request.getSession(false), "course/ConflictList.jsp");
          return list(mapping, form, request, response);
        } else return list(mapping, form, request, response);
      }
    }
  }
  @Override
  public void eval(final ExecutionContext context) {
    /*
     * Eval left
     */
    context.newCallStackFrame(LEFT_POS);
    left.eval(context);
    context.returnFromCallFrame();
    /*
     * If it is a function pointer, then create a new function call
     */
    final Object target = left.getAnnotation();
    if (isApply && target instanceof FunctionDefinition) {
      final FunctionDefinition fd = (FunctionDefinition) target;
      /*
       * Currently, there is no change in the codepath when superscript is
       * executed: f.apply(...) is exactly equivalent to f(...).
       */
      final FunctionCall fc;
      final boolean hasCall = getSuperscript() instanceof FunctionCall;
      final FunctionCall prevFC = hasCall ? (FunctionCall) getSuperscript() : null;
      if (hasCall && fd.equals(prevFC.getFunctionDefinition())) {
        fc = prevFC;
      } else {
        fc = new FunctionCall(fd, deepCopyBranches());
      }
      setSuperscript(fc);
      fc.eval(context);
      setAnnotation(fc.getAnnotation());
    } else {
      /*
       * Otherwise, evaluate branches and proceed to evaluation
       */
      projectAndEval(context);
      /*
       *  Check everything for fields
       */
      final Stream<?> argsstr = getBranchesAnnotationStream();
      final Object[] args = argsstr.toArray();
      /*
       *  collect any field indices
       */

      List<Integer> list = new ArrayList<>();
      for (Object o : args) {
        if (Field.class.isAssignableFrom(o.getClass())) {
          list.add(ArrayUtils.indexOf(args, o));
        }
      }
      final int[] fieldIndexes = new int[list.size()];
      for (Integer i : list) {
        fieldIndexes[i] = list.get(i);
      }
      // End

      /*
       *  if there are any fields, do a field apply:
       */
      final boolean fieldTarget = target instanceof Field;
      if (fieldTarget || fieldIndexes.length > 0) {
        /*
         * Run on every element of the field, and at each iteration use the
         * current annotation as corresponding element for the field. Once
         * done, set the entire field as annotation.
         */
        final Field res =
            Fields.apply(
                new BiFunction<Object, Object[], Object>() {
                  @Override
                  public Object apply(Object actualT, Object[] actualA) {
                    return ReflectionUtils.invokeBestNotStatic(actualT, methodName, actualA);
                  }
                },
                fieldTarget,
                fieldIndexes,
                target,
                args);
        setAnnotation(res);
      } else {
        final Object annotation = ReflectionUtils.invokeBestNotStatic(target, methodName, args);
        setAnnotation(annotation);
      }
    }
  }
예제 #7
0
  /**
   * Fill a Java VoltTable with random values. If created with TableHelper.quickTable(..), then it
   * will respect unique columns, pkey uniqueness, column widths and nullability
   */
  public static void randomFill(VoltTable table, int rowCount, int maxStringSize, Random rand) {
    int[] pkeyIndexes = table.getPkeyColumnIndexes();

    Set<Tuple> pkeyValues = new HashSet<Tuple>();

    // figure out which columns must have unique values
    Map<Integer, Set<Object>> uniqueValues = new TreeMap<Integer, Set<Object>>();
    for (int col = 0; col < table.getColumnCount(); col++) {
      if (table.getColumnUniqueness(col)) {
        uniqueValues.put(col, new HashSet<Object>());
      }
    }

    for (int i = 0; i < rowCount; i++) {
      Object[] row;
      Tuple pkey = new Tuple(pkeyIndexes.length);
      // build the row
      boolean success = false;
      trynewrow:
      while (!success) {
        // create a candidate row
        row = randomRow(table, maxStringSize, rand);

        // store pkey values for row
        for (int col = 0; col < table.getColumnCount(); col++) {
          int pkeyIndex = ArrayUtils.indexOf(pkeyIndexes, col);
          if (pkeyIndex != -1) {
            pkey.values[pkeyIndex] = row[col];
          }
        }

        // check pkey
        if (pkeyIndexes.length > 0) {
          if (pkeyValues.contains(pkey)) {
            // System.err.println("randomFill: skipping tuple because of pkey violation");
            continue trynewrow;
          }
        }

        // check unique cols
        for (int col = 0; col < table.getColumnCount(); col++) {
          Set<Object> uniqueColValues = uniqueValues.get(col);
          if (uniqueColValues != null) {
            if (uniqueColValues.contains(row[col])) {
              // System.err.println("randomFill: skipping tuple because of uniqe col violation");
              continue trynewrow;
            }
          }
        }

        // update pkey
        if (pkeyIndexes.length > 0) {
          pkeyValues.add(pkey);
        }

        // update unique cols
        for (int col = 0; col < table.getColumnCount(); col++) {
          Set<Object> uniqueColValues = uniqueValues.get(col);
          if (uniqueColValues != null) {
            uniqueColValues.add(row[col]);
          }
        }

        // add the row
        table.addRow(row);
        success = true;
      }
    }
  }
  private void showUpdateIntervalTimePreferencesDialog() {
    final Context context = ui.getActivity();

    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(R.string.pref_autoUpdateIntervallOrTime_title);
    builder.content(R.string.pref_autoUpdateIntervallOrTime_message);
    builder.positiveText(R.string.pref_autoUpdateIntervallOrTime_Interval);
    builder.negativeText(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay);
    builder.neutralText(R.string.pref_autoUpdateIntervallOrTime_Disable);
    builder.onPositive(
        (dialog, which) -> {
          AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
          builder1.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval));
          final String[] values =
              context.getResources().getStringArray(R.array.update_intervall_values);
          final String[] entries = getUpdateIntervalEntries(values);
          long currInterval = UserPreferences.getUpdateInterval();
          int checkedItem = -1;
          if (currInterval > 0) {
            String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval));
            checkedItem = ArrayUtils.indexOf(values, currIntervalStr);
          }
          builder1.setSingleChoiceItems(
              entries,
              checkedItem,
              (dialog1, which1) -> {
                int hours = Integer.parseInt(values[which1]);
                UserPreferences.setUpdateInterval(hours);
                dialog1.dismiss();
                setUpdateIntervalText();
              });
          builder1.setNegativeButton(context.getString(R.string.cancel_label), null);
          builder1.show();
        });
    builder.onNegative(
        (dialog, which) -> {
          int hourOfDay = 7, minute = 0;
          int[] updateTime = UserPreferences.getUpdateTimeOfDay();
          if (updateTime.length == 2) {
            hourOfDay = updateTime[0];
            minute = updateTime[1];
          }
          TimePickerDialog timePickerDialog =
              new TimePickerDialog(
                  context,
                  (view, selectedHourOfDay, selectedMinute) -> {
                    if (view.getTag() == null) { // onTimeSet() may get called twice!
                      view.setTag("TAGGED");
                      UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute);
                      setUpdateIntervalText();
                    }
                  },
                  hourOfDay,
                  minute,
                  DateFormat.is24HourFormat(context));
          timePickerDialog.setTitle(
              context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay));
          timePickerDialog.show();
        });
    builder.onNeutral(
        (dialog, which) -> {
          UserPreferences.setUpdateInterval(0);
          setUpdateIntervalText();
        });
    builder.show();
  }
예제 #9
0
 /**
  * @param rowLabel
  * @param colLabel
  * @return
  */
 public double get(String rowLabel, String colLabel) {
   int row = ArrayUtils.indexOf(rowLabels, rowLabel);
   int col = ArrayUtils.indexOf(colLabels, colLabel);
   return table[row][col];
 }
예제 #10
0
 /**
  * @param rowLabel
  * @param colLabel
  * @param val
  */
 public void set(String rowLabel, String colLabel, double val) {
   int row = ArrayUtils.indexOf(rowLabels, rowLabel);
   int col = ArrayUtils.indexOf(colLabels, colLabel);
   table[row][col] = val;
 }
 @Override
 public int getIndexOfChild(Object parent, Object child) {
   refreshCache(parent);
   return ArrayUtils.indexOf(currentChilds, child);
 }