public static final Sample ValueB = new Sample() { @Override public String getValue(){ return "B"; } public void doSomething(){ } };
@Override public String toString() { return String.format( "%s[timestamp=%s, context=%s, resource=%s, name=%s, type=%s, value=%s]", getClass().getSimpleName(), getTimestamp(), getContext(), getResource(), getName(), getType(), getValue()); }
final Sample a = new Sample(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { a.setVisible(true); } }); this.dispose();
private Sample getRate(Sample sample) { ValueType<?> value = NAN; Sample previous = m_prevSamples.get(sample.getName()); if (previous != null) { long elapsed = sample.getTimestamp().asSeconds() - previous.getTimestamp().asSeconds(); try { value = new Gauge(sample.getValue().delta(previous.getValue()).doubleValue() / elapsed); } catch (ArithmeticException e) { value = NAN; } } return new Sample(sample.getTimestamp(), sample.getResource(), sample.getName(), GAUGE, value, sample.getAttributes()); }
int ttl = m_ttl; if (calculateTimeToLive) { ttl -= (int) (now.asSeconds() - m.getTimestamp().asSeconds()); if (ttl <= 0) { LOG.debug("Skipping expired sample: {}", m); Duration resourceShard = m_contextConfigurations.getResourceShard(m.getContext()); .value(SchemaConstants.F_CONTEXT, m.getContext().getId()) .value(SchemaConstants.F_PARTITION, m.getTimestamp().stepFloor(resourceShard).asSeconds()) .value(SchemaConstants.F_RESOURCE, m.getResource().getId()) .value(SchemaConstants.F_COLLECTED, m.getTimestamp().asMillis()) .value(SchemaConstants.F_METRIC_NAME, m.getName()) .value(SchemaConstants.F_VALUE, ValueType.decompose(m.getValue())); if (m.getAttributes() != null) { insert.value(SchemaConstants.F_ATTRIBUTES, m.getAttributes()); insert.setConsistencyLevel(m_contextConfigurations.getWriteConsistency(m.getContext()));
maybeIndexResource(cacheQueue, generators, sample.getContext(), sample.getResource()); maybeIndexResourceAttributes(cacheQueue, generators, sample.getContext(), sample.getResource()); maybeAddMetricName(cacheQueue, generators, sample.getContext(), sample.getResource(), sample.getName());
public void initialize() { Sample startEntity = new Sample(); startEntity.setId(1); startEntity.setName("Start name"); sampleRepository.saveSample(startEntity); sampleRepository.flush(); // <-- just to make sure scenario is recreated sampleRepository.clear(); // same as above LOGGER.info(sampleRepository.findSampleById(1)); sampleRepository.clear(); // same as above above :D }
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. }
Sample sam = new Sample(); interf intObj = new Sample(); Sample2 sam2 = new Sample2(); sam.intmethod(); sam.sampleMethod(); intObj.intmethod(); // the las one will give you an erro because sampleMethod is not defined for interf //intObj.sampleMethod() sam.intmethod(); sam2.sampleMethod2();
public class SampleGSONParserAdapter implements JsonDeserializer<Sample> { @Override public Sample deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Sample sample = new Sample(); JsonObject sampleJsonObject = json.getAsJsonObject(); sample.setName(sampleJsonObject.get("name").getAsString()); // do the other parsing stuff here.. // getting the data object as a string sample.setJsonString(sampleJsonObject.get("data").toString()); return sample; } }
Sample sam = new Sample(); sam.setUsername("Test"); JSONObject json = new JSONObject(); json.put("sample", sam.getUserName()); StringEntity se = new StringEntity(json.toString()); Httppostrequest.setEntity(se);
Sample s = new Sample(); // Why this doesn't work? for (String string : s.getStringList()) { }