public static final Sample ValueB = new Sample() { @Override public String getValue(){ return "B"; } public void doSomething(){ } };
var samples = []; /* If you have no data to put in yet. */ /* Later, probably in a callback method with computed data */ /* replacing the constants. */ samples.push(new Sample(1, 2, 3)); /* Assuming Sample is an object. */ /* or */ samples.push({id: 23, chemical: "NO2", ppm: 1.4}); /* Object literal. */
/** * Creates a sample used to index string attributes. * * These should only be index and not be persisted. */ public static Sample createSampleForIndexingStrings(Context context, Resource resource) { return new Sample(EPOCH, context, resource, "strings", MetricType.GAUGE, ZERO); }
/** * Creates a sample used to index string attributes. * * These should only be index and not be persisted. */ public static Sample createSampleForIndexingStrings(Context context, Resource resource) { return new Sample(EPOCH, context, resource, "strings", MetricType.GAUGE, ZERO); }
var Sample = function() { var that = this; this.sampleMethod = function() { return alert("Hello!"); }; this.sampleMethod2 = function(){ that["sampleMethod"].apply(that); }; }; var objImpl = new Sample(); objImpl.sampleMethod2(); //you will get a message from 'sampleMethod()'
public class Test { public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Sample sample=new Sample(); Method method=Sample.class.getDeclaredMethod("appendStrings", String.class, String.class); System.out.println(method.invoke(sample, "Hello", "World")); }
Sample test = new Sample(); test.preco = 11.12f; ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<Sample>> violations = validator.validate(test); for (final ConstraintViolation<Sample> cons : violations) { System.out.println(cons.getMessage()); }
public static void indexer (String field) { Sample sam = new Sample(); sam.Sample_ID = "SAMPLE1"; try { Field myField = Sample.class.getDeclaredField(field); myField.setAccessible(true); System.out.println(sam.Sample_ID); // This will print SAMPLE1 to console. System.out.println(myField.get(sam)); // I want this to print the value of the field as per the variable's name. } catch (Exception e) { // Handle exception } }
final Sample a = new Sample(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { a.setVisible(true); } }); this.dispose();
public Sample add(int number){ Sample sample = new Sample(); sample.setNumber(sample.number + number); return sample; }
function Sample() { // Sample() is the constructor function for your objects return { prop_1: 'value', prop_2: 3 } } var obj = Sample(); // without new console.log(obj); // Object { prop_1="value", prop_2=3} var obj = new Sample(); // with new console.log(obj); // The same result with new operator: Object { prop_1="value", prop_2=3}
private void injectStringPropertiesToNewts(final ResourcePath resourcePath, final Map<String, String> stringProperties) { final Resource resource = new Resource(NewtsUtils.toResourceId(resourcePath), Optional.of(stringProperties)); final Sample sample = new Sample(EPOCH, resource, "strings", MetricType.GAUGE, ZERO); indexer.update(Lists.newArrayList(sample)); }
public static void main(String args[]) { Sample first = new Sample(); first.setData(1); //Either //Sample second = new Sample(); //second.setData(1); //or Sample second = first; System.out.println(first.getData()); // 1 System.out.println(second.getData()); // here, you will get 1 after above changes made. }
public class RestrictedSample { private Sample sample = new Sample(); public void method1(){ sample.method1(); } public void method2(){ sample.method2(); } public void method3(){ sample.method3(); } }
protected static Sample toSample(AbstractDS ds, Resource resource, Timestamp timestamp, double value) { final String metric = ds.getName(); final MetricType type = ds.isCounter() ? MetricType.COUNTER : MetricType.GAUGE; final ValueType<?> valueType = ds.isCounter() ? new Counter(UnsignedLong.valueOf(BigDecimal.valueOf(value).toBigInteger())) : new Gauge(value); return new Sample(timestamp, resource, metric, type, valueType); }
@Override public Sample call(Sample s) { Timestamp oldTs = s.getTimestamp(); Timestamp newTs = Timestamp.fromEpochMillis(m_timeoffset + Math.round(oldTs.asMillis()/m_timescaleFactor)); return new Sample(newTs, s.getResource(), s.getName(), s.getType(), s.getValue()); }
@Override public Sample apply(SampleDTO input) { return new Sample( Timestamp.fromEpochMillis(input.getTimestamp()), input.getContext(), new Resource(input.getResource().getId(), wrapMap(input.getResource().getAttributes())), input.getName(), input.getType(), ValueType.compose(input.getValue(), input.getType()), input.getAttributes()); } };
@Override public Sample apply(SampleDTO input) { return new Sample( Timestamp.fromEpochMillis(input.getTimestamp()), input.getContext(), new Resource(input.getResource().getId(), wrapMap(input.getResource().getAttributes())), input.getName(), input.getType(), ValueType.compose(input.getValue(), input.getType()), input.getAttributes()); } };