/** * Returns true if this capacity is greater or equal than the capacity toCompare * * @param toCompare the capacity to compare * @return true if this capacity is greater or equal than toCompare * @throws NullPointerException if one of the args is null */ public boolean isGreaterOrEqual(Capacity toCompare) { if (toCompare == null) throw new NullPointerException(); for (int i = 0; i < Math.max(this.getNuOfDimensions(), toCompare.getNuOfDimensions()); i++) { if (this.get(i) < toCompare.get(i)) return false; } return true; }
public Capacity unmarshall(JsonUnmarshallerContext context) throws Exception { Capacity capacity = new Capacity(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) return null; while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("CapacityUnits", targetDepth)) { context.nextToken(); capacity.setCapacityUnits(DoubleJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return capacity; }
/** * Adds up two capacities, i.e. sums up each and every capacity dimension, and returns the * resulting Capacity. * * <p>Note that this assumes that capacity dimension can be added up. * * @param cap1 capacity to be added up * @param cap2 capacity to be added up * @return new capacity * @throws NullPointerException if one of the args is null */ public static Capacity addup(Capacity cap1, Capacity cap2) { if (cap1 == null || cap2 == null) throw new NullPointerException("arguments must not be null"); Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); for (int i = 0; i < Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions()); i++) { capacityBuilder.addDimension(i, cap1.get(i) + cap2.get(i)); } return capacityBuilder.build(); }
public static Capacity min(Capacity cap1, Capacity cap2) { if (cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null"); Capacity.Builder toReturnBuilder = Capacity.Builder.newInstance(); for (int i = 0; i < Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions()); i++) { toReturnBuilder.addDimension(i, Math.min(cap1.get(i), cap2.get(i))); } return toReturnBuilder.build(); }
/** * Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1. * * @param cap2invert capacity to be inverted * @return inverted capacity * @throws NullPointerException if one of the args is null */ public static Capacity invert(Capacity cap2invert) { if (cap2invert == null) throw new NullPointerException("arguments must not be null"); Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); for (int i = 0; i < cap2invert.getNuOfDimensions(); i++) { int dimValue = cap2invert.get(i) * -1; capacityBuilder.addDimension(i, dimValue); } return capacityBuilder.build(); }
/** * Subtracts cap2subtract from cap and returns the resulting Capacity. * * @param cap capacity to be subtracted from * @param cap2subtract capacity to subtract * @return new capacity * @throws NullPointerException if one of the args is null * @throws IllegalStateException if number of capacityDimensions of cap1 and cap2 are different * (i.e. <code>cap1.getNuOfDimension() != cap2.getNuOfDimension()</code>). */ public static Capacity subtract(Capacity cap, Capacity cap2subtract) { if (cap == null || cap2subtract == null) throw new NullPointerException("arguments must not be null"); Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); for (int i = 0; i < Math.max(cap.getNuOfDimensions(), cap2subtract.getNuOfDimensions()); i++) { int dimValue = cap.get(i) - cap2subtract.get(i); capacityBuilder.addDimension(i, dimValue); } return capacityBuilder.build(); }
// private methods private void create(String filename, String capacity_filename, String capacity_id) { this.filename = filename; this.jobs = new HashMap<Integer, Job>(); if (capacity_filename != null) { Capacity.load(capacity_filename); this.capacity = Capacity.get(capacity_id); } parse_file(); }
/** * Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the * capacity dimensions > than the corresponding dimension in toCompare. * * @param toCompare the capacity to compare * @return true if this capacity is less or equal than toCompare * @throws NullPointerException if one of the args is null */ public boolean isLessOrEqual(Capacity toCompare) { if (toCompare == null) throw new NullPointerException(); for (int i = 0; i < this.getNuOfDimensions(); i++) { if (this.get(i) > toCompare.get(i)) return false; } return true; }
public SpeechSynthesizer( Capacity capacity, MaxFilibusters maxFilibusters, MinimumMemory minimumMemory, FilibusterHome filibusterHome, LogHome logHome, Timeout timeout, TimeToLive ttl, IdleTime idleTime, FakeSynthesize fake) { this.filibusters = maxFilibusters; FilibusterPool pool = new FilibusterPool.Builder() .speechSynthesizer(this) .maxPoolSize(maxFilibusters) .minimumMemory(minimumMemory) .filibusterHome(filibusterHome) .logHome(logHome) .timeout(timeout) .ttl(ttl) .fake(fake) .build(); dispatcher = new Dispatcher(pool, this, idleTime); inQue = new LinkedBlockingQueue<>(capacity.getCapacity()); out = new ConcurrentHashMap<>(); }
/** * Divides every dimension of numerator capacity by the corresponding dimension of denominator * capacity, , and averages each quotient. * * <p>If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored. * * <p>If both capacities are have only dimensions with dimensionVal=0, it returns 0.0 * * @param numerator the numerator * @param denominator the denominator * @return quotient * @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0 */ public static double divide(Capacity numerator, Capacity denominator) { int nuOfDimensions = 0; double sumQuotients = 0.0; for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) { if (numerator.get(index) != 0 && denominator.get(index) == 0) { throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0"); } else if (numerator.get(index) == 0 && denominator.get(index) == 0) { continue; } else { nuOfDimensions++; sumQuotients += (double) numerator.get(index) / (double) denominator.get(index); } } if (nuOfDimensions > 0) return sumQuotients / (double) nuOfDimensions; return 0.0; }
/** * copy constructor * * @param capacity capacity to be copied */ Capacity(Capacity capacity) { this.dimensions = new int[capacity.getNuOfDimensions()]; for (int i = 0; i < capacity.getNuOfDimensions(); i++) { this.dimensions[i] = capacity.get(i); } }