Esempio n. 1
0
 static {
   error.put(9999, "失败");
   error.put(1000, "参数缺失");
   error.put(1001, "正在处理中");
   error.put(1002, "用户中途取消");
   error.put(1003, "用户名不存在");
   error.put(1004, "密码错误");
 }
Esempio n. 2
0
 /** Get the object associated with the ID in the session */
 protected Object getSessionIdObject(String id) {
   HttpSession session = getSession();
   synchronized (session) {
     BidiMap map = (BidiMap) session.getAttribute(SESSION_KEY_OBJ_MAP);
     if (map == null) {
       return null;
     }
     return map.getKey(id);
   }
 }
  private void checkStatusUpdate(
      Exchange exchange, List<Message> messageList, TelemetryObject incomingMessage) {
    // No reason to check polling, if nothing to poll
    if (PollStoreSetValues.getRequiredParameterValueDataStore().size() == 0) return;

    String dataStoreKey;
    if (commandsBidiMap.getKey(incomingMessage.getName()) == null) return;

    dataStoreKey = (String) commandsBidiMap.getKey(incomingMessage.getName());
    boolean statusUpdateParametersCorrect = true;
    /*
     * Int starts from 1 because first parameter is always name and doesnt
     * contain value.
     */
    for (int i = 1; i < incomingMessage.getParams().size() - 1; i++) {

      try {
        if (commandsThatReturnIntegrer.contains(incomingMessage.getName())) {
          statusUpdateParametersCorrect =
              checkIntegerParameterValue(
                  exchange,
                  messageList,
                  incomingMessage,
                  dataStoreKey,
                  statusUpdateParametersCorrect,
                  i);
        } else {
          statusUpdateParametersCorrect =
              checkBigDecimalParameterValue(
                  exchange,
                  messageList,
                  incomingMessage,
                  dataStoreKey,
                  statusUpdateParametersCorrect,
                  i);
        }
      } catch (NumberFormatException e) {
        statusUpdateParametersCorrect =
            checkStringParameterValue(
                exchange,
                messageList,
                incomingMessage,
                dataStoreKey,
                statusUpdateParametersCorrect,
                i);
      }
      if (statusUpdateParametersCorrect == false) {
        break;
      }
    }
    if (statusUpdateParametersCorrect == true) {
      PollStoreSetValues.getRequiredParameterValueDataStore().remove(dataStoreKey);
    }
  }
Esempio n. 4
0
  /**
   * Maps names to numbers (numbers are required by SVMLight format)
   *
   * @param names names (e.g., features, outcomes)
   * @return bidirectional map of name:number
   */
  public static BidiMap mapVocabularyToIntegers(SortedSet<String> names) {
    BidiMap result = new DualTreeBidiMap();

    // start numbering from 1
    int index = 1;
    for (String featureName : names) {
      result.put(featureName, index);
      index++;
    }

    return result;
  }
  @Test
  public void testGetVariableMap()
      throws BadExpressionException, ContradictionException, TimeoutException {
    FormulaBuilder formulaBuilder = new FormulaBuilder("(a and b) or (a and c)");

    BidiMap map = formulaBuilder.build().getVariableMap();

    assertTrue(map.size() == 3);
    assertTrue("a".equals(map.get(1)));
    assertTrue("b".equals(map.get(2)));
    assertTrue("c".equals(map.get(3)));
  }
Esempio n. 6
0
  /**
   * Saves the feature mapping to readable format, each line is a feature id and feature name,
   * sorted by feature id
   *
   * @param mapping mapping (name:id)
   * @param outputFile output file
   * @throws IOException
   */
  public static void saveMappingTextFormat(BidiMap mapping, File outputFile) throws IOException {
    PrintWriter pw = new PrintWriter(new FileOutputStream(outputFile));

    // sort values (feature indexes)
    @SuppressWarnings("unchecked")
    SortedSet<Object> featureIndexes = new TreeSet<Object>(mapping.values());

    for (Object featureIndex : featureIndexes) {
      pw.printf(
          Locale.ENGLISH, "%5d %s%n", (int) featureIndex, mapping.getKey(featureIndex).toString());
    }

    IOUtils.closeQuietly(pw);
  }
Esempio n. 7
0
  /**
   * Creates a new file in the same directory as {@code featureVectorsFile} and replaces the first
   * token (outcome label) by its corresponding integer number from the bi-di map
   *
   * @param featureVectorsFile file
   * @param labelsToIntegers mapping
   * @return new file
   */
  public static File replaceLabelsWithIntegers(File featureVectorsFile, BidiMap labelsToIntegers)
      throws IOException {
    File result =
        new File(
            featureVectorsFile.getParent(), "mappedLabelsToInt_" + featureVectorsFile.getName());
    PrintWriter pw = new PrintWriter(new FileOutputStream(result));

    BufferedReader br = new BufferedReader(new FileReader(featureVectorsFile));

    String line = null;
    while ((line = br.readLine()) != null) {
      // split on the first whitespaces, keep the rest
      String[] split = line.split("\\s", 2);
      String label = split[0];
      String remainingContent = split[1];

      // find the integer
      Integer intOutput = (Integer) labelsToIntegers.get(label);

      // print to the output stream
      pw.printf("%d %s%n", intOutput, remainingContent);
    }

    IOUtils.closeQuietly(pw);
    IOUtils.closeQuietly(br);

    return result;
  }
  private void checkPollingMessageType(
      Exchange exchange, List<Message> messageList, TelemetryObject incomingMessage) {

    if (exchange.getIn().getHeader(JMSConstants.HEADER_POLLING) != null) {
      if (exchange
          .getIn()
          .getHeader(JMSConstants.HEADER_POLLING)
          .equals(JMSConstants.POLL_SET_COMMAND)) {

        if (incomingMessage
            .getParameter(JMSConstants.GS_DEVICE_END_MESSAGE)
            .getValue()
            .equals("0")) {
          createPollingMessage(exchange, messageList, incomingMessage);
        } else {
          PollStoreSetValues.getRequiredParameterValueDataStore().remove(incomingMessage.getName());
        }
      }
      if (exchange
          .getIn()
          .getHeader(JMSConstants.HEADER_POLLING)
          .equals(JMSConstants.POLL_GET_COMMAND)) {
        if (incomingMessage
            .getParameter(JMSConstants.GS_DEVICE_END_MESSAGE)
            .getValue()
            .equals("0")) {
          checkStatusUpdate(exchange, messageList, incomingMessage);
        } else {
          PollStoreSetValues.getRequiredParameterValueDataStore()
              .remove(commandsBidiMap.getKey(incomingMessage.getName()));
        }
      }
    }
  }
Esempio n. 9
0
  /**
   * Verifies whether given class is primitive.
   *
   * @param className fully qualified class name to verify
   * @return true if given class is primitive; false otherwise
   */
  public static boolean isPrimitive(String className) {
    for (Object clazz : PRIMITIVE_TYPE_MAP.values()) {
      if (((Class) clazz).getName().equals(className)) {
        return true;
      }
    }

    return false;
  }
Esempio n. 10
0
 /** Get the ID with which the object is associated with the session, if any */
 protected String getSessionObjectId(Object obj) {
   HttpSession session = getSession();
   BidiMap map;
   synchronized (session) {
     map = (BidiMap) session.getAttribute(SESSION_KEY_OBJ_MAP);
     if (map == null) {
       map = new DualHashBidiMap();
       session.setAttribute(SESSION_KEY_OBJ_MAP, map);
     }
   }
   synchronized (map) {
     String id = (String) map.get(obj);
     if (id == null) {
       id = getNewSessionObjectId();
       map.put(obj, id);
     }
     return id;
   }
 }
Esempio n. 11
0
 public WebChannel makeChannel(String type) throws Exception {
   Class clazz = (Class) channelMap.get(type);
   if (clazz == null) {
     log.warn("Invalid channel type: " + type);
     clazz = FixedUrlChannel.class;
     //			clazz = PaginatedResultChannel.class;
   }
   WebChannel result = (WebChannel) clazz.newInstance();
   return result;
 }
  @Test
  public void testIsPossiblySatisfiedBy() throws ContradictionException, TimeoutException {
    Var P = new Var("P");
    Var Q = new Var("Q");
    Var R = new Var("R");
    Formula f = Formula.newInstanceforSAT((P.or(Q)).and(P.not().or(R))); // (P or Q) and (~P or R)

    // Possible assignments
    // ~P ~Q ~R
    // ~P ~Q  R
    // ~P  Q ~R (solution)
    // ~P  Q  R (solution
    //  P ~Q ~R
    //  P ~Q  R (solution)
    //  P  Q ~R
    //  P  Q  R (solution)

    BidiMap map = f.getVariableMap();
    assertTrue(map.get(1).equals("P"));
    assertTrue(map.get(2).equals("Q"));
    assertTrue(map.get(3).equals("R"));

    // The following partial models should pass
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {-1})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {1})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {-1, 2})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {1, 3})));

    // These partial models should not
    assertFalse(f.isPossiblySatisfiedBy(new Model(new int[] {-2, -3})));

    // Complete models, by definition, should satisfy (if solutions)
    assertFalse(f.isPossiblySatisfiedBy(new Model(new int[] {-1, -2, -3})));
    assertFalse(f.isPossiblySatisfiedBy(new Model(new int[] {-1, -2, 3})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {-1, 2, -3})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {-1, 2, 3})));
    assertFalse(f.isPossiblySatisfiedBy(new Model(new int[] {1, -2, -3})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {1, -2, 3})));
    assertFalse(f.isPossiblySatisfiedBy(new Model(new int[] {1, 2, -3})));
    assertTrue(f.isPossiblySatisfiedBy(new Model(new int[] {1, 2, 3})));
  }
Esempio n. 13
0
  /**
   * Reads the prediction file (each line is a integer) and converts them into original outcome
   * labels using the mapping provided by the bi-directional map
   *
   * @param predictionsFile predictions from classifier
   * @param labelsToIntegersMapping mapping outcomeLabel:integer
   * @return list of outcome labels
   * @throws IOException
   */
  public static List<String> extractOutcomeLabelsFromPredictions(
      File predictionsFile, BidiMap labelsToIntegersMapping) throws IOException {
    List<String> result = new ArrayList<>();

    for (String line : FileUtils.readLines(predictionsFile)) {
      Integer intLabel = Integer.valueOf(line);

      String outcomeLabel = (String) labelsToIntegersMapping.getKey(intLabel);

      result.add(outcomeLabel);
    }

    return result;
  }
Esempio n. 14
0
  private void createPollingMessage(
      Exchange exchange, List<Message> messageList, TelemetryObject incomingMessage) {
    DefaultMessage pollingMessage = new DefaultMessage();

    if (exchange
        .getIn()
        .getHeader(JMSConstants.HEADER_POLLING)
        .equals(JMSConstants.POLL_GET_COMMAND)) {
      pollingMessage.setBody(new TelemetryCommand(incomingMessage.getName()));
    } else {
      pollingMessage.setBody(
          new TelemetryCommand((String) commandsBidiMap.get(incomingMessage.getName())));
    }
    pollingMessage.setHeader(
        JMSConstants.HEADER_DEVICE, exchange.getIn().getHeader(JMSConstants.HEADER_DEVICE));
    pollingMessage.setHeader(
        JMSConstants.HEADER_GROUNDSTATIONID,
        exchange.getIn().getHeader(JMSConstants.HEADER_GROUNDSTATIONID));
    pollingMessage.setHeader(JMSConstants.HEADER_POLLING, JMSConstants.POLL_GET_COMMAND);
    pollingMessage.setHeader(JMSConstants.HEADER_FORWARD, JMSConstants.DIRECT_CHOOSE_DEVICE);
    messageList.add(pollingMessage);
  }
Esempio n. 15
0
 public static String getErrorMessage(int errorCode) {
   return error.get(errorCode).toString();
 }
Esempio n. 16
0
  static {
    DateTimeParser[] parsers = {
      DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
      DateTimeFormat.forPattern("yyyy-MM-dd HH:mm Z").getParser(),
      DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").getParser(),
      DateTimeFormat.fullDateTime().getParser(),
      DateTimeFormat.fullDate().getParser(),
      DateTimeFormat.shortDateTime().getParser(),
      DateTimeFormat.shortDate().getParser()
    };
    DTF = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();

    BidiMap primitiveTypeMap = new DualHashBidiMap();
    primitiveTypeMap.put(Integer.class, int.class);
    primitiveTypeMap.put(Long.class, long.class);
    primitiveTypeMap.put(Short.class, short.class);
    primitiveTypeMap.put(Byte.class, byte.class);
    primitiveTypeMap.put(Byte[].class, byte[].class);
    primitiveTypeMap.put(Double.class, double.class);
    primitiveTypeMap.put(Float.class, float.class);
    primitiveTypeMap.put(Character.class, char.class);
    primitiveTypeMap.put(Boolean.class, boolean.class);

    PRIMITIVE_TYPE_MAP = UnmodifiableBidiMap.decorate(primitiveTypeMap);

    Map<String, Class<?>> primitiveWrapperNameMap = new HashMap<>();

    primitiveWrapperNameMap.put(Integer.class.getName(), Integer.class);
    primitiveWrapperNameMap.put(Long.class.getName(), Long.class);
    primitiveWrapperNameMap.put(Short.class.getName(), Short.class);
    primitiveWrapperNameMap.put(Byte.class.getName(), Byte.class);
    primitiveWrapperNameMap.put(Byte[].class.getName(), Byte[].class);
    primitiveWrapperNameMap.put(Double.class.getName(), Double.class);
    primitiveWrapperNameMap.put(Float.class.getName(), Float.class);
    primitiveWrapperNameMap.put(Character.class.getName(), Character.class);
    primitiveWrapperNameMap.put(Boolean.class.getName(), Boolean.class);

    primitiveWrapperNameMap.put(int.class.getName(), Integer.class);
    primitiveWrapperNameMap.put(long.class.getName(), Long.class);
    primitiveWrapperNameMap.put(short.class.getName(), Short.class);
    primitiveWrapperNameMap.put(byte.class.getName(), Byte.class);
    primitiveWrapperNameMap.put(byte[].class.getName(), Byte[].class);
    primitiveWrapperNameMap.put(double.class.getName(), Double.class);
    primitiveWrapperNameMap.put(float.class.getName(), Float.class);
    primitiveWrapperNameMap.put(char.class.getName(), Character.class);
    primitiveWrapperNameMap.put(boolean.class.getName(), Boolean.class);

    PRIMITIVE_WRAPPER_NAME_MAP = primitiveWrapperNameMap;

    COLLECTION_IMPLEMENTATIONS = new HashMap<>();

    // PMD sees this as declaring ArrayList type fields for some reason
    COLLECTION_IMPLEMENTATIONS.put(
        List.class.getName(),
        ArrayList.class); // NOPMD - bug in PMD, objects to ArrayList.class here
    COLLECTION_IMPLEMENTATIONS.put(
        Set.class.getName(), HashSet.class); // NOPMD - bug in PMD, objects to HashSet.class here
    COLLECTION_IMPLEMENTATIONS.put(
        SortedSet.class.getName(),
        TreeSet.class); // NOPMD - bug in PMD, objects to TreeSet.class here
    COLLECTION_IMPLEMENTATIONS.put(Queue.class.getName(), ArrayDeque.class);

    MAP_SUPPORTED_TYPES = new HashMap<>();

    Set<String> keyClasses = new HashSet<>();
    keyClasses.add(String.class.getName());
    keyClasses.add(Long.class.getName());
    keyClasses.add(Integer.class.getName());

    Set<String> valueClasses = new HashSet<>();
    valueClasses.add(String.class.getName());
    valueClasses.add(Long.class.getName());
    valueClasses.add(Integer.class.getName());

    MAP_SUPPORTED_TYPES.put(MAP_KEY_TYPE, keyClasses);
    MAP_SUPPORTED_TYPES.put(MAP_VALUE_TYPE, valueClasses);
  }
Esempio n. 17
0
 /**
  * Verifies whether given class is primitive.
  *
  * @param clazz class to verify
  * @return true if given class is primitive; false otherwise
  */
 public static boolean isPrimitive(Class<?> clazz) {
   return PRIMITIVE_TYPE_MAP.containsValue(clazz);
 }
Esempio n. 18
0
 /**
  * Retrieves equivalent primitive class for the given wrapper class.
  *
  * @param clazz wrapper class
  * @return equivalent primitive class
  */
 public static Class<?> getPrimitive(Class<?> clazz) {
   return (Class<?>) PRIMITIVE_TYPE_MAP.get(clazz);
 }
Esempio n. 19
0
 /**
  * Retrieves equivalent wrapper class for the given primitive type.
  *
  * @param clazz primitive type
  * @return equivalent wrapper class
  */
 public static Class<?> getWrapperForPrimitive(Class<?> clazz) {
   return (Class<?>) PRIMITIVE_TYPE_MAP.getKey(clazz);
 }
Esempio n. 20
0
  public PollCheckValues() {
    commandsBidiMap = new DualHashBidiMap();
    commandsBidiMap.put(
        TelemetryRotatorConstants.SET_POSITION, TelemetryRotatorConstants.GET_POSITION);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_ANTENNA_NR, TelemetryRadioConstants.GET_ANTENNA_NR);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_CTCSS_TONE, TelemetryRadioConstants.GET_CTCSS_TONE);
    commandsBidiMap.put(TelemetryRadioConstants.SET_DCS_CODE, TelemetryRadioConstants.GET_DCS_CODE);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_FREQUENCY, TelemetryRadioConstants.GET_FREQUENCY);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_MEMORY_CHANNELNR, TelemetryRadioConstants.GET_MEMORY_CHANNELNR);
    commandsBidiMap.put(TelemetryRadioConstants.SET_MODE, TelemetryRadioConstants.GET_MODE);
    commandsBidiMap.put(TelemetryRadioConstants.SET_PTT, TelemetryRadioConstants.GET_PTT);
    commandsBidiMap.put(TelemetryRadioConstants.SET_RIT, TelemetryRadioConstants.GET_RIT);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_RPTR_OFFSET, TelemetryRadioConstants.GET_RPTR_OFFSET);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_RPTR_SHIFT, TelemetryRadioConstants.GET_RPTR_SHIFT);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_SPLIT_VFO, TelemetryRadioConstants.GET_SPLIT_VFO);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_TRANCEIVE_MODE, TelemetryRadioConstants.GET_TRANCEIVE_MODE);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_TRANSMIT_FREQUENCY,
        TelemetryRadioConstants.GET_TRANSMIT_FREQUENCY);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_TRANSMIT_MODE, TelemetryRadioConstants.GET_TRANSMIT_MODE);
    commandsBidiMap.put(
        TelemetryRadioConstants.SET_TUNING_STEP, TelemetryRadioConstants.GET_TUNING_STEP);
    commandsBidiMap.put(TelemetryRadioConstants.SET_VFO, TelemetryRadioConstants.GET_VFO);

    commandsThatReturnIntegrer = new ArrayList<String>();
    commandsThatReturnIntegrer.add(TelemetryRadioConstants.GET_FREQUENCY);
  }
Esempio n. 21
0
 private DB() {
   channelMap = new DualHashBidiMap();
   channelMap.put("fixedUrl", FixedUrlChannel.class);
   channelMap.put("paginated", PaginatedResultChannel.class);
   channelMap.put("parasplit", ParagraphSplitChannel.class);
 };
Esempio n. 22
0
 public static int getErrorCode(String errorMsg) {
   return Integer.parseInt(error.getKey(errorMsg).toString());
 }