Exemplo n.º 1
0
  public static void testToHTML() {
    String source, expected, actual;

    source = Locale.getString("JAVA_HTML_SOURCE"); // $NON-NLS-1$
    expected = Locale.getString("JAVA_HTML_EXPECTED"); // $NON-NLS-1$

    assertNull(TextUtil.toHTML(null));

    actual = TextUtil.toHTML(source);
    assertEquals(expected, actual);
  }
Exemplo n.º 2
0
  /** @throws Exception */
  public static void testCutString() throws Exception {
    String src, res, actual;

    src = Locale.getString("A_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("A_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("A:", res, actual); // $NON-NLS-1$

    src = Locale.getString("B_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("B_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("B:", res, actual); // $NON-NLS-1$

    src = Locale.getString("C_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("C_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("C:", res, actual); // $NON-NLS-1$

    src = Locale.getString("D_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("D_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("D:", res, actual); // $NON-NLS-1$
  }
		/** {@inheritDoc}
		 */
		@Override
		public void run() {
			while (true) {
				try {
					Thread.currentThread().setName(
							Locale.getString(JanusJXTAGroup.class,
									"DISCOVER_THREAD_NAME", //$NON-NLS-1$
									getPeerGroup().getPeerName()));
				}
				catch(AssertionError e) {
					throw e;
				}
				catch(Throwable _) {
					//
				}
				// TODO make all this configurations
				try {
					PipeUtil.discoverAdvertisements(getPeerGroup(), null, this);
					Thread.sleep(1000);
				}
				catch (AssertionError ae) {
					throw ae;
				}
				catch (InterruptedException e) {
					//
				}
			}

		}
  /**
   * @param k is the kernel to inspect.
   * @param planeEntity is the entity which is the plane.
   * @param cubeCount is the number of cubes in the problem.
   */
  public CubeWorldPanel(Kernel k, EcoIdentity planeEntity, int cubeCount) {
    this.planeEntity = planeEntity;
    this.cubeCount = cubeCount;

    setLayout(new BorderLayout());
    add(this.displayer, BorderLayout.CENTER);

    JPanel tools = new JPanel();
    tools.setLayout(new BoxLayout(tools, BoxLayout.X_AXIS));
    add(tools, BorderLayout.SOUTH);

    this.startButton = new JButton(getIcon("first.png")); // $NON-NLS-1$
    this.startButton.setActionCommand(ACTION_FIRST_STATE);
    this.startButton.setToolTipText(
        Locale.getString(CubeWorldPanel.class, "FIRST_STATE")); // $NON-NLS-1$
    tools.add(this.startButton);
    this.startButton.addActionListener(this);

    this.previousButton = new JButton(getIcon("previous.png")); // $NON-NLS-1$
    this.previousButton.setActionCommand(ACTION_PREVIOUS_STATE);
    this.previousButton.setToolTipText(
        Locale.getString(CubeWorldPanel.class, "PREVIOUS_STATE")); // $NON-NLS-1$
    tools.add(this.previousButton);
    this.previousButton.addActionListener(this);

    this.nextButton = new JButton(getIcon("next.png")); // $NON-NLS-1$
    this.nextButton.setActionCommand(ACTION_NEXT_STATE);
    this.nextButton.setToolTipText(
        Locale.getString(CubeWorldPanel.class, "NEXT_STATE")); // $NON-NLS-1$
    tools.add(this.nextButton);
    this.nextButton.addActionListener(this);

    this.endButton = new JButton(getIcon("last.png")); // $NON-NLS-1$
    this.endButton.setActionCommand(ACTION_LAST_STATE);
    this.endButton.setToolTipText(
        Locale.getString(CubeWorldPanel.class, "LAST_STATE")); // $NON-NLS-1$
    tools.add(this.endButton);
    this.endButton.addActionListener(this);

    this.stateLabel = new JLabel();
    this.stateLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    tools.add(this.stateLabel);

    updateUIComponents();

    k.getChannelManager().addChannelInteractableListener(this);
  }
 /** {@inheritDoc} */
 @Override
 public void start(BundleContext context) throws Exception {
   LoggerUtil.setGlobalLevel(Level.INFO);
   this.logger = Logger.getLogger(this.getClass().getCanonicalName());
   this.logger.info(
       Locale.getString(
           GroovySimpleMessageActivator.class, "ACTIVATING_GROOVYSIMPLEMESSAGE")); // $NON-NLS-1$
   context.registerService(JanusApplication.class.getName(), this, null);
 }
Exemplo n.º 6
0
  /** @throws Exception */
  public static void testCutStringAsArray() throws Exception {
    String src;
    String[] res;
    String[] actual;

    src = Locale.getString("A_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("A_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "A:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("A:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("B_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("B_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "B:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("B:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("C_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("C_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "C:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("C:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("D_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("D_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "D:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("D:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }
  }
 private void updateUIComponents() {
   boolean prev = this.currentStateIndex > 0 && this.currentStateIndex < this.worldStates.size();
   boolean next =
       this.currentStateIndex >= 0 && this.currentStateIndex < (this.worldStates.size() - 1);
   this.startButton.setEnabled(prev);
   this.previousButton.setEnabled(prev);
   this.nextButton.setEnabled(next);
   this.endButton.setEnabled(next);
   String label;
   if (this.currentStateIndex >= 0 && this.currentStateIndex < this.worldStates.size()) {
     State state = getCurrentState();
     assert (state != null);
     String key = (state.isInitialization) ? "INIT_INFO" : "INFO"; // $NON-NLS-1$ //$NON-NLS-2$
     label =
         Locale.getString(
             CubeWorldPanel.class,
             key,
             Integer.toString(this.currentStateIndex + 1),
             Integer.toString(this.worldStates.size()));
   } else {
     label = Locale.getString(CubeWorldPanel.class, "NO_INFO"); // $NON-NLS-1$
   }
   this.stateLabel.setText(label);
 }
  /** {@inheritDoc} */
  @Override
  public Status start(KernelService kernel) {
    this.logger.log(
        Level.INFO,
        Locale.getString(
            GroovySimpleMessageActivator.class, "GROOVYSIMPLEMESSAGE_START")); // $NON-NLS-1$

    GroovyAgentReceiver receiver = new GroovyAgentReceiver();
    AgentAddress arec = kernel.launchLightAgent(receiver, "receiver"); // $NON-NLS-1$

    GroovyAgentSender sender = new GroovyAgentSender(arec);
    kernel.launchLightAgent(sender, "sender"); // $NON-NLS-1$

    return StatusFactory.ok(this);
  }
		/** {@inheritDoc}
		 */
		@Override
		public void run() {
			try {
				Thread.currentThread().setName(
						Locale.getString(JanusJXTAGroup.class,
								"SERVER_THREADS_NAME", //$NON-NLS-1$
								getPeerGroup().getPeerName()));
			}
			catch(AssertionError e) {
				throw e;
			}
			catch(Throwable _) {
				//
			}
			try {
				if (this.serverPipe == null) {
					this.serverPipe = new JxtaServerPipe(
							getPeerGroup(), 
							PipeUtil.getAdvertisement(
									getPeerGroup(), 
									getPeerGroup().getPeerName(), 
									PipeService.UnicastType, 
									null));
					// lock forever
					this.serverPipe.setPipeTimeout(0);
				}

				while (true) {
					JxtaBiDiPipe bidiPipe = this.serverPipe.accept();
					if (bidiPipe != null) {
						IncommingConnectionHandler handler = new IncommingConnectionHandler();
						handler.attachBiDiPipe(bidiPipe);
					}
				}

			} catch (AssertionError ae) {
				throw ae;
			} catch (IOException e) {
				Logger.getLogger(getClass().getName()).severe(Throwables.toString(e));
			}

		}
Exemplo n.º 10
0
	/** Compute the better metric representing
	 * the given time amount and reply a string representation
	 * of the given amount with this selected unit.
	 * <p>
	 * This function try to use a greater metric unit.
	 * 
	 * @param amount is the amount expressed in the given unit.
	 * @param unit is the unit of the given amount.
	 * @return a string representation of the given amount.
	 */
	public static String formatTime(double amount, TimeUnit unit) {
		double amt;
		double coef = 1.;
		switch(unit) {
		case DAYS:
			coef = 86400.;
			break;
		case HOURS:
			coef = 3600.;
			break;
		case MINUTES:
			coef = 60.;
			break;
		case SECONDS:
			break;
		case MILLISECONDS:
			coef = 1e-3;
			break;
		case MICROSECONDS:
			coef = 1e-6;
			break;
		case NANOSECONDS:
			coef = 1e-9;
			break;
		default:
			throw new IllegalArgumentException();
		}

		// amount is in seconds
		amt = amount * coef;

		StringBuilder text = new StringBuilder();
		String centuries, years, days, hours, minutes, seconds;
		int idx;
		long a, ah, am, as;
		
		centuries = years = days = hours = minutes = seconds = ""; //$NON-NLS-1$
		ah = am = as = 0;
		idx = 0;
		
		if (amt>=3153600000.) {
			a = (long)Math.floor(amt / 3153600000.);
			centuries = Locale.getString((a>=2) ? "TIME_FORMAT_Cs" : "TIME_FORMAT_C", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 3153600000.;
			text.append(centuries);
			idx |= 32;
		}

		if (amt>=31536000.) {
			a = (long)Math.floor(amt / 31536000.);
			years = Locale.getString((a>=2) ? "TIME_FORMAT_Ys" : "TIME_FORMAT_Y", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 31536000.;
			if (text.length()>0) text.append(' ');
			text.append(years);
			idx |= 16;
		}

		if (amt>=86400.) {
			a = (long)Math.floor(amt / 86400.);
			days = Locale.getString((a>=2) ? "TIME_FORMAT_Ds" : "TIME_FORMAT_D", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 86400.;
			if (text.length()>0) text.append(' ');
			text.append(days);
			idx |= 8;
		}
		
		//-------------------
		
		if (amt>=3600.) {
			ah = (long)Math.floor(amt / 3600.);
			hours = Long.toString(ah);
			if (ah<10.) hours = "0" + hours; //$NON-NLS-1$
			amt -= ah * 3600.;
			idx |= 4;
		}

		if (amt>=60.) {
			am = (long)Math.floor(amt / 60.);
			minutes = Long.toString(am);
			if (am<10.) minutes = "0" + minutes; //$NON-NLS-1$
			amt -= am * 60.;
			idx |= 2;
		}
		
		if (amt>=0. || idx==0) {
			if (idx>=8) {
				as = (long)Math.floor(amt);
				seconds = Long.toString(as);
			}
			else {
				NumberFormat fmt = new DecimalFormat("#0.000"); //$NON-NLS-1$				
				seconds = fmt.format(amt);
			}
			idx |= 1;
		}

		if ((idx&7)==7) {
			if (text.length()>0) text.append(' ');
			if (idx>=8 && as>0) {
				if (as<10.) seconds = "0" + seconds; //$NON-NLS-1$
			}
			else if (idx<8 && amt>0.) {
				if (amt<10.) seconds = "0" + seconds; //$NON-NLS-1$
			}			
			text.append(Locale.getString("TIME_FORMAT_HMS", hours, minutes, seconds)); //$NON-NLS-1$
		}
		else {
			if (ah>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((ah>=2) ? "TIME_FORMAT_Hs" : "TIME_FORMAT_H", hours)); //$NON-NLS-1$ //$NON-NLS-2$
			}
			if (am>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((am>=2) ? "TIME_FORMAT_Ms" : "TIME_FORMAT_M", minutes)); //$NON-NLS-1$ //$NON-NLS-2$
			}
			if (idx>=8 && as>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((as>=2) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S", seconds)); //$NON-NLS-1$ //$NON-NLS-2$
			}
			else if (idx<8 && amt>0.) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((amt>=2.) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S", seconds)); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}

		return text.toString();
	}
 /** {@inheritDoc} */
 @Override
 public String getDescription() {
   return Locale.getString(
       GroovySimpleMessageActivator.class, "APPLICATION_DESCRIPTION"); // $NON-NLS-1$
 }
 /** {@inheritDoc} */
 @Override
 public String getName() {
   return Locale.getString(GroovySimpleMessageActivator.class, "APPLICATION_NAME"); // $NON-NLS-1$
 }