@SuppressWarnings("unchecked") static Object normalize(Property<?> prop, Class<?> clz) { if (clz.isAssignableFrom(IntegerProperty.class)) { return toInteger((Property<Integer>) prop); } else if (clz.isAssignableFrom(LongProperty.class)) { return toLong((Property<Long>) prop); } else if (clz.isAssignableFrom(FloatProperty.class)) { return toFloat((Property<Float>) prop); } else if (clz.isAssignableFrom(DoubleProperty.class)) { return toDouble((Property<Double>) prop); } else if (clz.isAssignableFrom(StringProperty.class)) { return toString((Property<String>) prop); } else if (clz.isAssignableFrom(ObjectProperty.class)) { return toObject((Property<Object>) prop); } return prop; }
@Subscribe public void registerWatchResult(RegWatchResponseEvent e) { if (!e.isSuccess()) throw new IllegalArgumentException("There isn't a register with the name " + e.getRegisterName()); String id = e.getRegisterID(); String registerName = e.getRegisterName(); LongProperty register = e.getRegObject(); register.addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { watchedRegisters.refresh(); } }); RegisterRow row = new RegisterRow(registerName, id, register); registers.add(row); }
@Subscribe public void memoryWatchResult(MemWatchResponseEvent e) { if (!e.isSuccess()) return; long address = e.getWatchedAddress(); LongProperty value = e.getMemObject(); value.addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { watchedAddresses.refresh(); } }); MemoryRow row = new MemoryRow(address, value); memoryAddresses.add(row); }
@Override public LongProperty getMemoryValueProperty(long addr) { if(addr < startAddress || addr > endAddress) { //Error return null;//Constants.PLP_SIM_OUT_ADDRESS_OUT_OF_RANGE; } else if(wordAligned && addr % 4 != 0) { return null;//Constants.PLP_SIM_OUT_UNALIGNED_MEMORY; } else if(!values.containsKey(addr)) { return null;//Constants.PLP_SIM_UNINITIALIZED_MEMORY; } else return values.get(addr); }
/*** * PLPRegFile constructor. It creates all the registers and initializes to default value */ public PLPRegFile() { this.registers = new LongProperty[NUMBER_OF_REGISTERS]; this.regInstructions = new BooleanProperty[NUMBER_OF_REGISTERS]; for(int i = 0; i < NUMBER_OF_REGISTERS; i++) this.registers[i] = new SimpleLongProperty(DEFAULT_REGISTER_VALUE); for(int i = 0; i < NUMBER_OF_REGISTERS; i++) this.regInstructions[i] = new SimpleBooleanProperty(false); this.namedRegisters = buildNamedRegistersMap(); EventRegistry.getGlobalRegistry().register(this); }
@SuppressWarnings("restriction") @Subscribe public void registerWatchResult(RegWatchResponseEvent e) { if (!e.isSuccess()) throw new IllegalArgumentException("There isn't a register with the name " + e.getRegisterName()); String id = e.getRegisterID(); String registerName = e.getRegisterName(); LongProperty register = e.getRegObject(); System.out.println("suc" + id + " -- " + registerName + " -- " + register); register.addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { //watchedRegisters.refresh(); System.out.println("Success" + id + " -- " + registerName + " -- " + register); session.setAttribute("idd", register.getValue()); //System.out.println("id is: " + session.getAttribute("idd")); } }); }
public void refreshPingTime() { XYChart.Data<String, Number> point = new XYChart.Data<>(); point.setXValue(String.valueOf(counter)); LongProperty responseTime = new SimpleLongProperty(); Runnable doneListener = () -> { Platform.runLater(() -> { final long timeInMs = responseTime.get(); System.out.println("Ping time: " + timeInMs); point.setYValue(timeInMs); pingSeries.getData().add(point); }); }; service.ping("http://" + uri, responseTime::set, errorSink::setText, doneListener); }
@Test public void testGeneratedOutputTypes() throws Exception { ObjectFactory of = new ObjectFactory(); TestType cut = of.createTestType(); assertTrue("StringProperty expected!", cut.aStringProperty() instanceof StringProperty); assertTrue("ObjectProperty expected!", cut.aBooleanProperty() instanceof ObjectProperty); assertTrue("ObjectProperty expected!", cut.aDoubleProperty() instanceof ObjectProperty); assertTrue("ObjectProperty expected!", cut.aFloatProperty() instanceof ObjectProperty); assertTrue("ObjectProperty expected!", cut.aLongProperty() instanceof ObjectProperty); cut.getAList(); assertTrue("ListProperty expected!", cut.aListProperty() instanceof ListProperty); assertTrue("ObjectProperty expected!", cut.anIntegerProperty() instanceof ObjectProperty); assertTrue("BooleanProperty expected!", cut.aPrimitiveBooleanProperty() instanceof BooleanProperty); assertTrue("DoubleProperty expected!", cut.aPrimitiveDoubleProperty() instanceof DoubleProperty); assertTrue("FloatProperty expected!", cut.aPrimitiveFloatProperty() instanceof FloatProperty); assertTrue("LongProperty expected!", cut.aPrimitiveLongProperty() instanceof LongProperty); assertTrue("IntegerProperty expected!", cut.aPrimitiveIntegerProperty() instanceof IntegerProperty); }
@Test public void testSaveLong() { // given String name = "long"; long value = Long.MAX_VALUE; LongProperty property = new SimpleLongProperty(null, name, value); // when PreferencesUtils.save(property, preferences); // then long saved = preferences.getLong(name, -1); assertEquals(value, saved); }
@Test public void testReadLong() { // given String name = "long"; long value = Long.MIN_VALUE; LongProperty property = new SimpleLongProperty(null, name, -value); // when preferences.putLong(name, value); // then PreferencesUtils.read(property, preferences); assertEquals(property.getValue().longValue(), value); }
/** * The constructor for the superclass requires the address space and * whether the registers of the module are word-aligned * * @param startAddr Starting address of the module's address space * @param endAddr Final address of the module's address space * @param wordAligned Whether the module's address space is word aligned */ PLPToolIOMemoryModule(long startAddr, long endAddr, boolean wordAligned) { values = new TreeMap<Long, LongProperty>(); isInstruction = new TreeMap<Long, Boolean>(); this.startAddress = startAddr; this.endAddress = endAddr; this.wordAligned = wordAligned; enabled = false; phantom = false; }
@Override public synchronized void setNewParameters(long startAddr, long endAddr, boolean isWordAligned) { values = new TreeMap<Long, LongProperty>(); isInstruction = new TreeMap<Long, Boolean>(); startAddress = startAddr; endAddress = endAddr; wordAligned = isWordAligned; }
@Subscribe public void receivedWatchRequest(MemWatchRequestEvent e) { long address = e.getMemoryAddress(); if (!validateAddress(address)) return; LongProperty valueProperty = null; for(HashMap.Entry<String, IOMemoryModule> entry : modules.entrySet()) { IOMemoryModule mod = entry.getValue(); if(mod.isAddressWithModule(address)) { if(!mod.isPhantom()) valueProperty = mod.getMemoryValueProperty(address); else { //verify: why are we even calling read of the module if not interested in its value //mod.read(addr); } break; } } EventRegistry.getGlobalRegistry().post(new MemWatchResponseEvent(true, address, valueProperty)); }
public final ChartItem build() { final ChartItem ITEM = new ChartItem(); for (String key : properties.keySet()) { if ("name".equals(key)) { ITEM.setName(((StringProperty) properties.get(key)).get()); } else if ("value".equals(key)) { ITEM.setValue(((DoubleProperty) properties.get(key)).get()); } else if("fill".equals(key)) { ITEM.setFill(((ObjectProperty<Color>) properties.get(key)).get()); } else if("stroke".equals(key)) { ITEM.setStroke(((ObjectProperty<Color>) properties.get(key)).get()); } else if("textColor".equals(key)) { ITEM.setTextColor(((ObjectProperty<Color>) properties.get(key)).get()); } else if("timestamp".equals(key)) { ITEM.setTimestamp(((ObjectProperty<Instant>) properties.get(key)).get()); } else if ("timestampDateTime".equals(key)) { ITEM.setTimestamp(((ObjectProperty<ZonedDateTime>) properties.get(key)).get()); } else if("symbol".equals(key)) { ITEM.setSymbol(((ObjectProperty<Symbol>) properties.get(key)).get()); } else if("animated".equals(key)) { ITEM.setAnimated(((BooleanProperty) properties.get(key)).get()); } else if("animationDuration".equals(key)) { ITEM.setAnimationDuration(((LongProperty) properties.get(key)).get()); } } return ITEM; }
/** * Provides the underlying value class for a given {@link Property} * * @param property * the {@link Property} to check * @return the value class of the {@link Property} */ @SuppressWarnings("unchecked") protected static <T> Class<T> propertyValueClass(final Property<T> property) { Class<T> clazz = null; if (property != null) { if (StringProperty.class.isAssignableFrom(property.getClass())) { clazz = (Class<T>) String.class; } else if (IntegerProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Integer.class; } else if (BooleanProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Boolean.class; } else if (DoubleProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Double.class; } else if (FloatProperty.class .isAssignableFrom(property.getClass())) { clazz = (Class<T>) Float.class; } else if (LongProperty.class.isAssignableFrom(property.getClass())) { clazz = (Class<T>) Long.class; } else if (ListProperty.class.isAssignableFrom(property.getClass())) { clazz = (Class<T>) List.class; } else if (MapProperty.class.isAssignableFrom(property.getClass())) { clazz = (Class<T>) Map.class; } else { clazz = (Class<T>) Object.class; } } return clazz; }
@DataPoints public static Class<?>[] primitivePropertyClasses() { return new Class<?>[]{ BooleanProperty.class, IntegerProperty.class, LongProperty.class, FloatProperty.class, DoubleProperty.class, }; }
@Theory public void testNullPropertiesAccepted(@FromDataPoints("safeProperties") Gson gson) { testSerialize(WithBooleanProp.class, "{\"prop\":null}", (BooleanProperty) null, (o, v) -> o.prop = v, gson); testSerialize(WithIntegerProp.class, "{\"prop\":null}", (IntegerProperty) null, (o, v) -> o.prop = v, gson); testSerialize(WithLongProp.class, "{\"prop\":null}", (LongProperty) null, (o, v) -> o.prop = v, gson); testSerialize(WithFloatProp.class, "{\"prop\":null}", (FloatProperty) null, (o, v) -> o.prop = v, gson); testSerialize(WithDoubleProp.class, "{\"prop\":null}", (DoubleProperty) null, (o, v) -> o.prop = v, gson); }
/** * @see #bind(ObjectProperty, String) * * @param property {@link Property} to bind * @param key unique application store key */ public void bind(LongProperty property, String key) { try { property.set(prefs.getLong(validateKey(key), property.get())); } catch (NumberFormatException e) { prefs.putLong(key, property.getValue()); } property.addListener(o -> prefs.putLong(key, property.getValue())); }
/** * Create a JavaFX {@link javafx.beans.property.LongProperty} as a wrapper for a dolphin platform property * * @param dolphinProperty the dolphin platform property * @return the JavaFX property */ public static LongProperty wrapLongProperty(final Property<Long> dolphinProperty) { Assert.requireNonNull(dolphinProperty, "dolphinProperty"); final LongProperty property = new SimpleLongProperty(); FXBinder.bind(property).bidirectionalToNumeric(dolphinProperty); return property; }
@Override public final OptionalLong getAsLong(String key) { final LongProperty prop = (LongProperty) properties.get(key); if (prop == null) { return OptionalLong.empty(); } else { return OptionalUtil.ofNullable(prop.getValue()); } }
@Test public void testLongProperty() { LongProperty actual = new SimpleLongProperty(10l); assertThat(actual).hasValue(10l); assertThat(actual).hasSameValue(actual); }
/** * Provides the underlying value class for a given {@linkplain Property} * * @param property * the {@linkplain Property} to check * @return the value class of the {@linkplain Property} */ @SuppressWarnings("unchecked") protected static <T> Class<T> propertyValueClass(final Property<T> property) { Class<T> clazz = null; if (property != null) { if (StringProperty.class.isAssignableFrom(property.getClass())) { clazz = (Class<T>) String.class; } else if (IntegerProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Integer.class; } else if (BooleanProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Boolean.class; } else if (DoubleProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Double.class; } else if (FloatProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Float.class; } else if (LongProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Long.class; } else if (ListProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) List.class; } else if (MapProperty.class.isAssignableFrom(property .getClass())) { clazz = (Class<T>) Map.class; } else { clazz = (Class<T>) Object.class; } } return clazz; }
@Override public TransferData build() { // Catch data final StringProperty actionId = (StringProperty) properties.get(ATTR__ACTION_ID); final BooleanProperty booleanValue = (BooleanProperty) properties.get(ATTR__BOOLEAN_VALUE); final ObjectProperty characterValue = (ObjectProperty) properties.get(ATTR__CHARACTER_VALUE); final DoubleProperty doubleValue = (DoubleProperty) properties.get(ATTR__DOUBLE_VALUE); final IntegerProperty integerValue = (IntegerProperty) properties.get(ATTR__INTERGER_VALUE); final LongProperty longValue = (LongProperty) properties.get(ATTR__LONG_VALUE); final ObjectProperty objectValue = (ObjectProperty) properties.get(ATTR__OBJECT_VALUE); final StringProperty stringValue = (StringProperty) properties.get(ATTR__STRING_VALUE); final StringProperty responseActionId = (StringProperty) properties.get(ATTR__RESPONSE_ACTION_ID); final BooleanProperty logTransferData = (BooleanProperty) properties.get(ATTR__LOG_TRANSFERDATA); // Create a new TransferData return DefaultTransferData.create( actionId.getValue(), booleanValue.getValue(), (Character)characterValue.getValue(), // TODO add unittest doubleValue.getValue(), integerValue.getValue(), longValue.getValue(), objectValue.getValue(), stringValue.getValue(), responseActionId.getValue(), logTransferData.get()); }
public static void main(String[] args) { int n = 40; FibTest eagerTest = new FibTest(n); LongProperty eagerResult = new SimpleLongProperty(); eagerTest.setupFor(eagerResult); FibTest lazyTest = new FibTest(n); SuspendableVar<Number> lazyResult = Var.suspendable(Var.newSimpleVar(0L)); lazyTest.setupFor(lazyResult); long t1 = System.currentTimeMillis(); eagerTest.run(); long t2 = System.currentTimeMillis(); double eagerTime = (t2-t1)/1000.0; t1 = System.currentTimeMillis(); Guard g = lazyResult.suspend(); lazyTest.run(); g.close(); t2 = System.currentTimeMillis(); double lazyTime = (t2-t1)/1000.0; System.out.println("EAGER TEST:"); System.out.println(" fib_" + n + " = " + eagerResult.get()); System.out.println(" result invalidations: " + eagerTest.invalidationCount); System.out.println(" duration: " + eagerTime + " seconds"); System.out.println(); System.out.println("LAZY TEST:"); System.out.println(" fib_" + n + " = " + lazyResult.getValue()); System.out.println(" result invalidations: " + lazyTest.invalidationCount); System.out.println(" duration: " + lazyTime + " seconds"); }
/** * Test of maxSizeProperty method, of class MagicCopierPreferencesModel. */ @Test public void testMaxSizeProperty() { System.out.println("maxSizeProperty"); MagicCopierPreferencesModel instance = new MagicCopierPreferencesModel(); LongProperty expResult = null; LongProperty result = instance.maxSizeProperty(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
public LongPropertyConverter(Mapper mapper) { super(LongProperty.class, mapper); }
public static LongProperty toLong(Property<Long> p) { return andFinal(() -> new SimpleLongProperty(), np -> BidirectionalBinding.bindNumber(np, p)); }
public LongProperty valueProperty(){ return value; }
public static LongProperty startTimeProperty() { return startTime; }
public ValueRow(LongProperty value, ObjectProperty<Function<Long, String>> function) { this.value = value; this.displayFunctionProperty = function; }
public RegisterRow(String name, String id, LongProperty value) { super(value, WatcherWindow.this.registerDisplayFunction); registerName = new SimpleStringProperty(name); registerID = new SimpleStringProperty(id); }
public MemoryRow(long address, LongProperty value) { super(value, WatcherWindow.this.memoryDisplayFunction); this.address = new SimpleLongProperty(address); }
@Override public synchronized void clear() { values = new TreeMap<Long, LongProperty>(); isInstruction = new TreeMap<Long, Boolean>(); }
public MemWatchResponseEvent(boolean success, long watchedAddress, LongProperty memObject) { this.success = success; this.watchedAddress = watchedAddress; this.memObject = memObject; }
public LongProperty getMemObject() { return memObject; }
public RegWatchResponseEvent(boolean success, String registerID, String registerName, LongProperty regObject) { this.success = success; this.registerID = registerID; this.registerName = registerName; this.regObject = regObject; }
public LongProperty getRegObject() { return regObject; }
@Override protected Long extractPrimitiveValue(LongProperty property) { return property.get(); }
@Override protected LongProperty createDefaultProperty() { return new SimpleLongProperty(); }