/**
  * 根据序数得到枚举
  *
  * @param ordinal
  * @return
  */
 public static ChannelType getByOrdinal(Integer ordinal) {
   if (null != ordinal) {
     for (ChannelType t : ChannelType.values()) {
       if (t.ordinal() == ordinal) {
         return t;
       }
     }
   }
   return null;
 }
 /**
  * {@inheritDoc}
  *
  * @see com.communote.server.model.security.IpRangeChannel#setType(String)
  */
 @Override
 public void setType(String type) {
   super.setType(type);
   if (type == null) {
     this.channel = null;
   } else {
     this.channel = ChannelType.fromString(type);
   }
 }
 public static int[] getChannelNos(ChannelType channelType, int constant) {
   //		if (constant < Constants.MAX_PRECOMPUTED_ROUNDS / Constants.CHANNEL_CYCLE) {
   //			return getChannelNosPrecomputed(channelType, constant);
   //		}
   int[] channelNos = new int[Constants.REDUNDANT_CHANNELS];
   int rangeStart = channelType.ordinal() * ChannelType.range;
   constant += 1;
   for (int i = 0; i < Constants.REDUNDANT_CHANNELS; i++) {
     int offset =
         ((Integer.toString(((constant << 4 + 17 * channelType.ordinal()) << 4 + i)).hashCode())
                 + rc.getTeam().ordinal())
             % ChannelType.range;
     // ensure that the offset is nonnegative
     if (offset < 0) {
       offset += ChannelType.range;
     }
     channelNos[i] = rangeStart + offset;
   }
   return channelNos;
 }
Example #4
0
 public static Command parse(String line) {
   String[] tokens = line.split(",");
   Command cmd = new Command();
   Action action = Action.valueOf(tokens[0]);
   cmd.setAction(action);
   cmd.setChannel(tokens[1]);
   ChannelType type = ChannelType.translate(tokens[2]);
   cmd.setType(type);
   if (!"null".equals(tokens[3])) {
     String[] hostPort = tokens[3].split(":");
     int port = Integer.parseInt(hostPort[1]);
     InetSocketAddress addr = new InetSocketAddress(hostPort[0], port);
     cmd.setAddress(addr);
   }
   int payloadSize = Integer.parseInt(tokens[4]);
   cmd.setPayloadSize(payloadSize);
   boolean isNeedPlayback = Boolean.parseBoolean(tokens[5]);
   cmd.setNeedsPlayback(isNeedPlayback);
   return cmd;
 }
 /**
  * For precomputed channels.
  *
  * @param channelType
  * @param round_cycle
  * @return
  */
 public static int[] getChannelNosPrecomputed(ChannelType channelType, int round_cycle) {
   return PrecomputedChannelNos.precomputedChannelNos[round_cycle][channelType.ordinal()];
   //		return new int[0];
 }
Example #6
0
 /** @see ChannelType#fromString(String) */
 @Test(expected = IllegalArgumentException.class)
 public void fromCode_shouldThrowExceptionForInvalidCode() {
   ChannelType.fromString("XX");
 }
Example #7
0
 /** @see io.rapidpro.mage.core.ChannelType#fromString(String) */
 @Test
 public void fromCode() {
   assertThat(ChannelType.fromString("T"), is(ChannelType.TWILIO));
   assertThat(ChannelType.fromString("EX"), is(ChannelType.EXTERNAL));
 }