repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
nabedge/mixer2 | src/main/java/org/mixer2/util/XMLStringUtil.java | XMLStringUtil.getXMLValidString | public static String getXMLValidString(final String input,
final boolean replace, final char replacement) {
if (input == null) {
return null;
}
if ("".equals(input)) {
return "";
}
StringBuilder sb = new StringBuilder();
for (char c : input.toCharArray()) {
if (XMLStringUtil.isXMLValid(c)) {
sb.append(c);
} else if (replace) {
sb.append(replacement);
}
}
return sb.toString();
} | java | public static String getXMLValidString(final String input,
final boolean replace, final char replacement) {
if (input == null) {
return null;
}
if ("".equals(input)) {
return "";
}
StringBuilder sb = new StringBuilder();
for (char c : input.toCharArray()) {
if (XMLStringUtil.isXMLValid(c)) {
sb.append(c);
} else if (replace) {
sb.append(replacement);
}
}
return sb.toString();
} | [
"public",
"static",
"String",
"getXMLValidString",
"(",
"final",
"String",
"input",
",",
"final",
"boolean",
"replace",
",",
"final",
"char",
"replacement",
")",
"{",
"if",
"(",
"input",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"\"\... | Remove or replace XML invalid chars from input.
@param input
@param replace
Whether or not to replace invalid characters by replacement
@param replacement
The character to replace any invalid character found
@return The String that is cleaned from the invalid in XML characters.
@see #isXMLValid(char) | [
"Remove",
"or",
"replace",
"XML",
"invalid",
"chars",
"from",
"input",
"."
] | 8c2db27cfcd65bf0b1e0242ef9362ebd8033777c | https://github.com/nabedge/mixer2/blob/8c2db27cfcd65bf0b1e0242ef9362ebd8033777c/src/main/java/org/mixer2/util/XMLStringUtil.java#L28-L47 | train |
m-m-m/util | io/src/main/java/net/sf/mmm/util/io/impl/PooledByteArray.java | PooledByteArray.release | public boolean release() {
if (this.released) {
// already (marked as) released...
return false;
}
this.released = true;
if (this.childCount == 0) {
if (this.parent == null) {
return true;
} else {
assert (this.parent.childCount > 0);
this.parent.childCount--;
if ((this.parent.childCount == 0) && (this.parent.released)) {
return true;
}
}
}
return false;
} | java | public boolean release() {
if (this.released) {
// already (marked as) released...
return false;
}
this.released = true;
if (this.childCount == 0) {
if (this.parent == null) {
return true;
} else {
assert (this.parent.childCount > 0);
this.parent.childCount--;
if ((this.parent.childCount == 0) && (this.parent.released)) {
return true;
}
}
}
return false;
} | [
"public",
"boolean",
"release",
"(",
")",
"{",
"if",
"(",
"this",
".",
"released",
")",
"{",
"// already (marked as) released...\r",
"return",
"false",
";",
"}",
"this",
".",
"released",
"=",
"true",
";",
"if",
"(",
"this",
".",
"childCount",
"==",
"0",
... | This method marks this array to be released.
@return {@code true} if this array can be released, {@code false} if there are references left that have to be
released before. | [
"This",
"method",
"marks",
"this",
"array",
"to",
"be",
"released",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/io/src/main/java/net/sf/mmm/util/io/impl/PooledByteArray.java#L87-L106 | train |
nikolavp/approval | approval-core/src/main/java/com/github/approval/Approval.java | Approval.of | @Nonnull
public static <T> ApprovalBuilder<T> of(Class<T> clazz) {
return new ApprovalBuilder<T>(clazz);
} | java | @Nonnull
public static <T> ApprovalBuilder<T> of(Class<T> clazz) {
return new ApprovalBuilder<T>(clazz);
} | [
"@",
"Nonnull",
"public",
"static",
"<",
"T",
">",
"ApprovalBuilder",
"<",
"T",
">",
"of",
"(",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"return",
"new",
"ApprovalBuilder",
"<",
"T",
">",
"(",
"clazz",
")",
";",
"}"
] | Create a new approval builder that will be able to approve objects from the specified class type.
@param clazz the class object for the things you will be approving
@param <T> the type of the objects you will be approving
@return an approval builder that will be able to construct an {@link Approval} for your objects | [
"Create",
"a",
"new",
"approval",
"builder",
"that",
"will",
"be",
"able",
"to",
"approve",
"objects",
"from",
"the",
"specified",
"class",
"type",
"."
] | 5e32ecc3bc7f631e94a7049894fdd99a3aa5b1b8 | https://github.com/nikolavp/approval/blob/5e32ecc3bc7f631e94a7049894fdd99a3aa5b1b8/approval-core/src/main/java/com/github/approval/Approval.java#L78-L81 | train |
nikolavp/approval | approval-core/src/main/java/com/github/approval/Approval.java | Approval.getApprovalPath | @Nonnull
public static Path getApprovalPath(Path filePath) {
Pre.notNull(filePath, "filePath");
String s = filePath.toString();
int extensionIndex = s.lastIndexOf('.');
if (extensionIndex == -1) {
return Paths.get(s + FOR_APPROVAL_EXTENSION);
}
int lastPartOfPath = s.lastIndexOf('/');
if (lastPartOfPath != -1 && lastPartOfPath > extensionIndex) {
//there was no extension and the directory contains dots.
return Paths.get(s + FOR_APPROVAL_EXTENSION);
}
String firstPart = s.substring(0, extensionIndex);
String extension = s.substring(extensionIndex);
return Paths.get(firstPart + FOR_APPROVAL_EXTENSION + extension);
} | java | @Nonnull
public static Path getApprovalPath(Path filePath) {
Pre.notNull(filePath, "filePath");
String s = filePath.toString();
int extensionIndex = s.lastIndexOf('.');
if (extensionIndex == -1) {
return Paths.get(s + FOR_APPROVAL_EXTENSION);
}
int lastPartOfPath = s.lastIndexOf('/');
if (lastPartOfPath != -1 && lastPartOfPath > extensionIndex) {
//there was no extension and the directory contains dots.
return Paths.get(s + FOR_APPROVAL_EXTENSION);
}
String firstPart = s.substring(0, extensionIndex);
String extension = s.substring(extensionIndex);
return Paths.get(firstPart + FOR_APPROVAL_EXTENSION + extension);
} | [
"@",
"Nonnull",
"public",
"static",
"Path",
"getApprovalPath",
"(",
"Path",
"filePath",
")",
"{",
"Pre",
".",
"notNull",
"(",
"filePath",
",",
"\"filePath\"",
")",
";",
"String",
"s",
"=",
"filePath",
".",
"toString",
"(",
")",
";",
"int",
"extensionIndex"... | Get the path for approval from the original file path.
@param filePath the original path to value
@return the path for approval | [
"Get",
"the",
"path",
"for",
"approval",
"from",
"the",
"original",
"file",
"path",
"."
] | 5e32ecc3bc7f631e94a7049894fdd99a3aa5b1b8 | https://github.com/nikolavp/approval/blob/5e32ecc3bc7f631e94a7049894fdd99a3aa5b1b8/approval-core/src/main/java/com/github/approval/Approval.java#L89-L111 | train |
mapcode-foundation/mapcode-java | src/main/java/com/mapcode/Point.java | Point.fromUniformlyDistributedRandomPoints | @Nonnull
public static Point fromUniformlyDistributedRandomPoints(@Nonnull final Random randomGenerator) {
checkNonnull("randomGenerator", randomGenerator);
// Calculate uniformly distributed 3D point on sphere (radius = 1.0):
// http://mathproofs.blogspot.co.il/2005/04/uniform-random-distribution-on-sphere.html
final double unitRand1 = randomGenerator.nextDouble();
final double unitRand2 = randomGenerator.nextDouble();
final double theta0 = (2.0 * Math.PI) * unitRand1;
final double theta1 = Math.acos(1.0 - (2.0 * unitRand2));
final double x = Math.sin(theta0) * Math.sin(theta1);
final double y = Math.cos(theta0) * Math.sin(theta1);
final double z = Math.cos(theta1);
// Convert Carthesian 3D point into lat/lon (radius = 1.0):
// http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates
final double latRad = Math.asin(z);
final double lonRad = Math.atan2(y, x);
// Convert radians to degrees.
assert !Double.isNaN(latRad);
assert !Double.isNaN(lonRad);
final double lat = latRad * (180.0 / Math.PI);
final double lon = lonRad * (180.0 / Math.PI);
return fromDeg(lat, lon);
} | java | @Nonnull
public static Point fromUniformlyDistributedRandomPoints(@Nonnull final Random randomGenerator) {
checkNonnull("randomGenerator", randomGenerator);
// Calculate uniformly distributed 3D point on sphere (radius = 1.0):
// http://mathproofs.blogspot.co.il/2005/04/uniform-random-distribution-on-sphere.html
final double unitRand1 = randomGenerator.nextDouble();
final double unitRand2 = randomGenerator.nextDouble();
final double theta0 = (2.0 * Math.PI) * unitRand1;
final double theta1 = Math.acos(1.0 - (2.0 * unitRand2));
final double x = Math.sin(theta0) * Math.sin(theta1);
final double y = Math.cos(theta0) * Math.sin(theta1);
final double z = Math.cos(theta1);
// Convert Carthesian 3D point into lat/lon (radius = 1.0):
// http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates
final double latRad = Math.asin(z);
final double lonRad = Math.atan2(y, x);
// Convert radians to degrees.
assert !Double.isNaN(latRad);
assert !Double.isNaN(lonRad);
final double lat = latRad * (180.0 / Math.PI);
final double lon = lonRad * (180.0 / Math.PI);
return fromDeg(lat, lon);
} | [
"@",
"Nonnull",
"public",
"static",
"Point",
"fromUniformlyDistributedRandomPoints",
"(",
"@",
"Nonnull",
"final",
"Random",
"randomGenerator",
")",
"{",
"checkNonnull",
"(",
"\"randomGenerator\"",
",",
"randomGenerator",
")",
";",
"// Calculate uniformly distributed 3D poi... | Create a random point, uniformly distributed over the surface of the Earth.
@param randomGenerator Random generator used to create a point.
@return Random point with uniform distribution over the sphere. | [
"Create",
"a",
"random",
"point",
"uniformly",
"distributed",
"over",
"the",
"surface",
"of",
"the",
"Earth",
"."
] | f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8 | https://github.com/mapcode-foundation/mapcode-java/blob/f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8/src/main/java/com/mapcode/Point.java#L138-L163 | train |
mapcode-foundation/mapcode-java | src/main/java/com/mapcode/Point.java | Point.distanceInMeters | public static double distanceInMeters(@Nonnull final Point p1, @Nonnull final Point p2) {
checkNonnull("p1", p1);
checkNonnull("p2", p2);
final Point from;
final Point to;
if (p1.getLonDeg() <= p2.getLonDeg()) {
from = p1;
to = p2;
} else {
from = p2;
to = p1;
}
// Calculate mid point of 2 latitudes.
final double avgLat = (from.getLatDeg() + to.getLatDeg()) / 2.0;
final double deltaLatDeg = Math.abs(to.getLatDeg() - from.getLatDeg());
final double deltaLonDeg360 = Math.abs(to.getLonDeg() - from.getLonDeg());
final double deltaLonDeg = ((deltaLonDeg360 <= 180.0) ? deltaLonDeg360 : (360.0 - deltaLonDeg360));
// Meters per longitude is fixed; per latitude requires * cos(avg(lat)).
final double deltaXMeters = degreesLonToMetersAtLat(deltaLonDeg, avgLat);
final double deltaYMeters = degreesLatToMeters(deltaLatDeg);
// Calculate length through Earth. This is an approximation, but works fine for short distances.
return Math.sqrt((deltaXMeters * deltaXMeters) + (deltaYMeters * deltaYMeters));
} | java | public static double distanceInMeters(@Nonnull final Point p1, @Nonnull final Point p2) {
checkNonnull("p1", p1);
checkNonnull("p2", p2);
final Point from;
final Point to;
if (p1.getLonDeg() <= p2.getLonDeg()) {
from = p1;
to = p2;
} else {
from = p2;
to = p1;
}
// Calculate mid point of 2 latitudes.
final double avgLat = (from.getLatDeg() + to.getLatDeg()) / 2.0;
final double deltaLatDeg = Math.abs(to.getLatDeg() - from.getLatDeg());
final double deltaLonDeg360 = Math.abs(to.getLonDeg() - from.getLonDeg());
final double deltaLonDeg = ((deltaLonDeg360 <= 180.0) ? deltaLonDeg360 : (360.0 - deltaLonDeg360));
// Meters per longitude is fixed; per latitude requires * cos(avg(lat)).
final double deltaXMeters = degreesLonToMetersAtLat(deltaLonDeg, avgLat);
final double deltaYMeters = degreesLatToMeters(deltaLatDeg);
// Calculate length through Earth. This is an approximation, but works fine for short distances.
return Math.sqrt((deltaXMeters * deltaXMeters) + (deltaYMeters * deltaYMeters));
} | [
"public",
"static",
"double",
"distanceInMeters",
"(",
"@",
"Nonnull",
"final",
"Point",
"p1",
",",
"@",
"Nonnull",
"final",
"Point",
"p2",
")",
"{",
"checkNonnull",
"(",
"\"p1\"",
",",
"p1",
")",
";",
"checkNonnull",
"(",
"\"p2\"",
",",
"p2",
")",
";",
... | Calculate the distance between two points. This algorithm does not take the curvature of the Earth into
account, so it only works for small distance up to, say 200 km, and not too close to the poles.
@param p1 Point 1.
@param p2 Point 2.
@return Straight distance between p1 and p2. Only accurate for small distances up to 200 km. | [
"Calculate",
"the",
"distance",
"between",
"two",
"points",
".",
"This",
"algorithm",
"does",
"not",
"take",
"the",
"curvature",
"of",
"the",
"Earth",
"into",
"account",
"so",
"it",
"only",
"works",
"for",
"small",
"distance",
"up",
"to",
"say",
"200",
"km... | f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8 | https://github.com/mapcode-foundation/mapcode-java/blob/f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8/src/main/java/com/mapcode/Point.java#L173-L201 | train |
btrplace/scheduler | btrpsl/src/main/java/org/btrplace/btrpsl/constraint/migration/BeforeBuilder.java | BeforeBuilder.buildConstraint | @Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
// Get the first parameter
@SuppressWarnings("unchecked")
List<VM> s = (List<VM>) params[0].transform(this, t, args.get(0));
if (s == null) {
return Collections.emptyList();
}
// Get param 'OneOf'
Object obj = params[1].transform(this, t, args.get(1));
if (obj == null) {
return Collections.emptyList();
}
if (obj instanceof List) {
@SuppressWarnings("unchecked")
List<VM> s2 = (List<VM>) obj;
if (s2.isEmpty()) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a non-empty list of VMs");
return Collections.emptyList();
}
return Precedence.newPrecedence(s, s2);
} else if (obj instanceof String) {
String timestamp = (String) obj;
if ("".equals(timestamp)) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a non-empty string");
return Collections.emptyList();
}
return Deadline.newDeadline(s, timestamp);
} else {
return Collections.emptyList();
}
} | java | @Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
// Get the first parameter
@SuppressWarnings("unchecked")
List<VM> s = (List<VM>) params[0].transform(this, t, args.get(0));
if (s == null) {
return Collections.emptyList();
}
// Get param 'OneOf'
Object obj = params[1].transform(this, t, args.get(1));
if (obj == null) {
return Collections.emptyList();
}
if (obj instanceof List) {
@SuppressWarnings("unchecked")
List<VM> s2 = (List<VM>) obj;
if (s2.isEmpty()) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a non-empty list of VMs");
return Collections.emptyList();
}
return Precedence.newPrecedence(s, s2);
} else if (obj instanceof String) {
String timestamp = (String) obj;
if ("".equals(timestamp)) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a non-empty string");
return Collections.emptyList();
}
return Deadline.newDeadline(s, timestamp);
} else {
return Collections.emptyList();
}
} | [
"@",
"Override",
"public",
"List",
"<",
"?",
"extends",
"SatConstraint",
">",
"buildConstraint",
"(",
"BtrPlaceTree",
"t",
",",
"List",
"<",
"BtrpOperand",
">",
"args",
")",
"{",
"if",
"(",
"!",
"checkConformance",
"(",
"t",
",",
"args",
")",
")",
"{",
... | Build a precedence constraint.
@param t the current tree
@param args can be a non-empty set of vms ({@see Precedence} constraint) or
a timestamp string ({@see Deadline} constraint)
@return a constraint | [
"Build",
"a",
"precedence",
"constraint",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/btrpsl/src/main/java/org/btrplace/btrpsl/constraint/migration/BeforeBuilder.java#L61-L98 | train |
m-m-m/util | collection/src/main/java/net/sf/mmm/util/collection/base/BasicDoubleLinkedNode.java | BasicDoubleLinkedNode.remove | public void remove() {
BasicDoubleLinkedNode<V> next = getNext();
if (next != null) {
next.previous = this.previous;
}
if (this.previous != null) {
this.previous.setNext(next);
}
} | java | public void remove() {
BasicDoubleLinkedNode<V> next = getNext();
if (next != null) {
next.previous = this.previous;
}
if (this.previous != null) {
this.previous.setNext(next);
}
} | [
"public",
"void",
"remove",
"(",
")",
"{",
"BasicDoubleLinkedNode",
"<",
"V",
">",
"next",
"=",
"getNext",
"(",
")",
";",
"if",
"(",
"next",
"!=",
"null",
")",
"{",
"next",
".",
"previous",
"=",
"this",
".",
"previous",
";",
"}",
"if",
"(",
"this",... | This method removes this node from the double linked list. | [
"This",
"method",
"removes",
"this",
"node",
"from",
"the",
"double",
"linked",
"list",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/collection/src/main/java/net/sf/mmm/util/collection/base/BasicDoubleLinkedNode.java#L141-L150 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/plan/event/MigrateVM.java | MigrateVM.applyAction | @Override
public boolean applyAction(Model i) {
Mapping c = i.getMapping();
return c.isRunning(vm)
&& c.getVMLocation(vm).equals(src)
&& !src.equals(dst)
&& c.addRunningVM(vm, dst);
} | java | @Override
public boolean applyAction(Model i) {
Mapping c = i.getMapping();
return c.isRunning(vm)
&& c.getVMLocation(vm).equals(src)
&& !src.equals(dst)
&& c.addRunningVM(vm, dst);
} | [
"@",
"Override",
"public",
"boolean",
"applyAction",
"(",
"Model",
"i",
")",
"{",
"Mapping",
"c",
"=",
"i",
".",
"getMapping",
"(",
")",
";",
"return",
"c",
".",
"isRunning",
"(",
"vm",
")",
"&&",
"c",
".",
"getVMLocation",
"(",
"vm",
")",
".",
"eq... | Make the VM running on the destination node
in the given model.
@param i the model to alter with the action
@return {@code true} iff the VM is running on the destination node | [
"Make",
"the",
"VM",
"running",
"on",
"the",
"destination",
"node",
"in",
"the",
"given",
"model",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/plan/event/MigrateVM.java#L111-L118 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.resetCaches | public static void resetCaches(int size) {
nodesCache = new LinkedHashMap<String, List<Node>>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, List<Node>> foo) {
return size() == size;
}
};
vmsCache = new LinkedHashMap<String, List<VM>>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, List<VM>> foo) {
return size() == size;
}
};
} | java | public static void resetCaches(int size) {
nodesCache = new LinkedHashMap<String, List<Node>>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, List<Node>> foo) {
return size() == size;
}
};
vmsCache = new LinkedHashMap<String, List<VM>>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, List<VM>> foo) {
return size() == size;
}
};
} | [
"public",
"static",
"void",
"resetCaches",
"(",
"int",
"size",
")",
"{",
"nodesCache",
"=",
"new",
"LinkedHashMap",
"<",
"String",
",",
"List",
"<",
"Node",
">",
">",
"(",
")",
"{",
"@",
"Override",
"protected",
"boolean",
"removeEldestEntry",
"(",
"Map",
... | Reset the cache of element sets.
@param size the new cache size | [
"Reset",
"the",
"cache",
"of",
"element",
"sets",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L68-L82 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredInt | public static int requiredInt(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return (Integer) o.get(id);
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a int from string '" + id + "'", e);
}
} | java | public static int requiredInt(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return (Integer) o.get(id);
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a int from string '" + id + "'", e);
}
} | [
"public",
"static",
"int",
"requiredInt",
"(",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"try",
"{",
"return",
"(",
"Integer",
")",
"o",
".",
"get",
"(",
"id",
")",... | Read an expected integer.
@param o the object to parse
@param id the key in the map that points to an integer
@return the int
@throws JSONConverterException if the key does not point to a int | [
"Read",
"an",
"expected",
"integer",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L92-L99 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.optInt | public static int optInt(JSONObject o, String id, int def) throws JSONConverterException {
if (o.containsKey(id)) {
try {
return (Integer) o.get(id);
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a int from string '" + id + "'", e);
}
}
return def;
} | java | public static int optInt(JSONObject o, String id, int def) throws JSONConverterException {
if (o.containsKey(id)) {
try {
return (Integer) o.get(id);
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a int from string '" + id + "'", e);
}
}
return def;
} | [
"public",
"static",
"int",
"optInt",
"(",
"JSONObject",
"o",
",",
"String",
"id",
",",
"int",
"def",
")",
"throws",
"JSONConverterException",
"{",
"if",
"(",
"o",
".",
"containsKey",
"(",
"id",
")",
")",
"{",
"try",
"{",
"return",
"(",
"Integer",
")",
... | Read an optional integer.
@param o the object to parse
@param id the key in the map that points to an integer
@param def the default integer value if the key is absent
@return the resulting integer
@throws JSONConverterException if the key does not point to a int | [
"Read",
"an",
"optional",
"integer",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L110-L119 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.checkKeys | public static void checkKeys(JSONObject o, String... keys) throws JSONConverterException {
for (String k : keys) {
if (!o.containsKey(k)) {
throw new JSONConverterException("Missing key '" + k + "'");
}
}
} | java | public static void checkKeys(JSONObject o, String... keys) throws JSONConverterException {
for (String k : keys) {
if (!o.containsKey(k)) {
throw new JSONConverterException("Missing key '" + k + "'");
}
}
} | [
"public",
"static",
"void",
"checkKeys",
"(",
"JSONObject",
"o",
",",
"String",
"...",
"keys",
")",
"throws",
"JSONConverterException",
"{",
"for",
"(",
"String",
"k",
":",
"keys",
")",
"{",
"if",
"(",
"!",
"o",
".",
"containsKey",
"(",
"k",
")",
")",
... | Check if some keys are present.
@param o the object to parse
@param keys the keys to check
@throws JSONConverterException when at least a key is missing | [
"Check",
"if",
"some",
"keys",
"are",
"present",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L128-L134 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredString | public static String requiredString(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
return x.toString();
} | java | public static String requiredString(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
return x.toString();
} | [
"public",
"static",
"String",
"requiredString",
"(",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"Object",
"x",
"=",
"o",
".",
"get",
"(",
"id",
")",
";",
"return",
"... | Read an expected string.
@param o the object to parse
@param id the key in the map that points to the string
@return the string
@throws JSONConverterException if the key does not point to a string | [
"Read",
"an",
"expected",
"string",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L144-L148 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredDouble | public static double requiredDouble(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof Number)) {
throw new JSONConverterException("Number expected at key '" + id + "' but was '" + x.getClass() + "'.");
}
return ((Number) x).doubleValue();
} | java | public static double requiredDouble(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof Number)) {
throw new JSONConverterException("Number expected at key '" + id + "' but was '" + x.getClass() + "'.");
}
return ((Number) x).doubleValue();
} | [
"public",
"static",
"double",
"requiredDouble",
"(",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"Object",
"x",
"=",
"o",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
... | Read an expected double.
@param o the object to parse
@param id the key in the map that points to the double
@return the double
@throws JSONConverterException if the key does not point to a double | [
"Read",
"an",
"expected",
"double",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L158-L165 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredBoolean | public static boolean requiredBoolean(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof Boolean)) {
throw new JSONConverterException("Boolean expected at key '" + id + "' but was '" + x.getClass() + "'.");
}
return (Boolean) x;
} | java | public static boolean requiredBoolean(JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof Boolean)) {
throw new JSONConverterException("Boolean expected at key '" + id + "' but was '" + x.getClass() + "'.");
}
return (Boolean) x;
} | [
"public",
"static",
"boolean",
"requiredBoolean",
"(",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"Object",
"x",
"=",
"o",
".",
"get",
"(",
"id",
")",
";",
"if",
"("... | Read an expected boolean.
@param o the object to parse
@param id the id in the map that should point to the boolean
@return the boolean
@throws org.btrplace.json.JSONConverterException if the key does not point to a boolean | [
"Read",
"an",
"expected",
"boolean",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L175-L182 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.vmsFromJSON | public static List<VM> vmsFromJSON(Model mo, JSONArray a) throws JSONConverterException {
String json = a.toJSONString();
List<VM> s = vmsCache.get(json);
if (s != null) {
return s;
}
s = new ArrayList<>(a.size());
for (Object o : a) {
s.add(getVM(mo, (int) o));
}
vmsCache.put(json, s);
return s;
} | java | public static List<VM> vmsFromJSON(Model mo, JSONArray a) throws JSONConverterException {
String json = a.toJSONString();
List<VM> s = vmsCache.get(json);
if (s != null) {
return s;
}
s = new ArrayList<>(a.size());
for (Object o : a) {
s.add(getVM(mo, (int) o));
}
vmsCache.put(json, s);
return s;
} | [
"public",
"static",
"List",
"<",
"VM",
">",
"vmsFromJSON",
"(",
"Model",
"mo",
",",
"JSONArray",
"a",
")",
"throws",
"JSONConverterException",
"{",
"String",
"json",
"=",
"a",
".",
"toJSONString",
"(",
")",
";",
"List",
"<",
"VM",
">",
"s",
"=",
"vmsCa... | Convert an array of VM identifiers to a set of VMs.
This operation uses a cache of previously converted set of VMs.
@param mo the associated model to browse
@param a the json array
@return the set of VMs | [
"Convert",
"an",
"array",
"of",
"VM",
"identifiers",
"to",
"a",
"set",
"of",
"VMs",
".",
"This",
"operation",
"uses",
"a",
"cache",
"of",
"previously",
"converted",
"set",
"of",
"VMs",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L191-L203 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.nodesFromJSON | public static List<Node> nodesFromJSON(Model mo, JSONArray a) throws JSONConverterException {
String json = a.toJSONString();
List<Node> s = nodesCache.get(json);
if (s != null) {
return s;
}
s = new ArrayList<>(a.size());
for (Object o : a) {
s.add(getNode(mo, (int) o));
}
nodesCache.put(json, s);
return s;
} | java | public static List<Node> nodesFromJSON(Model mo, JSONArray a) throws JSONConverterException {
String json = a.toJSONString();
List<Node> s = nodesCache.get(json);
if (s != null) {
return s;
}
s = new ArrayList<>(a.size());
for (Object o : a) {
s.add(getNode(mo, (int) o));
}
nodesCache.put(json, s);
return s;
} | [
"public",
"static",
"List",
"<",
"Node",
">",
"nodesFromJSON",
"(",
"Model",
"mo",
",",
"JSONArray",
"a",
")",
"throws",
"JSONConverterException",
"{",
"String",
"json",
"=",
"a",
".",
"toJSONString",
"(",
")",
";",
"List",
"<",
"Node",
">",
"s",
"=",
... | Convert an array of VM identifiers to a set of VMs.
This operation uses a cache of previously converted set of nodes.
@param mo the associated model to browse
@param a the json array
@return the set of nodes | [
"Convert",
"an",
"array",
"of",
"VM",
"identifiers",
"to",
"a",
"set",
"of",
"VMs",
".",
"This",
"operation",
"uses",
"a",
"cache",
"of",
"previously",
"converted",
"set",
"of",
"nodes",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L212-L224 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.vmsToJSON | public static JSONArray vmsToJSON(Collection<VM> s) {
JSONArray a = new JSONArray();
for (Element e : s) {
a.add(e.id());
}
return a;
} | java | public static JSONArray vmsToJSON(Collection<VM> s) {
JSONArray a = new JSONArray();
for (Element e : s) {
a.add(e.id());
}
return a;
} | [
"public",
"static",
"JSONArray",
"vmsToJSON",
"(",
"Collection",
"<",
"VM",
">",
"s",
")",
"{",
"JSONArray",
"a",
"=",
"new",
"JSONArray",
"(",
")",
";",
"for",
"(",
"Element",
"e",
":",
"s",
")",
"{",
"a",
".",
"add",
"(",
"e",
".",
"id",
"(",
... | Convert a collection of VMs to an array of VM identifiers.
@param s the VMs
@return a json formatted array of integers | [
"Convert",
"a",
"collection",
"of",
"VMs",
"to",
"an",
"array",
"of",
"VM",
"identifiers",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L232-L238 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.nodesToJSON | public static JSONArray nodesToJSON(Collection<Node> s) {
JSONArray a = new JSONArray();
for (Element e : s) {
a.add(e.id());
}
return a;
} | java | public static JSONArray nodesToJSON(Collection<Node> s) {
JSONArray a = new JSONArray();
for (Element e : s) {
a.add(e.id());
}
return a;
} | [
"public",
"static",
"JSONArray",
"nodesToJSON",
"(",
"Collection",
"<",
"Node",
">",
"s",
")",
"{",
"JSONArray",
"a",
"=",
"new",
"JSONArray",
"(",
")",
";",
"for",
"(",
"Element",
"e",
":",
"s",
")",
"{",
"a",
".",
"add",
"(",
"e",
".",
"id",
"(... | Convert a collection nodes to an array of nodes identifiers.
@param s the VMs
@return a json formatted array of integers | [
"Convert",
"a",
"collection",
"nodes",
"to",
"an",
"array",
"of",
"nodes",
"identifiers",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L246-L252 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredVMs | public static List<VM> requiredVMs(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("integers expected at key '" + id + "'");
}
return vmsFromJSON(mo, (JSONArray) x);
} | java | public static List<VM> requiredVMs(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("integers expected at key '" + id + "'");
}
return vmsFromJSON(mo, (JSONArray) x);
} | [
"public",
"static",
"List",
"<",
"VM",
">",
"requiredVMs",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"Object",
"x",
"=",
"o",
".",
"get",
... | Read an expected list of VMs.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the list
@return the parsed list
@throws JSONConverterException if the key does not point to a list of VM identifiers | [
"Read",
"an",
"expected",
"list",
"of",
"VMs",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L263-L270 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredNodes | public static List<Node> requiredNodes(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("integers expected at key '" + id + "'");
}
return nodesFromJSON(mo, (JSONArray) x);
} | java | public static List<Node> requiredNodes(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("integers expected at key '" + id + "'");
}
return nodesFromJSON(mo, (JSONArray) x);
} | [
"public",
"static",
"List",
"<",
"Node",
">",
"requiredNodes",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"Object",
"x",
"=",
"o",
".",
"get... | Read an expected list of nodes.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the list
@return the parsed list
@throws JSONConverterException if the key does not point to a list of nodes identifiers | [
"Read",
"an",
"expected",
"list",
"of",
"nodes",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L281-L288 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredVMPart | public static Set<Collection<VM>> requiredVMPart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<VM>> vms = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
vms.add(vmsFromJSON(mo, (JSONArray) obj));
}
return vms;
} | java | public static Set<Collection<VM>> requiredVMPart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<VM>> vms = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
vms.add(vmsFromJSON(mo, (JSONArray) obj));
}
return vms;
} | [
"public",
"static",
"Set",
"<",
"Collection",
"<",
"VM",
">",
">",
"requiredVMPart",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"Set",
"<",
"Collection",
"<",
"VM",
">>",
"vms",
"=",
"ne... | Read partitions of VMs.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the partitions
@return the parsed partition
@throws JSONConverterException if the key does not point to partitions of VMs | [
"Read",
"partitions",
"of",
"VMs",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L299-L309 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredNodePart | public static Set<Collection<Node>> requiredNodePart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<Node>> nodes = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
nodes.add(nodesFromJSON(mo, (JSONArray) obj));
}
return nodes;
} | java | public static Set<Collection<Node>> requiredNodePart(Model mo, JSONObject o, String id) throws JSONConverterException {
Set<Collection<Node>> nodes = new HashSet<>();
Object x = o.get(id);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("Set of identifiers sets expected at key '" + id + "'");
}
for (Object obj : (JSONArray) x) {
nodes.add(nodesFromJSON(mo, (JSONArray) obj));
}
return nodes;
} | [
"public",
"static",
"Set",
"<",
"Collection",
"<",
"Node",
">",
">",
"requiredNodePart",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"Set",
"<",
"Collection",
"<",
"Node",
">>",
"nodes",
"=... | Read partitions of nodes.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the partitions
@return the parsed partition
@throws JSONConverterException if the key does not point to partitions of nodes | [
"Read",
"partitions",
"of",
"nodes",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L320-L330 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredVM | public static VM requiredVM(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return getVM(mo, (Integer) o.get(id));
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a VM identifier from string at key '" + id + "'", e);
}
} | java | public static VM requiredVM(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return getVM(mo, (Integer) o.get(id));
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a VM identifier from string at key '" + id + "'", e);
}
} | [
"public",
"static",
"VM",
"requiredVM",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"try",
"{",
"return",
"getVM",
"(",
"mo",
",",
"(",
"Inte... | Read an expected VM.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the VM identifier
@return the VM
@throws JSONConverterException if the key does not point to a VM identifier | [
"Read",
"an",
"expected",
"VM",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L341-L348 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.requiredNode | public static Node requiredNode(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return getNode(mo, (Integer) o.get(id));
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a Node identifier from string at key '" + id + "'", e);
}
} | java | public static Node requiredNode(Model mo, JSONObject o, String id) throws JSONConverterException {
checkKeys(o, id);
try {
return getNode(mo, (Integer) o.get(id));
} catch (ClassCastException e) {
throw new JSONConverterException("Unable to read a Node identifier from string at key '" + id + "'", e);
}
} | [
"public",
"static",
"Node",
"requiredNode",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
",",
"String",
"id",
")",
"throws",
"JSONConverterException",
"{",
"checkKeys",
"(",
"o",
",",
"id",
")",
";",
"try",
"{",
"return",
"getNode",
"(",
"mo",
",",
"(",
... | Read an expected node.
@param mo the associated model to browse
@param o the object to parse
@param id the key in the map that points to the node identifier
@return the node
@throws JSONConverterException if the key does not point to a node identifier | [
"Read",
"an",
"expected",
"node",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L359-L366 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.getVM | public static VM getVM(Model mo, int vmID) throws JSONConverterException {
VM vm = new VM(vmID);
if (!mo.contains(vm)) {
throw new JSONConverterException("Undeclared vm '" + vmID + "'");
}
return vm;
} | java | public static VM getVM(Model mo, int vmID) throws JSONConverterException {
VM vm = new VM(vmID);
if (!mo.contains(vm)) {
throw new JSONConverterException("Undeclared vm '" + vmID + "'");
}
return vm;
} | [
"public",
"static",
"VM",
"getVM",
"(",
"Model",
"mo",
",",
"int",
"vmID",
")",
"throws",
"JSONConverterException",
"{",
"VM",
"vm",
"=",
"new",
"VM",
"(",
"vmID",
")",
";",
"if",
"(",
"!",
"mo",
".",
"contains",
"(",
"vm",
")",
")",
"{",
"throw",
... | Get a VM from its identifier.
The VM is already a part of the model.
@param mo the associated model to browse
@param vmID the node identifier
@return the resulting VM
@throws JSONConverterException if there is no model, or if the VM is unknown. | [
"Get",
"a",
"VM",
"from",
"its",
"identifier",
".",
"The",
"VM",
"is",
"already",
"a",
"part",
"of",
"the",
"model",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L377-L383 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/JSONs.java | JSONs.getNode | public static Node getNode(Model mo, int nodeID) throws JSONConverterException {
Node n = new Node(nodeID);
if (!mo.contains(n)) {
throw new JSONConverterException("Undeclared node '" + nodeID + "'");
}
return n;
} | java | public static Node getNode(Model mo, int nodeID) throws JSONConverterException {
Node n = new Node(nodeID);
if (!mo.contains(n)) {
throw new JSONConverterException("Undeclared node '" + nodeID + "'");
}
return n;
} | [
"public",
"static",
"Node",
"getNode",
"(",
"Model",
"mo",
",",
"int",
"nodeID",
")",
"throws",
"JSONConverterException",
"{",
"Node",
"n",
"=",
"new",
"Node",
"(",
"nodeID",
")",
";",
"if",
"(",
"!",
"mo",
".",
"contains",
"(",
"n",
")",
")",
"{",
... | Get a node from its identifier.
The node is already a part of the model
@param mo the associated model to browse
@param nodeID the node identifier
@return the resulting node
@throws JSONConverterException if there is no model, or if the node is unknown. | [
"Get",
"a",
"node",
"from",
"its",
"identifier",
".",
"The",
"node",
"is",
"already",
"a",
"part",
"of",
"the",
"model"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/JSONs.java#L394-L400 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/CMinMTTR.java | CMinMTTR.postCostConstraints | @Override
public void postCostConstraints() {
if (!costActivated) {
costActivated = true;
rp.getLogger().debug("Post the cost-oriented constraints");
List<IntVar> mttrs = Stream.concat(rp.getVMActions().stream(), rp.getNodeActions().stream())
.map(Transition::getEnd).collect(Collectors.toList());
rp.getModel().post(rp.getModel().sum(mttrs.toArray(new IntVar[0]), "=", cost));
}
} | java | @Override
public void postCostConstraints() {
if (!costActivated) {
costActivated = true;
rp.getLogger().debug("Post the cost-oriented constraints");
List<IntVar> mttrs = Stream.concat(rp.getVMActions().stream(), rp.getNodeActions().stream())
.map(Transition::getEnd).collect(Collectors.toList());
rp.getModel().post(rp.getModel().sum(mttrs.toArray(new IntVar[0]), "=", cost));
}
} | [
"@",
"Override",
"public",
"void",
"postCostConstraints",
"(",
")",
"{",
"if",
"(",
"!",
"costActivated",
")",
"{",
"costActivated",
"=",
"true",
";",
"rp",
".",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"Post the cost-oriented constraints\"",
")",
";",
"L... | Post the constraints related to the objective. | [
"Post",
"the",
"constraints",
"related",
"to",
"the",
"objective",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/CMinMTTR.java#L205-L215 | train |
mapcode-foundation/mapcode-java | src/main/java/com/mapcode/DataModel.java | DataModel.getDataFirstRecord | @SuppressWarnings("PointlessArithmeticExpression")
int getDataFirstRecord(final int territoryNumber) {
assert (0 <= territoryNumber) && (territoryNumber <= Territory.AAA.getNumber());
return index[territoryNumber + POS_INDEX_FIRST_RECORD];
} | java | @SuppressWarnings("PointlessArithmeticExpression")
int getDataFirstRecord(final int territoryNumber) {
assert (0 <= territoryNumber) && (territoryNumber <= Territory.AAA.getNumber());
return index[territoryNumber + POS_INDEX_FIRST_RECORD];
} | [
"@",
"SuppressWarnings",
"(",
"\"PointlessArithmeticExpression\"",
")",
"int",
"getDataFirstRecord",
"(",
"final",
"int",
"territoryNumber",
")",
"{",
"assert",
"(",
"0",
"<=",
"territoryNumber",
")",
"&&",
"(",
"territoryNumber",
"<=",
"Territory",
".",
"AAA",
".... | Low-level routines for data access. | [
"Low",
"-",
"level",
"routines",
"for",
"data",
"access",
"."
] | f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8 | https://github.com/mapcode-foundation/mapcode-java/blob/f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8/src/main/java/com/mapcode/DataModel.java#L235-L239 | train |
btrplace/scheduler | btrpsl/src/main/java/org/btrplace/btrpsl/includes/PathBasedIncludes.java | PathBasedIncludes.getScripts | @Override
public List<Script> getScripts(String name) throws ScriptBuilderException {
List<Script> scripts = new ArrayList<>();
if (!name.endsWith(".*")) {
String toSearch = name.replaceAll("\\.", File.separator) + Script.EXTENSION;
for (File path : paths) {
File f = new File(path.getPath() + File.separator + toSearch);
if (f.exists()) {
scripts.add(builder.build(f));
break;
}
}
} else {
//We need to consolidate the errors in allEx and rethrow it at the end if necessary
ScriptBuilderException allEx = null;
String base = name.substring(0, name.length() - 2).replaceAll("\\.", File.separator);
for (File path : paths) {
File f = new File(path.getPath() + File.separator + base);
File[] files = f.listFiles();
if (f.isDirectory() && files != null) {
for (File sf : files) {
if (sf.getName().endsWith(Script.EXTENSION)) {
try {
scripts.add(builder.build(sf));
} catch (ScriptBuilderException ex) {
if (allEx == null) {
allEx = ex;
} else {
allEx.getErrorReporter().getErrors().addAll(ex.getErrorReporter().getErrors());
}
}
}
}
}
}
if (allEx != null) {
throw allEx;
}
}
return scripts;
} | java | @Override
public List<Script> getScripts(String name) throws ScriptBuilderException {
List<Script> scripts = new ArrayList<>();
if (!name.endsWith(".*")) {
String toSearch = name.replaceAll("\\.", File.separator) + Script.EXTENSION;
for (File path : paths) {
File f = new File(path.getPath() + File.separator + toSearch);
if (f.exists()) {
scripts.add(builder.build(f));
break;
}
}
} else {
//We need to consolidate the errors in allEx and rethrow it at the end if necessary
ScriptBuilderException allEx = null;
String base = name.substring(0, name.length() - 2).replaceAll("\\.", File.separator);
for (File path : paths) {
File f = new File(path.getPath() + File.separator + base);
File[] files = f.listFiles();
if (f.isDirectory() && files != null) {
for (File sf : files) {
if (sf.getName().endsWith(Script.EXTENSION)) {
try {
scripts.add(builder.build(sf));
} catch (ScriptBuilderException ex) {
if (allEx == null) {
allEx = ex;
} else {
allEx.getErrorReporter().getErrors().addAll(ex.getErrorReporter().getErrors());
}
}
}
}
}
}
if (allEx != null) {
throw allEx;
}
}
return scripts;
} | [
"@",
"Override",
"public",
"List",
"<",
"Script",
">",
"getScripts",
"(",
"String",
"name",
")",
"throws",
"ScriptBuilderException",
"{",
"List",
"<",
"Script",
">",
"scripts",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"!",
"name",
".",
... | Get the script associated to a given identifier by browsing the given paths.
The first script having a matching identifier is selected, whatever the parsing process result will be
@param name the identifier of the script
@return the script if found
@throws org.btrplace.btrpsl.ScriptBuilderException if the builder was not able to parse the looked script | [
"Get",
"the",
"script",
"associated",
"to",
"a",
"given",
"identifier",
"by",
"browsing",
"the",
"given",
"paths",
".",
"The",
"first",
"script",
"having",
"a",
"matching",
"identifier",
"is",
"selected",
"whatever",
"the",
"parsing",
"process",
"result",
"wil... | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/btrpsl/src/main/java/org/btrplace/btrpsl/includes/PathBasedIncludes.java#L67-L111 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/VMConsumptionComparator.java | VMConsumptionComparator.append | public VMConsumptionComparator append(ShareableResource r, boolean asc) {
rcs.add(r);
ascs.add(asc ? 1 : -1);
return this;
} | java | public VMConsumptionComparator append(ShareableResource r, boolean asc) {
rcs.add(r);
ascs.add(asc ? 1 : -1);
return this;
} | [
"public",
"VMConsumptionComparator",
"append",
"(",
"ShareableResource",
"r",
",",
"boolean",
"asc",
")",
"{",
"rcs",
".",
"add",
"(",
"r",
")",
";",
"ascs",
".",
"add",
"(",
"asc",
"?",
"1",
":",
"-",
"1",
")",
";",
"return",
"this",
";",
"}"
] | Append a new resource to use to make the comparison
@param r the resource to add
@param asc {@code true} for an ascending comparison
@return the current comparator | [
"Append",
"a",
"new",
"resource",
"to",
"use",
"to",
"make",
"the",
"comparison"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/VMConsumptionComparator.java#L77-L81 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.register | public void register(RoutingConverter<? extends Routing> r) {
java2json.put(r.getSupportedRouting(), r);
json2java.put(r.getJSONId(), r);
} | java | public void register(RoutingConverter<? extends Routing> r) {
java2json.put(r.getSupportedRouting(), r);
json2java.put(r.getJSONId(), r);
} | [
"public",
"void",
"register",
"(",
"RoutingConverter",
"<",
"?",
"extends",
"Routing",
">",
"r",
")",
"{",
"java2json",
".",
"put",
"(",
"r",
".",
"getSupportedRouting",
"(",
")",
",",
"r",
")",
";",
"json2java",
".",
"put",
"(",
"r",
".",
"getJSONId",... | Register a routing converter.
@param r the converter to register | [
"Register",
"a",
"routing",
"converter",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L82-L85 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.switchToJSON | public JSONObject switchToJSON(Switch s) {
JSONObject o = new JSONObject();
o.put("id", s.id());
o.put(CAPACITY_LABEL, s.getCapacity());
return o;
} | java | public JSONObject switchToJSON(Switch s) {
JSONObject o = new JSONObject();
o.put("id", s.id());
o.put(CAPACITY_LABEL, s.getCapacity());
return o;
} | [
"public",
"JSONObject",
"switchToJSON",
"(",
"Switch",
"s",
")",
"{",
"JSONObject",
"o",
"=",
"new",
"JSONObject",
"(",
")",
";",
"o",
".",
"put",
"(",
"\"id\"",
",",
"s",
".",
"id",
"(",
")",
")",
";",
"o",
".",
"put",
"(",
"CAPACITY_LABEL",
",",
... | Convert a Switch to a JSON object.
@param s the switch to convert
@return the JSON object | [
"Convert",
"a",
"Switch",
"to",
"a",
"JSON",
"object",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L124-L129 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.switchesToJSON | public JSONArray switchesToJSON(Collection<Switch> c) {
JSONArray a = new JSONArray();
for (Switch s : c) {
a.add(switchToJSON(s));
}
return a;
} | java | public JSONArray switchesToJSON(Collection<Switch> c) {
JSONArray a = new JSONArray();
for (Switch s : c) {
a.add(switchToJSON(s));
}
return a;
} | [
"public",
"JSONArray",
"switchesToJSON",
"(",
"Collection",
"<",
"Switch",
">",
"c",
")",
"{",
"JSONArray",
"a",
"=",
"new",
"JSONArray",
"(",
")",
";",
"for",
"(",
"Switch",
"s",
":",
"c",
")",
"{",
"a",
".",
"add",
"(",
"switchToJSON",
"(",
"s",
... | Convert a collection of switches to an array of JSON switches objects.
@param c the collection of Switches
@return a json formatted array of Switches | [
"Convert",
"a",
"collection",
"of",
"switches",
"to",
"an",
"array",
"of",
"JSON",
"switches",
"objects",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L137-L143 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.physicalElementToJSON | public JSONObject physicalElementToJSON(PhysicalElement pe) {
JSONObject o = new JSONObject();
if (pe instanceof Node) {
o.put("type", NODE_LABEL);
o.put("id", ((Node) pe).id());
} else if (pe instanceof Switch) {
o.put("type", SWITCH_LABEL);
o.put("id", ((Switch) pe).id());
} else {
throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
}
return o;
} | java | public JSONObject physicalElementToJSON(PhysicalElement pe) {
JSONObject o = new JSONObject();
if (pe instanceof Node) {
o.put("type", NODE_LABEL);
o.put("id", ((Node) pe).id());
} else if (pe instanceof Switch) {
o.put("type", SWITCH_LABEL);
o.put("id", ((Switch) pe).id());
} else {
throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
}
return o;
} | [
"public",
"JSONObject",
"physicalElementToJSON",
"(",
"PhysicalElement",
"pe",
")",
"{",
"JSONObject",
"o",
"=",
"new",
"JSONObject",
"(",
")",
";",
"if",
"(",
"pe",
"instanceof",
"Node",
")",
"{",
"o",
".",
"put",
"(",
"\"type\"",
",",
"NODE_LABEL",
")",
... | Convert a PhysicalElement to a JSON object.
@param pe the physical element to convert
@return the JSON object
@throws IllegalArgumentException if the physical element is not supported | [
"Convert",
"a",
"PhysicalElement",
"to",
"a",
"JSON",
"object",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L152-L164 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.linkToJSON | public JSONObject linkToJSON(Link s) {
JSONObject o = new JSONObject();
o.put("id", s.id());
o.put(CAPACITY_LABEL, s.getCapacity());
o.put(SWITCH_LABEL, s.getSwitch().id());
o.put("physicalElement", physicalElementToJSON(s.getElement()));
return o;
} | java | public JSONObject linkToJSON(Link s) {
JSONObject o = new JSONObject();
o.put("id", s.id());
o.put(CAPACITY_LABEL, s.getCapacity());
o.put(SWITCH_LABEL, s.getSwitch().id());
o.put("physicalElement", physicalElementToJSON(s.getElement()));
return o;
} | [
"public",
"JSONObject",
"linkToJSON",
"(",
"Link",
"s",
")",
"{",
"JSONObject",
"o",
"=",
"new",
"JSONObject",
"(",
")",
";",
"o",
".",
"put",
"(",
"\"id\"",
",",
"s",
".",
"id",
"(",
")",
")",
";",
"o",
".",
"put",
"(",
"CAPACITY_LABEL",
",",
"s... | Convert a Link to a JSON object.
@param s the switch to convert
@return the JSON object | [
"Convert",
"a",
"Link",
"to",
"a",
"JSON",
"object",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L172-L179 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.linksToJSON | public JSONArray linksToJSON(Collection<Link> c) {
JSONArray a = new JSONArray();
for (Link l : c) {
a.add(linkToJSON(l));
}
return a;
} | java | public JSONArray linksToJSON(Collection<Link> c) {
JSONArray a = new JSONArray();
for (Link l : c) {
a.add(linkToJSON(l));
}
return a;
} | [
"public",
"JSONArray",
"linksToJSON",
"(",
"Collection",
"<",
"Link",
">",
"c",
")",
"{",
"JSONArray",
"a",
"=",
"new",
"JSONArray",
"(",
")",
";",
"for",
"(",
"Link",
"l",
":",
"c",
")",
"{",
"a",
".",
"add",
"(",
"linkToJSON",
"(",
"l",
")",
")... | Convert a collection of links to an array of JSON links objects.
@param c the collection of Links
@return a JSON formatted array of Links | [
"Convert",
"a",
"collection",
"of",
"links",
"to",
"an",
"array",
"of",
"JSON",
"links",
"objects",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L187-L193 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.routingFromJSON | public Routing routingFromJSON(Model mo, JSONObject o) throws JSONConverterException {
String type = requiredString(o, "type");
RoutingConverter<? extends Routing> c = json2java.get(type);
if (c == null) {
throw new JSONConverterException("No converter available for a routing of type '" + type + "'");
}
return c.fromJSON(mo, o);
} | java | public Routing routingFromJSON(Model mo, JSONObject o) throws JSONConverterException {
String type = requiredString(o, "type");
RoutingConverter<? extends Routing> c = json2java.get(type);
if (c == null) {
throw new JSONConverterException("No converter available for a routing of type '" + type + "'");
}
return c.fromJSON(mo, o);
} | [
"public",
"Routing",
"routingFromJSON",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
")",
"throws",
"JSONConverterException",
"{",
"String",
"type",
"=",
"requiredString",
"(",
"o",
",",
"\"type\"",
")",
";",
"RoutingConverter",
"<",
"?",
"extends",
"Routing",
... | Convert a JSON routing object into the corresponding java Routing implementation.
@param o the JSON object to convert
@throws JSONConverterException if the Routing implementation is not known | [
"Convert",
"a",
"JSON",
"routing",
"object",
"into",
"the",
"corresponding",
"java",
"Routing",
"implementation",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L217-L225 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.switchFromJSON | public Switch switchFromJSON(JSONObject o) throws JSONConverterException {
return new Switch(requiredInt(o, "id"), readCapacity(o));
} | java | public Switch switchFromJSON(JSONObject o) throws JSONConverterException {
return new Switch(requiredInt(o, "id"), readCapacity(o));
} | [
"public",
"Switch",
"switchFromJSON",
"(",
"JSONObject",
"o",
")",
"throws",
"JSONConverterException",
"{",
"return",
"new",
"Switch",
"(",
"requiredInt",
"(",
"o",
",",
"\"id\"",
")",
",",
"readCapacity",
"(",
"o",
")",
")",
";",
"}"
] | Convert a JSON switch object to a Switch.
@param o the json object
@return the Switch | [
"Convert",
"a",
"JSON",
"switch",
"object",
"to",
"a",
"Switch",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L233-L235 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.switchesFromJSON | public void switchesFromJSON(Network net, JSONArray a) throws JSONConverterException {
for (Object o : a) {
net.newSwitch(requiredInt((JSONObject) o, "id"), readCapacity((JSONObject) o));
}
} | java | public void switchesFromJSON(Network net, JSONArray a) throws JSONConverterException {
for (Object o : a) {
net.newSwitch(requiredInt((JSONObject) o, "id"), readCapacity((JSONObject) o));
}
} | [
"public",
"void",
"switchesFromJSON",
"(",
"Network",
"net",
",",
"JSONArray",
"a",
")",
"throws",
"JSONConverterException",
"{",
"for",
"(",
"Object",
"o",
":",
"a",
")",
"{",
"net",
".",
"newSwitch",
"(",
"requiredInt",
"(",
"(",
"JSONObject",
")",
"o",
... | Convert a JSON array of switches to a Java List of switches.
@param net the network to populate
@param a the json array | [
"Convert",
"a",
"JSON",
"array",
"of",
"switches",
"to",
"a",
"Java",
"List",
"of",
"switches",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L242-L246 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.physicalElementFromJSON | public PhysicalElement physicalElementFromJSON(Model mo, Network net, JSONObject o) throws JSONConverterException {
String type = requiredString(o, "type");
switch (type) {
case NODE_LABEL:
return requiredNode(mo, o, "id");
case SWITCH_LABEL:
return getSwitch(net, requiredInt(o, "id"));
default:
throw new JSONConverterException("type '" + type + "' is not a physical element");
}
} | java | public PhysicalElement physicalElementFromJSON(Model mo, Network net, JSONObject o) throws JSONConverterException {
String type = requiredString(o, "type");
switch (type) {
case NODE_LABEL:
return requiredNode(mo, o, "id");
case SWITCH_LABEL:
return getSwitch(net, requiredInt(o, "id"));
default:
throw new JSONConverterException("type '" + type + "' is not a physical element");
}
} | [
"public",
"PhysicalElement",
"physicalElementFromJSON",
"(",
"Model",
"mo",
",",
"Network",
"net",
",",
"JSONObject",
"o",
")",
"throws",
"JSONConverterException",
"{",
"String",
"type",
"=",
"requiredString",
"(",
"o",
",",
"\"type\"",
")",
";",
"switch",
"(",
... | Convert a JSON physical element object to a Java PhysicalElement object.
@param o the JSON object to convert the physical element to convert
@return the PhysicalElement | [
"Convert",
"a",
"JSON",
"physical",
"element",
"object",
"to",
"a",
"Java",
"PhysicalElement",
"object",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L262-L272 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.linkFromJSON | public void linkFromJSON(Model mo, Network net, JSONObject o) throws JSONConverterException {
net.connect(requiredInt(o, "id"),
readCapacity(o),
getSwitch(net, requiredInt(o, SWITCH_LABEL)),
physicalElementFromJSON(mo, net, (JSONObject) o.get("physicalElement"))
);
} | java | public void linkFromJSON(Model mo, Network net, JSONObject o) throws JSONConverterException {
net.connect(requiredInt(o, "id"),
readCapacity(o),
getSwitch(net, requiredInt(o, SWITCH_LABEL)),
physicalElementFromJSON(mo, net, (JSONObject) o.get("physicalElement"))
);
} | [
"public",
"void",
"linkFromJSON",
"(",
"Model",
"mo",
",",
"Network",
"net",
",",
"JSONObject",
"o",
")",
"throws",
"JSONConverterException",
"{",
"net",
".",
"connect",
"(",
"requiredInt",
"(",
"o",
",",
"\"id\"",
")",
",",
"readCapacity",
"(",
"o",
")",
... | Convert a JSON link object into a Java Link object.
@param net the network to populate
@param o the JSON object to convert | [
"Convert",
"a",
"JSON",
"link",
"object",
"into",
"a",
"Java",
"Link",
"object",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L288-L294 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java | NetworkConverter.linksFromJSON | public void linksFromJSON(Model mo, Network net, JSONArray a) throws JSONConverterException {
for (Object o : a) {
linkFromJSON(mo, net, (JSONObject) o);
}
} | java | public void linksFromJSON(Model mo, Network net, JSONArray a) throws JSONConverterException {
for (Object o : a) {
linkFromJSON(mo, net, (JSONObject) o);
}
} | [
"public",
"void",
"linksFromJSON",
"(",
"Model",
"mo",
",",
"Network",
"net",
",",
"JSONArray",
"a",
")",
"throws",
"JSONConverterException",
"{",
"for",
"(",
"Object",
"o",
":",
"a",
")",
"{",
"linkFromJSON",
"(",
"mo",
",",
"net",
",",
"(",
"JSONObject... | Convert a JSON array of links to a Java List of links.
@param net the network to populate
@param a the json array | [
"Convert",
"a",
"JSON",
"array",
"of",
"links",
"to",
"a",
"Java",
"List",
"of",
"links",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/NetworkConverter.java#L302-L306 | train |
btrplace/scheduler | examples/src/main/java/org/btrplace/examples/GettingStarted.java | GettingStarted.makeConstraints | public List<SatConstraint> makeConstraints() {
List<SatConstraint> cstrs = new ArrayList<>();
//VM1 and VM2 must be running on distinct nodes
cstrs.add(new Spread(new HashSet<>(Arrays.asList(vms.get(1), vms.get(2)))));
//VM0 must have at least 3 virtual CPU dedicated to it
cstrs.add(new Preserve(vms.get(0), "cpu", 3));
//N3 must be set offline
cstrs.add(new Offline(nodes.get(3)));
//VM4 must be running, It asks for 3 cpu and 2 mem resources
cstrs.add(new Running(vms.get(4)));
cstrs.add(new Preserve(vms.get(4), "cpu", 3));
cstrs.add(new Preserve(vms.get(4), "mem", 2));
//VM3 must be turned off, i.e. set back to the ready state
cstrs.add(new Ready(vms.get(3)));
return cstrs;
} | java | public List<SatConstraint> makeConstraints() {
List<SatConstraint> cstrs = new ArrayList<>();
//VM1 and VM2 must be running on distinct nodes
cstrs.add(new Spread(new HashSet<>(Arrays.asList(vms.get(1), vms.get(2)))));
//VM0 must have at least 3 virtual CPU dedicated to it
cstrs.add(new Preserve(vms.get(0), "cpu", 3));
//N3 must be set offline
cstrs.add(new Offline(nodes.get(3)));
//VM4 must be running, It asks for 3 cpu and 2 mem resources
cstrs.add(new Running(vms.get(4)));
cstrs.add(new Preserve(vms.get(4), "cpu", 3));
cstrs.add(new Preserve(vms.get(4), "mem", 2));
//VM3 must be turned off, i.e. set back to the ready state
cstrs.add(new Ready(vms.get(3)));
return cstrs;
} | [
"public",
"List",
"<",
"SatConstraint",
">",
"makeConstraints",
"(",
")",
"{",
"List",
"<",
"SatConstraint",
">",
"cstrs",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"//VM1 and VM2 must be running on distinct nodes",
"cstrs",
".",
"add",
"(",
"new",
"Spread",... | Declare some constraints. | [
"Declare",
"some",
"constraints",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/examples/src/main/java/org/btrplace/examples/GettingStarted.java#L105-L124 | train |
m-m-m/util | text/src/main/java/net/sf/mmm/util/text/base/DefaultLineWrapper.java | DefaultLineWrapper.verifyWithOfColumns | private boolean verifyWithOfColumns(ColumnState[] columnStates, TextTableInfo tableInfo) {
int tableWidth = tableInfo.getWidth();
if (tableWidth != TextColumnInfo.WIDTH_AUTO_ADJUST) {
int calculatedWidth = 0;
for (ColumnState columnState : columnStates) {
if (columnState.width < 0) {
throw new AssertionError("columnWidth=" + columnState.width);
// return false;
}
calculatedWidth = calculatedWidth + columnState.width + columnState.getColumnInfo().getBorderWidth();
}
if (calculatedWidth != tableWidth) {
throw new AssertionError("with=" + tableWidth + ", sum-of-columns=" + calculatedWidth);
// return false;
}
}
return true;
} | java | private boolean verifyWithOfColumns(ColumnState[] columnStates, TextTableInfo tableInfo) {
int tableWidth = tableInfo.getWidth();
if (tableWidth != TextColumnInfo.WIDTH_AUTO_ADJUST) {
int calculatedWidth = 0;
for (ColumnState columnState : columnStates) {
if (columnState.width < 0) {
throw new AssertionError("columnWidth=" + columnState.width);
// return false;
}
calculatedWidth = calculatedWidth + columnState.width + columnState.getColumnInfo().getBorderWidth();
}
if (calculatedWidth != tableWidth) {
throw new AssertionError("with=" + tableWidth + ", sum-of-columns=" + calculatedWidth);
// return false;
}
}
return true;
} | [
"private",
"boolean",
"verifyWithOfColumns",
"(",
"ColumnState",
"[",
"]",
"columnStates",
",",
"TextTableInfo",
"tableInfo",
")",
"{",
"int",
"tableWidth",
"=",
"tableInfo",
".",
"getWidth",
"(",
")",
";",
"if",
"(",
"tableWidth",
"!=",
"TextColumnInfo",
".",
... | This method verifies that the width of the columns are sane.
@param columnStates are the {@link ColumnState}s.
@param tableInfo is the {@link TextTableInfo}.
@return {@code true} if the width is sane, {@code false} otherwise. | [
"This",
"method",
"verifies",
"that",
"the",
"width",
"of",
"the",
"columns",
"are",
"sane",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/text/src/main/java/net/sf/mmm/util/text/base/DefaultLineWrapper.java#L258-L276 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/Network.java | Network.newSwitch | public Switch newSwitch(int id, int capacity) {
Switch s = swBuilder.newSwitch(id, capacity);
switches.add(s);
return s;
} | java | public Switch newSwitch(int id, int capacity) {
Switch s = swBuilder.newSwitch(id, capacity);
switches.add(s);
return s;
} | [
"public",
"Switch",
"newSwitch",
"(",
"int",
"id",
",",
"int",
"capacity",
")",
"{",
"Switch",
"s",
"=",
"swBuilder",
".",
"newSwitch",
"(",
"id",
",",
"capacity",
")",
";",
"switches",
".",
"add",
"(",
"s",
")",
";",
"return",
"s",
";",
"}"
] | Create a new switch with a specific identifier and a given maximal capacity
@param id the switch identifier
@param capacity the switch maximal capacity (put a nul or negative number for non-blocking switch)
@return the switch | [
"Create",
"a",
"new",
"switch",
"with",
"a",
"specific",
"identifier",
"and",
"a",
"given",
"maximal",
"capacity"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/Network.java#L140-L144 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/Network.java | Network.connect | public List<Link> connect(int bandwidth, Switch sw, Node... nodes) {
List<Link> l = new ArrayList<>();
for (Node n : nodes) {
l.add(connect(bandwidth, sw, n));
}
return l;
} | java | public List<Link> connect(int bandwidth, Switch sw, Node... nodes) {
List<Link> l = new ArrayList<>();
for (Node n : nodes) {
l.add(connect(bandwidth, sw, n));
}
return l;
} | [
"public",
"List",
"<",
"Link",
">",
"connect",
"(",
"int",
"bandwidth",
",",
"Switch",
"sw",
",",
"Node",
"...",
"nodes",
")",
"{",
"List",
"<",
"Link",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Node",
"n",
":",
"nodes"... | Create connections between a single switch and multiple nodes
@param bandwidth the maximal bandwidth for the connection
@param sw the switch to connect
@param nodes a list of nodes to connect
@return a list of links | [
"Create",
"connections",
"between",
"a",
"single",
"switch",
"and",
"multiple",
"nodes"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/Network.java#L236-L242 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/Network.java | Network.getConnectedLinks | public List<Link> getConnectedLinks(PhysicalElement pe) {
List<Link> myLinks = new ArrayList<>();
for (Link l : this.links) {
if (l.getElement().equals(pe)) {
myLinks.add(l);
} else if (l.getSwitch().equals(pe)) {
myLinks.add(l);
}
}
return myLinks;
} | java | public List<Link> getConnectedLinks(PhysicalElement pe) {
List<Link> myLinks = new ArrayList<>();
for (Link l : this.links) {
if (l.getElement().equals(pe)) {
myLinks.add(l);
} else if (l.getSwitch().equals(pe)) {
myLinks.add(l);
}
}
return myLinks;
} | [
"public",
"List",
"<",
"Link",
">",
"getConnectedLinks",
"(",
"PhysicalElement",
"pe",
")",
"{",
"List",
"<",
"Link",
">",
"myLinks",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Link",
"l",
":",
"this",
".",
"links",
")",
"{",
"if",
... | Get the list of links connected to a given physical element
@param pe the physical element
@return the list of links | [
"Get",
"the",
"list",
"of",
"links",
"connected",
"to",
"a",
"given",
"physical",
"element"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/Network.java#L277-L287 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/Network.java | Network.getConnectedNodes | public List<Node> getConnectedNodes() {
List<Node> nodes = new ArrayList<>();
for (Link l : links) {
if (l.getElement() instanceof Node) {
nodes.add((Node) l.getElement());
}
}
return nodes;
} | java | public List<Node> getConnectedNodes() {
List<Node> nodes = new ArrayList<>();
for (Link l : links) {
if (l.getElement() instanceof Node) {
nodes.add((Node) l.getElement());
}
}
return nodes;
} | [
"public",
"List",
"<",
"Node",
">",
"getConnectedNodes",
"(",
")",
"{",
"List",
"<",
"Node",
">",
"nodes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Link",
"l",
":",
"links",
")",
"{",
"if",
"(",
"l",
".",
"getElement",
"(",
")",... | Get the full list of nodes that have been connected into the network
@return the list of nodes | [
"Get",
"the",
"full",
"list",
"of",
"nodes",
"that",
"have",
"been",
"connected",
"into",
"the",
"network"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/Network.java#L294-L302 | train |
protegeproject/jpaul | src/main/java/jpaul/Constraints/SetConstraints/SetConstraints.java | SetConstraints.addInclusion | public void addInclusion(SVar<T> s1, SVar<T> s2) {
this.add(new LtConstraint<SVar<T>,Set<T>>(s1, s2));
} | java | public void addInclusion(SVar<T> s1, SVar<T> s2) {
this.add(new LtConstraint<SVar<T>,Set<T>>(s1, s2));
} | [
"public",
"void",
"addInclusion",
"(",
"SVar",
"<",
"T",
">",
"s1",
",",
"SVar",
"<",
"T",
">",
"s2",
")",
"{",
"this",
".",
"add",
"(",
"new",
"LtConstraint",
"<",
"SVar",
"<",
"T",
">",
",",
"Set",
"<",
"T",
">",
">",
"(",
"s1",
",",
"s2",
... | Adds an inclusion constraints between two sets. | [
"Adds",
"an",
"inclusion",
"constraints",
"between",
"two",
"sets",
"."
] | db579ffb16faaa4b0c577ec82c246f7349427714 | https://github.com/protegeproject/jpaul/blob/db579ffb16faaa4b0c577ec82c246f7349427714/src/main/java/jpaul/Constraints/SetConstraints/SetConstraints.java#L26-L28 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/RandomVMPlacement.java | RandomVMPlacement.randomWithRankedValues | private int randomWithRankedValues(IntVar x) {
TIntArrayList[] values = new TIntArrayList[ranks.length];
DisposableValueIterator ite = x.getValueIterator(true);
try {
while (ite.hasNext()) {
int v = ite.next();
int i;
for (i = 0; i < ranks.length; i++) {
if (ranks[i].contains(v)) {
if (values[i] == null) {
values[i] = new TIntArrayList();
}
values[i].add(v);
}
}
}
} finally {
ite.dispose();
}
//We pick a random value in the first rank that is not empty (aka null here)
for (TIntArrayList rank : values) {
if (rank != null) {
int v = rnd.nextInt(rank.size());
return rank.get(v);
}
}
return -1;
} | java | private int randomWithRankedValues(IntVar x) {
TIntArrayList[] values = new TIntArrayList[ranks.length];
DisposableValueIterator ite = x.getValueIterator(true);
try {
while (ite.hasNext()) {
int v = ite.next();
int i;
for (i = 0; i < ranks.length; i++) {
if (ranks[i].contains(v)) {
if (values[i] == null) {
values[i] = new TIntArrayList();
}
values[i].add(v);
}
}
}
} finally {
ite.dispose();
}
//We pick a random value in the first rank that is not empty (aka null here)
for (TIntArrayList rank : values) {
if (rank != null) {
int v = rnd.nextInt(rank.size());
return rank.get(v);
}
}
return -1;
} | [
"private",
"int",
"randomWithRankedValues",
"(",
"IntVar",
"x",
")",
"{",
"TIntArrayList",
"[",
"]",
"values",
"=",
"new",
"TIntArrayList",
"[",
"ranks",
".",
"length",
"]",
";",
"DisposableValueIterator",
"ite",
"=",
"x",
".",
"getValueIterator",
"(",
"true",... | Random value but that consider the rank of nodes.
So values are picked up from the first rank possible. | [
"Random",
"value",
"but",
"that",
"consider",
"the",
"rank",
"of",
"nodes",
".",
"So",
"values",
"are",
"picked",
"up",
"from",
"the",
"first",
"rank",
"possible",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/RandomVMPlacement.java#L121-L151 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/RandomVMPlacement.java | RandomVMPlacement.randomValue | private int randomValue(IntVar x) {
int i = rnd.nextInt(x.getDomainSize());
DisposableValueIterator ite = x.getValueIterator(true);
int pos = -1;
try {
while (i >= 0) {
pos = ite.next();
i--;
}
} finally {
ite.dispose();
}
return pos;
} | java | private int randomValue(IntVar x) {
int i = rnd.nextInt(x.getDomainSize());
DisposableValueIterator ite = x.getValueIterator(true);
int pos = -1;
try {
while (i >= 0) {
pos = ite.next();
i--;
}
} finally {
ite.dispose();
}
return pos;
} | [
"private",
"int",
"randomValue",
"(",
"IntVar",
"x",
")",
"{",
"int",
"i",
"=",
"rnd",
".",
"nextInt",
"(",
"x",
".",
"getDomainSize",
"(",
")",
")",
";",
"DisposableValueIterator",
"ite",
"=",
"x",
".",
"getValueIterator",
"(",
"true",
")",
";",
"int"... | Pick a random value inside the variable domain. | [
"Pick",
"a",
"random",
"value",
"inside",
"the",
"variable",
"domain",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/RandomVMPlacement.java#L156-L169 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SequiturFactory.java | SequiturFactory.runSequitur | public static SAXRule runSequitur(String inputString) throws Exception {
LOGGER.trace("digesting the string " + inputString);
// clear global collections
//
SAXRule.numRules = new AtomicInteger(0);
SAXRule.theRules.clear();
SAXSymbol.theDigrams.clear();
SAXSymbol.theSubstituteTable.clear();
// init the top-level rule
//
SAXRule resRule = new SAXRule();
// tokenize the input string
//
StringTokenizer st = new StringTokenizer(inputString, " ");
// while there are tokens
int currentPosition = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken();
// System.out.println(" processing the token " + token);
// extract next token
SAXTerminal symbol = new SAXTerminal(token, currentPosition);
// append to the end of the current sequitur string
// ... As each new input symbol is observed, append it to rule S....
resRule.last().insertAfter(symbol);
// once appended, check if the resulting digram is new or recurrent
//
// ... Each time a link is made between two symbols if the new digram is repeated elsewhere
// and the repetitions do not overlap, if the other occurrence is a complete rule,
// replace the new digram with the non-terminal symbol that heads the rule,
// otherwise,form a new rule and replace both digrams with the new non-terminal symbol
// otherwise, insert the digram into the index...
resRule.last().p.check();
currentPosition++;
// LOGGER.debug("Current grammar:\n" + SAXRule.getRules());
}
return resRule;
} | java | public static SAXRule runSequitur(String inputString) throws Exception {
LOGGER.trace("digesting the string " + inputString);
// clear global collections
//
SAXRule.numRules = new AtomicInteger(0);
SAXRule.theRules.clear();
SAXSymbol.theDigrams.clear();
SAXSymbol.theSubstituteTable.clear();
// init the top-level rule
//
SAXRule resRule = new SAXRule();
// tokenize the input string
//
StringTokenizer st = new StringTokenizer(inputString, " ");
// while there are tokens
int currentPosition = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken();
// System.out.println(" processing the token " + token);
// extract next token
SAXTerminal symbol = new SAXTerminal(token, currentPosition);
// append to the end of the current sequitur string
// ... As each new input symbol is observed, append it to rule S....
resRule.last().insertAfter(symbol);
// once appended, check if the resulting digram is new or recurrent
//
// ... Each time a link is made between two symbols if the new digram is repeated elsewhere
// and the repetitions do not overlap, if the other occurrence is a complete rule,
// replace the new digram with the non-terminal symbol that heads the rule,
// otherwise,form a new rule and replace both digrams with the new non-terminal symbol
// otherwise, insert the digram into the index...
resRule.last().p.check();
currentPosition++;
// LOGGER.debug("Current grammar:\n" + SAXRule.getRules());
}
return resRule;
} | [
"public",
"static",
"SAXRule",
"runSequitur",
"(",
"String",
"inputString",
")",
"throws",
"Exception",
"{",
"LOGGER",
".",
"trace",
"(",
"\"digesting the string \"",
"+",
"inputString",
")",
";",
"// clear global collections",
"//",
"SAXRule",
".",
"numRules",
"=",... | Digests a string of terminals separated by a space.
@param inputString the string to digest.
@return The top rule handler (i.e. R0).
@throws Exception if error occurs. | [
"Digests",
"a",
"string",
"of",
"terminals",
"separated",
"by",
"a",
"space",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SequiturFactory.java#L49-L97 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SequiturFactory.java | SequiturFactory.series2SequiturRules | public static GrammarRules series2SequiturRules(double[] timeseries, int saxWindowSize,
int saxPAASize, int saxAlphabetSize, NumerosityReductionStrategy numerosityReductionStrategy,
double normalizationThreshold) throws Exception, IOException {
LOGGER.debug("Discretizing time series...");
SAXRecords saxFrequencyData = sp.ts2saxViaWindow(timeseries, saxWindowSize, saxPAASize,
normalA.getCuts(saxAlphabetSize), numerosityReductionStrategy, normalizationThreshold);
LOGGER.debug("Inferring the grammar...");
// this is a string we are about to feed into Sequitur
//
String saxDisplayString = saxFrequencyData.getSAXString(" ");
// reset the Sequitur data structures
SAXRule.numRules = new AtomicInteger(0);
SAXRule.theRules.clear();
SAXSymbol.theDigrams.clear();
// bootstrap the grammar
SAXRule grammar = new SAXRule();
SAXRule.arrRuleRecords = new ArrayList<GrammarRuleRecord>();
// digest the string via the tokenizer and build the grammar
StringTokenizer st = new StringTokenizer(saxDisplayString, " ");
int currentPosition = 0;
while (st.hasMoreTokens()) {
grammar.last().insertAfter(new SAXTerminal(st.nextToken(), currentPosition));
grammar.last().p.check();
currentPosition++;
}
// bw.close();
LOGGER.debug("Collecting the grammar rules statistics and expanding the rules...");
GrammarRules rules = grammar.toGrammarRulesData();
LOGGER.debug("Mapping expanded rules to time-series intervals...");
SequiturFactory.updateRuleIntervals(rules, saxFrequencyData, true, timeseries, saxWindowSize,
saxPAASize);
return rules;
} | java | public static GrammarRules series2SequiturRules(double[] timeseries, int saxWindowSize,
int saxPAASize, int saxAlphabetSize, NumerosityReductionStrategy numerosityReductionStrategy,
double normalizationThreshold) throws Exception, IOException {
LOGGER.debug("Discretizing time series...");
SAXRecords saxFrequencyData = sp.ts2saxViaWindow(timeseries, saxWindowSize, saxPAASize,
normalA.getCuts(saxAlphabetSize), numerosityReductionStrategy, normalizationThreshold);
LOGGER.debug("Inferring the grammar...");
// this is a string we are about to feed into Sequitur
//
String saxDisplayString = saxFrequencyData.getSAXString(" ");
// reset the Sequitur data structures
SAXRule.numRules = new AtomicInteger(0);
SAXRule.theRules.clear();
SAXSymbol.theDigrams.clear();
// bootstrap the grammar
SAXRule grammar = new SAXRule();
SAXRule.arrRuleRecords = new ArrayList<GrammarRuleRecord>();
// digest the string via the tokenizer and build the grammar
StringTokenizer st = new StringTokenizer(saxDisplayString, " ");
int currentPosition = 0;
while (st.hasMoreTokens()) {
grammar.last().insertAfter(new SAXTerminal(st.nextToken(), currentPosition));
grammar.last().p.check();
currentPosition++;
}
// bw.close();
LOGGER.debug("Collecting the grammar rules statistics and expanding the rules...");
GrammarRules rules = grammar.toGrammarRulesData();
LOGGER.debug("Mapping expanded rules to time-series intervals...");
SequiturFactory.updateRuleIntervals(rules, saxFrequencyData, true, timeseries, saxWindowSize,
saxPAASize);
return rules;
} | [
"public",
"static",
"GrammarRules",
"series2SequiturRules",
"(",
"double",
"[",
"]",
"timeseries",
",",
"int",
"saxWindowSize",
",",
"int",
"saxPAASize",
",",
"int",
"saxAlphabetSize",
",",
"NumerosityReductionStrategy",
"numerosityReductionStrategy",
",",
"double",
"no... | Takes a time series and returns a grammar.
@param timeseries the input time series.
@param saxWindowSize the sliding window size.
@param saxPAASize the PAA num.
@param saxAlphabetSize the SAX alphabet size.
@param numerosityReductionStrategy the SAX Numerosity Reduction strategy.
@param normalizationThreshold the SAX normalization threshod.
@return the set of rules, i.e. the grammar.
@throws Exception if error occurs.
@throws IOException if error occurs. | [
"Takes",
"a",
"time",
"series",
"and",
"returns",
"a",
"grammar",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SequiturFactory.java#L112-L155 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SequiturFactory.java | SequiturFactory.getRulePositionsByRuleNum | public static ArrayList<RuleInterval> getRulePositionsByRuleNum(int ruleIdx, SAXRule grammar,
SAXRecords saxFrequencyData, double[] originalTimeSeries, int saxWindowSize) {
// this will be the result
ArrayList<RuleInterval> resultIntervals = new ArrayList<RuleInterval>();
// the rule container
GrammarRuleRecord ruleContainer = grammar.getRuleRecords().get(ruleIdx);
// the original indexes of all SAX words
ArrayList<Integer> saxWordsIndexes = new ArrayList<Integer>(saxFrequencyData.getAllIndices());
// debug printout
LOGGER.trace("Expanded rule: \"" + ruleContainer.getExpandedRuleString() + '\"');
LOGGER.trace("Indexes: " + ruleContainer.getOccurrences());
// array of all words of this expanded rule
String[] expandedRuleSplit = ruleContainer.getExpandedRuleString().trim().split(" ");
for (Integer currentIndex : ruleContainer.getOccurrences()) {
String extractedStr = "";
StringBuffer sb = new StringBuffer(expandedRuleSplit.length);
for (int i = 0; i < expandedRuleSplit.length; i++) {
LOGGER.trace("currentIndex " + currentIndex + ", i: " + i);
extractedStr = extractedStr.concat(" ").concat(String.valueOf(
saxFrequencyData.getByIndex(saxWordsIndexes.get(currentIndex + i)).getPayload()));
sb.append(saxWordsIndexes.get(currentIndex + i)).append(" ");
}
LOGGER.trace("Recovered string: " + extractedStr);
LOGGER.trace("Recovered positions: " + sb.toString());
int start = saxWordsIndexes.get(currentIndex);
int end = -1;
// need to care about bouncing beyond the all SAX words index array
if ((currentIndex + expandedRuleSplit.length) >= saxWordsIndexes.size()) {
// if we at the last index - then it's easy - end is the timeseries end
end = originalTimeSeries.length - 1;
}
else {
// if we OK with indexes, the Rule subsequence end is the start of the very next SAX word
// after the kast in this expanded rule
end = saxWordsIndexes.get(currentIndex + expandedRuleSplit.length) - 1 + saxWindowSize;
}
// save it
resultIntervals.add(new RuleInterval(start, end));
}
return resultIntervals;
} | java | public static ArrayList<RuleInterval> getRulePositionsByRuleNum(int ruleIdx, SAXRule grammar,
SAXRecords saxFrequencyData, double[] originalTimeSeries, int saxWindowSize) {
// this will be the result
ArrayList<RuleInterval> resultIntervals = new ArrayList<RuleInterval>();
// the rule container
GrammarRuleRecord ruleContainer = grammar.getRuleRecords().get(ruleIdx);
// the original indexes of all SAX words
ArrayList<Integer> saxWordsIndexes = new ArrayList<Integer>(saxFrequencyData.getAllIndices());
// debug printout
LOGGER.trace("Expanded rule: \"" + ruleContainer.getExpandedRuleString() + '\"');
LOGGER.trace("Indexes: " + ruleContainer.getOccurrences());
// array of all words of this expanded rule
String[] expandedRuleSplit = ruleContainer.getExpandedRuleString().trim().split(" ");
for (Integer currentIndex : ruleContainer.getOccurrences()) {
String extractedStr = "";
StringBuffer sb = new StringBuffer(expandedRuleSplit.length);
for (int i = 0; i < expandedRuleSplit.length; i++) {
LOGGER.trace("currentIndex " + currentIndex + ", i: " + i);
extractedStr = extractedStr.concat(" ").concat(String.valueOf(
saxFrequencyData.getByIndex(saxWordsIndexes.get(currentIndex + i)).getPayload()));
sb.append(saxWordsIndexes.get(currentIndex + i)).append(" ");
}
LOGGER.trace("Recovered string: " + extractedStr);
LOGGER.trace("Recovered positions: " + sb.toString());
int start = saxWordsIndexes.get(currentIndex);
int end = -1;
// need to care about bouncing beyond the all SAX words index array
if ((currentIndex + expandedRuleSplit.length) >= saxWordsIndexes.size()) {
// if we at the last index - then it's easy - end is the timeseries end
end = originalTimeSeries.length - 1;
}
else {
// if we OK with indexes, the Rule subsequence end is the start of the very next SAX word
// after the kast in this expanded rule
end = saxWordsIndexes.get(currentIndex + expandedRuleSplit.length) - 1 + saxWindowSize;
}
// save it
resultIntervals.add(new RuleInterval(start, end));
}
return resultIntervals;
} | [
"public",
"static",
"ArrayList",
"<",
"RuleInterval",
">",
"getRulePositionsByRuleNum",
"(",
"int",
"ruleIdx",
",",
"SAXRule",
"grammar",
",",
"SAXRecords",
"saxFrequencyData",
",",
"double",
"[",
"]",
"originalTimeSeries",
",",
"int",
"saxWindowSize",
")",
"{",
"... | Recovers start and stop coordinates of a rule subsequences.
@param ruleIdx The rule index.
@param grammar The grammar to analyze.
@param saxFrequencyData the SAX frquency data used for the grammar construction.
@param originalTimeSeries the original time series.
@param saxWindowSize the SAX sliding window size.
@return The array of all intervals corresponding to this rule. | [
"Recovers",
"start",
"and",
"stop",
"coordinates",
"of",
"a",
"rule",
"subsequences",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SequiturFactory.java#L236-L285 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/constraint/Preserve.java | Preserve.newPreserve | public static List<Preserve> newPreserve(Collection<VM> vms, String r, int q) {
return vms.stream().map(v -> new Preserve(v, r, q)).collect(Collectors.toList());
} | java | public static List<Preserve> newPreserve(Collection<VM> vms, String r, int q) {
return vms.stream().map(v -> new Preserve(v, r, q)).collect(Collectors.toList());
} | [
"public",
"static",
"List",
"<",
"Preserve",
">",
"newPreserve",
"(",
"Collection",
"<",
"VM",
">",
"vms",
",",
"String",
"r",
",",
"int",
"q",
")",
"{",
"return",
"vms",
".",
"stream",
"(",
")",
".",
"map",
"(",
"v",
"->",
"new",
"Preserve",
"(",
... | Make multiple constraints
@param vms the VMs involved in the constraints
@param r the resource identifier
@param q the the minimum amount of resources to allocate to each VM. >= 0
@return a list of constraints | [
"Make",
"multiple",
"constraints"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/constraint/Preserve.java#L133-L135 | train |
protegeproject/jpaul | src/main/java/jpaul/DataStructs/UnionFind.java | UnionFind._link | private Node<E> _link(Node<E> node1, Node<E> node2) {
// maybe there is no real unification here
if(node1 == node2) return node2;
// from now on, we know that we unify really disjoint trees
if(node1.rank > node2.rank) {
node2.parent = node1;
node1.nbElems += node2.nbElems;
return node1;
}
else {
node1.parent = node2;
if (node1.rank == node2.rank) {
node2.rank++;
}
node2.nbElems += node1.nbElems;
return node2;
}
} | java | private Node<E> _link(Node<E> node1, Node<E> node2) {
// maybe there is no real unification here
if(node1 == node2) return node2;
// from now on, we know that we unify really disjoint trees
if(node1.rank > node2.rank) {
node2.parent = node1;
node1.nbElems += node2.nbElems;
return node1;
}
else {
node1.parent = node2;
if (node1.rank == node2.rank) {
node2.rank++;
}
node2.nbElems += node1.nbElems;
return node2;
}
} | [
"private",
"Node",
"<",
"E",
">",
"_link",
"(",
"Node",
"<",
"E",
">",
"node1",
",",
"Node",
"<",
"E",
">",
"node2",
")",
"{",
"// maybe there is no real unification here",
"if",
"(",
"node1",
"==",
"node2",
")",
"return",
"node2",
";",
"// from now on, we... | Unifies the tree rooted in node1 with the tree rooted in
node2, by making one of them the subtree of the other one;
returns the root of the new tree. | [
"Unifies",
"the",
"tree",
"rooted",
"in",
"node1",
"with",
"the",
"tree",
"rooted",
"in",
"node2",
"by",
"making",
"one",
"of",
"them",
"the",
"subtree",
"of",
"the",
"other",
"one",
";",
"returns",
"the",
"root",
"of",
"the",
"new",
"tree",
"."
] | db579ffb16faaa4b0c577ec82c246f7349427714 | https://github.com/protegeproject/jpaul/blob/db579ffb16faaa4b0c577ec82c246f7349427714/src/main/java/jpaul/DataStructs/UnionFind.java#L125-L142 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SAXRule.java | SAXRule.reset | public static void reset() {
SAXRule.numRules = new AtomicInteger(0);
SAXSymbol.theDigrams.clear();
SAXSymbol.theSubstituteTable.clear();
SAXRule.arrRuleRecords = new ArrayList<GrammarRuleRecord>();
} | java | public static void reset() {
SAXRule.numRules = new AtomicInteger(0);
SAXSymbol.theDigrams.clear();
SAXSymbol.theSubstituteTable.clear();
SAXRule.arrRuleRecords = new ArrayList<GrammarRuleRecord>();
} | [
"public",
"static",
"void",
"reset",
"(",
")",
"{",
"SAXRule",
".",
"numRules",
"=",
"new",
"AtomicInteger",
"(",
"0",
")",
";",
"SAXSymbol",
".",
"theDigrams",
".",
"clear",
"(",
")",
";",
"SAXSymbol",
".",
"theSubstituteTable",
".",
"clear",
"(",
")",
... | Cleans up data structures. | [
"Cleans",
"up",
"data",
"structures",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SAXRule.java#L190-L195 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SAXRule.java | SAXRule.assignLevel | protected void assignLevel() {
int lvl = Integer.MAX_VALUE;
SAXSymbol sym;
for (sym = this.first(); (!sym.isGuard()); sym = sym.n) {
if (sym.isNonTerminal()) {
SAXRule referedTo = ((SAXNonTerminal) sym).r;
lvl = Math.min(referedTo.level + 1, lvl);
}
else {
level = 1;
return;
}
}
level = lvl;
} | java | protected void assignLevel() {
int lvl = Integer.MAX_VALUE;
SAXSymbol sym;
for (sym = this.first(); (!sym.isGuard()); sym = sym.n) {
if (sym.isNonTerminal()) {
SAXRule referedTo = ((SAXNonTerminal) sym).r;
lvl = Math.min(referedTo.level + 1, lvl);
}
else {
level = 1;
return;
}
}
level = lvl;
} | [
"protected",
"void",
"assignLevel",
"(",
")",
"{",
"int",
"lvl",
"=",
"Integer",
".",
"MAX_VALUE",
";",
"SAXSymbol",
"sym",
";",
"for",
"(",
"sym",
"=",
"this",
".",
"first",
"(",
")",
";",
"(",
"!",
"sym",
".",
"isGuard",
"(",
")",
")",
";",
"sy... | This traces the rule level. | [
"This",
"traces",
"the",
"rule",
"level",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SAXRule.java#L265-L285 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SAXRule.java | SAXRule.expandRules | private static void expandRules() {
// long start = System.currentTimeMillis();
// iterate over all SAX containers
// ArrayList<SAXMapEntry<Integer, Integer>> recs = new ArrayList<SAXMapEntry<Integer, Integer>>(
// arrRuleRecords.size());
//
// for (GrammarRuleRecord ruleRecord : arrRuleRecords) {
// recs.add(new SAXMapEntry<Integer, Integer>(ruleRecord.getRuleLevel(), ruleRecord
// .getRuleNumber()));
// }
//
// Collections.sort(recs, new Comparator<SAXMapEntry<Integer, Integer>>() {
// @Override
// public int compare(SAXMapEntry<Integer, Integer> o1, SAXMapEntry<Integer, Integer> o2) {
// return o1.getKey().compareTo(o2.getKey());
// }
// });
// for (SAXMapEntry<Integer, Integer> entry : recs) {
for (GrammarRuleRecord ruleRecord : arrRuleRecords) {
if (ruleRecord.getRuleNumber() == 0) {
continue;
}
String curString = ruleRecord.getRuleString();
StringBuilder resultString = new StringBuilder(8192);
String[] split = curString.split(" ");
for (String s : split) {
if (s.startsWith("R")) {
resultString.append(" ").append(expandRule(Integer.valueOf(s.substring(1, s.length()))));
}
else {
resultString.append(" ").append(s);
}
}
// need to trim space at the very end
String rr = resultString.delete(0, 1).append(" ").toString();
ruleRecord.setExpandedRuleString(rr);
ruleRecord.setRuleYield(countSpaces(rr));
}
StringBuilder resultString = new StringBuilder(8192);
GrammarRuleRecord ruleRecord = arrRuleRecords.get(0);
resultString.append(ruleRecord.getRuleString());
int currentSearchStart = resultString.indexOf("R");
while (currentSearchStart >= 0) {
int spaceIdx = resultString.indexOf(" ", currentSearchStart);
String ruleName = resultString.substring(currentSearchStart, spaceIdx + 1);
Integer ruleId = Integer.valueOf(ruleName.substring(1, ruleName.length() - 1));
resultString.replace(spaceIdx - ruleName.length() + 1, spaceIdx + 1,
arrRuleRecords.get(ruleId).getExpandedRuleString());
currentSearchStart = resultString.indexOf("R");
}
ruleRecord.setExpandedRuleString(resultString.toString().trim());
// ruleRecord.setRuleYield(countSpaces(resultString));
// long end = System.currentTimeMillis();
// System.out.println("Rules expanded in " + SAXFactory.timeToString(start, end));
} | java | private static void expandRules() {
// long start = System.currentTimeMillis();
// iterate over all SAX containers
// ArrayList<SAXMapEntry<Integer, Integer>> recs = new ArrayList<SAXMapEntry<Integer, Integer>>(
// arrRuleRecords.size());
//
// for (GrammarRuleRecord ruleRecord : arrRuleRecords) {
// recs.add(new SAXMapEntry<Integer, Integer>(ruleRecord.getRuleLevel(), ruleRecord
// .getRuleNumber()));
// }
//
// Collections.sort(recs, new Comparator<SAXMapEntry<Integer, Integer>>() {
// @Override
// public int compare(SAXMapEntry<Integer, Integer> o1, SAXMapEntry<Integer, Integer> o2) {
// return o1.getKey().compareTo(o2.getKey());
// }
// });
// for (SAXMapEntry<Integer, Integer> entry : recs) {
for (GrammarRuleRecord ruleRecord : arrRuleRecords) {
if (ruleRecord.getRuleNumber() == 0) {
continue;
}
String curString = ruleRecord.getRuleString();
StringBuilder resultString = new StringBuilder(8192);
String[] split = curString.split(" ");
for (String s : split) {
if (s.startsWith("R")) {
resultString.append(" ").append(expandRule(Integer.valueOf(s.substring(1, s.length()))));
}
else {
resultString.append(" ").append(s);
}
}
// need to trim space at the very end
String rr = resultString.delete(0, 1).append(" ").toString();
ruleRecord.setExpandedRuleString(rr);
ruleRecord.setRuleYield(countSpaces(rr));
}
StringBuilder resultString = new StringBuilder(8192);
GrammarRuleRecord ruleRecord = arrRuleRecords.get(0);
resultString.append(ruleRecord.getRuleString());
int currentSearchStart = resultString.indexOf("R");
while (currentSearchStart >= 0) {
int spaceIdx = resultString.indexOf(" ", currentSearchStart);
String ruleName = resultString.substring(currentSearchStart, spaceIdx + 1);
Integer ruleId = Integer.valueOf(ruleName.substring(1, ruleName.length() - 1));
resultString.replace(spaceIdx - ruleName.length() + 1, spaceIdx + 1,
arrRuleRecords.get(ruleId).getExpandedRuleString());
currentSearchStart = resultString.indexOf("R");
}
ruleRecord.setExpandedRuleString(resultString.toString().trim());
// ruleRecord.setRuleYield(countSpaces(resultString));
// long end = System.currentTimeMillis();
// System.out.println("Rules expanded in " + SAXFactory.timeToString(start, end));
} | [
"private",
"static",
"void",
"expandRules",
"(",
")",
"{",
"// long start = System.currentTimeMillis();\r",
"// iterate over all SAX containers\r",
"// ArrayList<SAXMapEntry<Integer, Integer>> recs = new ArrayList<SAXMapEntry<Integer, Integer>>(\r",
"// arrRuleRecords.size());\r",
"//\r",
"/... | Manfred's cool trick to get out all expanded rules. Expands the rule of each SAX container into
SAX words string. Can be rewritten recursively though. | [
"Manfred",
"s",
"cool",
"trick",
"to",
"get",
"out",
"all",
"expanded",
"rules",
".",
"Expands",
"the",
"rule",
"of",
"each",
"SAX",
"container",
"into",
"SAX",
"words",
"string",
".",
"Can",
"be",
"rewritten",
"recursively",
"though",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SAXRule.java#L295-L362 | train |
jMotif/GI | src/main/java/net/seninp/gi/sequitur/SAXRule.java | SAXRule.getIndexes | private int[] getIndexes() {
int[] res = new int[this.indexes.size()];
int i = 0;
for (Integer idx : this.indexes) {
res[i] = idx;
i++;
}
return res;
} | java | private int[] getIndexes() {
int[] res = new int[this.indexes.size()];
int i = 0;
for (Integer idx : this.indexes) {
res[i] = idx;
i++;
}
return res;
} | [
"private",
"int",
"[",
"]",
"getIndexes",
"(",
")",
"{",
"int",
"[",
"]",
"res",
"=",
"new",
"int",
"[",
"this",
".",
"indexes",
".",
"size",
"(",
")",
"]",
";",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"Integer",
"idx",
":",
"this",
".",
"inde... | Get all the rule occurrences.
@return all the rule occurrences. | [
"Get",
"all",
"the",
"rule",
"occurrences",
"."
] | 381212dd4f193246a6df82bd46f0d2bcd04a68d6 | https://github.com/jMotif/GI/blob/381212dd4f193246a6df82bd46f0d2bcd04a68d6/src/main/java/net/seninp/gi/sequitur/SAXRule.java#L421-L429 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/plan/ActionConverter.java | ActionConverter.fromJSON | public Action fromJSON(JSONObject in) throws JSONConverterException {
String id = requiredString(in, ACTION_ID_LABEL);
Action a;
switch (id) {
case "bootVM":
a = bootVMFromJSON(in);
break;
case "shutdownVM":
a = shutdownVMFromJSON(in);
break;
case "shutdownNode":
a = shutdownNodeFromJSON(in);
break;
case "bootNode":
a = bootNodeFromJSON(in);
break;
case "forgeVM":
a = forgeVMFromJSON(in);
break;
case "killVM":
a = killVMFromJSON(in);
break;
case "migrateVM":
a = migrateVMFromJSON(in);
break;
case "resumeVM":
a = resumeVMFromJSON(in);
break;
case "suspendVM":
a = suspendVMFromJSON(in);
break;
case RC_ALLOCATE_LABEL:
a = allocateFromJSON(in);
break;
default:
throw new JSONConverterException("Unsupported action '" + id + "'");
}
attachEvents(a, in);
return a;
} | java | public Action fromJSON(JSONObject in) throws JSONConverterException {
String id = requiredString(in, ACTION_ID_LABEL);
Action a;
switch (id) {
case "bootVM":
a = bootVMFromJSON(in);
break;
case "shutdownVM":
a = shutdownVMFromJSON(in);
break;
case "shutdownNode":
a = shutdownNodeFromJSON(in);
break;
case "bootNode":
a = bootNodeFromJSON(in);
break;
case "forgeVM":
a = forgeVMFromJSON(in);
break;
case "killVM":
a = killVMFromJSON(in);
break;
case "migrateVM":
a = migrateVMFromJSON(in);
break;
case "resumeVM":
a = resumeVMFromJSON(in);
break;
case "suspendVM":
a = suspendVMFromJSON(in);
break;
case RC_ALLOCATE_LABEL:
a = allocateFromJSON(in);
break;
default:
throw new JSONConverterException("Unsupported action '" + id + "'");
}
attachEvents(a, in);
return a;
} | [
"public",
"Action",
"fromJSON",
"(",
"JSONObject",
"in",
")",
"throws",
"JSONConverterException",
"{",
"String",
"id",
"=",
"requiredString",
"(",
"in",
",",
"ACTION_ID_LABEL",
")",
";",
"Action",
"a",
";",
"switch",
"(",
"id",
")",
"{",
"case",
"\"bootVM\""... | decode a json-encoded action.
@param in the action to decode
@return the resulting action
@throws JSONConverterException if the conversion failed | [
"decode",
"a",
"json",
"-",
"encoded",
"action",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/plan/ActionConverter.java#L113-L154 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/plan/ActionConverter.java | ActionConverter.attachEvents | private void attachEvents(Action a, JSONObject in) throws JSONConverterException {
if (in.containsKey(HOOK_LABEL)) {
JSONObject hooks = (JSONObject) in.get(HOOK_LABEL);
for (Map.Entry<String, Object> e : hooks.entrySet()) {
String k = e.getKey();
try {
Action.Hook h = Action.Hook.valueOf(k.toUpperCase());
for (Object o : (JSONArray) e.getValue()) {
a.addEvent(h, eventFromJSON((JSONObject) o));
}
} catch (IllegalArgumentException ex) {
throw new JSONConverterException("Unsupported hook type '" + k + "'", ex);
}
}
}
} | java | private void attachEvents(Action a, JSONObject in) throws JSONConverterException {
if (in.containsKey(HOOK_LABEL)) {
JSONObject hooks = (JSONObject) in.get(HOOK_LABEL);
for (Map.Entry<String, Object> e : hooks.entrySet()) {
String k = e.getKey();
try {
Action.Hook h = Action.Hook.valueOf(k.toUpperCase());
for (Object o : (JSONArray) e.getValue()) {
a.addEvent(h, eventFromJSON((JSONObject) o));
}
} catch (IllegalArgumentException ex) {
throw new JSONConverterException("Unsupported hook type '" + k + "'", ex);
}
}
}
} | [
"private",
"void",
"attachEvents",
"(",
"Action",
"a",
",",
"JSONObject",
"in",
")",
"throws",
"JSONConverterException",
"{",
"if",
"(",
"in",
".",
"containsKey",
"(",
"HOOK_LABEL",
")",
")",
"{",
"JSONObject",
"hooks",
"=",
"(",
"JSONObject",
")",
"in",
"... | Decorate the action with optional events.
@param a the action to decorate
@param in the JSON message containing the event at the "hook" key
@throws JSONConverterException in case of error | [
"Decorate",
"the",
"action",
"with",
"optional",
"events",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/plan/ActionConverter.java#L163-L178 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/plan/ActionConverter.java | ActionConverter.makeActionSkeleton | private JSONObject makeActionSkeleton(Action a) {
JSONObject o = new JSONObject();
o.put(START_LABEL, a.getStart());
o.put(END_LABEL, a.getEnd());
JSONObject hooks = new JSONObject();
for (Action.Hook k : Action.Hook.values()) {
JSONArray arr = new JSONArray();
for (Event e : a.getEvents(k)) {
arr.add(toJSON(e));
}
hooks.put(k.toString(), arr);
}
o.put(HOOK_LABEL, hooks);
return o;
} | java | private JSONObject makeActionSkeleton(Action a) {
JSONObject o = new JSONObject();
o.put(START_LABEL, a.getStart());
o.put(END_LABEL, a.getEnd());
JSONObject hooks = new JSONObject();
for (Action.Hook k : Action.Hook.values()) {
JSONArray arr = new JSONArray();
for (Event e : a.getEvents(k)) {
arr.add(toJSON(e));
}
hooks.put(k.toString(), arr);
}
o.put(HOOK_LABEL, hooks);
return o;
} | [
"private",
"JSONObject",
"makeActionSkeleton",
"(",
"Action",
"a",
")",
"{",
"JSONObject",
"o",
"=",
"new",
"JSONObject",
"(",
")",
";",
"o",
".",
"put",
"(",
"START_LABEL",
",",
"a",
".",
"getStart",
"(",
")",
")",
";",
"o",
".",
"put",
"(",
"END_LA... | Just create the JSONObject and set the consume and the end attribute.
@param a the action to convert
@return a skeleton JSONObject | [
"Just",
"create",
"the",
"JSONObject",
"and",
"set",
"the",
"consume",
"and",
"the",
"end",
"attribute",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/plan/ActionConverter.java#L410-L424 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/plan/ActionConverter.java | ActionConverter.listFromJSON | public List<Action> listFromJSON(JSONArray in) throws JSONConverterException {
List<Action> l = new ArrayList<>(in.size());
for (Object o : in) {
if (!(o instanceof JSONObject)) {
throw new JSONConverterException("Expected an array of JSONObject but got an array of " + o.getClass().getName());
}
l.add(fromJSON((JSONObject) o));
}
return l;
} | java | public List<Action> listFromJSON(JSONArray in) throws JSONConverterException {
List<Action> l = new ArrayList<>(in.size());
for (Object o : in) {
if (!(o instanceof JSONObject)) {
throw new JSONConverterException("Expected an array of JSONObject but got an array of " + o.getClass().getName());
}
l.add(fromJSON((JSONObject) o));
}
return l;
} | [
"public",
"List",
"<",
"Action",
">",
"listFromJSON",
"(",
"JSONArray",
"in",
")",
"throws",
"JSONConverterException",
"{",
"List",
"<",
"Action",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
"in",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Object"... | Convert a list of json-encoded actions.
@param in the list to decode
@return the action list. Might be empty
@throws JSONConverterException if the conversion failed | [
"Convert",
"a",
"list",
"of",
"json",
"-",
"encoded",
"actions",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/plan/ActionConverter.java#L437-L446 | train |
mapcode-foundation/mapcode-java | src/main/java/com/mapcode/Decoder.java | Decoder.decodeUTF16 | @Nonnull
static String decodeUTF16(@Nonnull final String mapcode) {
String result;
final StringBuilder asciiBuf = new StringBuilder();
for (final char ch : mapcode.toCharArray()) {
if (ch == '.') {
asciiBuf.append(ch);
} else if ((ch >= 1) && (ch <= 'z')) {
// normal ascii
asciiBuf.append(ch);
} else {
boolean found = false;
for (final Unicode2Ascii unicode2Ascii : UNICODE2ASCII) {
if ((ch >= unicode2Ascii.min) && (ch <= unicode2Ascii.max)) {
final int pos = ((int) ch) - (int) unicode2Ascii.min;
asciiBuf.append(unicode2Ascii.convert.charAt(pos));
found = true;
break;
}
}
if (!found) {
asciiBuf.append('?');
break;
}
}
}
result = asciiBuf.toString();
// Repack if this was a Greek 'alpha' code. This will have been converted to a regular 'A' after one iteration.
if (mapcode.startsWith(String.valueOf(GREEK_CAPITAL_ALPHA))) {
final String unpacked = aeuUnpack(result);
if (unpacked.isEmpty()) {
throw new AssertionError("decodeUTF16: cannot decode " + mapcode);
}
result = Encoder.aeuPack(unpacked, false);
}
if (isAbjadScript(mapcode)) {
return convertFromAbjad(result);
} else {
return result;
}
} | java | @Nonnull
static String decodeUTF16(@Nonnull final String mapcode) {
String result;
final StringBuilder asciiBuf = new StringBuilder();
for (final char ch : mapcode.toCharArray()) {
if (ch == '.') {
asciiBuf.append(ch);
} else if ((ch >= 1) && (ch <= 'z')) {
// normal ascii
asciiBuf.append(ch);
} else {
boolean found = false;
for (final Unicode2Ascii unicode2Ascii : UNICODE2ASCII) {
if ((ch >= unicode2Ascii.min) && (ch <= unicode2Ascii.max)) {
final int pos = ((int) ch) - (int) unicode2Ascii.min;
asciiBuf.append(unicode2Ascii.convert.charAt(pos));
found = true;
break;
}
}
if (!found) {
asciiBuf.append('?');
break;
}
}
}
result = asciiBuf.toString();
// Repack if this was a Greek 'alpha' code. This will have been converted to a regular 'A' after one iteration.
if (mapcode.startsWith(String.valueOf(GREEK_CAPITAL_ALPHA))) {
final String unpacked = aeuUnpack(result);
if (unpacked.isEmpty()) {
throw new AssertionError("decodeUTF16: cannot decode " + mapcode);
}
result = Encoder.aeuPack(unpacked, false);
}
if (isAbjadScript(mapcode)) {
return convertFromAbjad(result);
} else {
return result;
}
} | [
"@",
"Nonnull",
"static",
"String",
"decodeUTF16",
"(",
"@",
"Nonnull",
"final",
"String",
"mapcode",
")",
"{",
"String",
"result",
";",
"final",
"StringBuilder",
"asciiBuf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"final",
"char",
"ch",
":... | This method decodes a Unicode string to ASCII. Package private for access by other modules.
@param mapcode Unicode string.
@return ASCII string. | [
"This",
"method",
"decodes",
"a",
"Unicode",
"string",
"to",
"ASCII",
".",
"Package",
"private",
"for",
"access",
"by",
"other",
"modules",
"."
] | f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8 | https://github.com/mapcode-foundation/mapcode-java/blob/f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8/src/main/java/com/mapcode/Decoder.java#L699-L741 | train |
mapcode-foundation/mapcode-java | src/main/java/com/mapcode/Decoder.java | Decoder.decodeBase31 | private static int decodeBase31(@Nonnull final String code) {
int value = 0;
for (final char c : code.toCharArray()) {
if (c == '.') {
return value;
}
if (DECODE_CHARS[c] < 0) {
return -1;
}
value = (value * 31) + DECODE_CHARS[c];
}
return value;
} | java | private static int decodeBase31(@Nonnull final String code) {
int value = 0;
for (final char c : code.toCharArray()) {
if (c == '.') {
return value;
}
if (DECODE_CHARS[c] < 0) {
return -1;
}
value = (value * 31) + DECODE_CHARS[c];
}
return value;
} | [
"private",
"static",
"int",
"decodeBase31",
"(",
"@",
"Nonnull",
"final",
"String",
"code",
")",
"{",
"int",
"value",
"=",
"0",
";",
"for",
"(",
"final",
"char",
"c",
":",
"code",
".",
"toCharArray",
"(",
")",
")",
"{",
"if",
"(",
"c",
"==",
"'",
... | returns negative in case of error | [
"returns",
"negative",
"in",
"case",
"of",
"error"
] | f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8 | https://github.com/mapcode-foundation/mapcode-java/blob/f12d4d9fbd460472ac0fff1f702f2ac716bc0ab8/src/main/java/com/mapcode/Decoder.java#L817-L829 | train |
btrplace/scheduler | btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java | SymbolsTable.declareImmutable | public boolean declareImmutable(String label, BtrpOperand t) {
if (isDeclared(label)) {
return false;
}
level.put(label, -1);
type.put(label, t);
return true;
} | java | public boolean declareImmutable(String label, BtrpOperand t) {
if (isDeclared(label)) {
return false;
}
level.put(label, -1);
type.put(label, t);
return true;
} | [
"public",
"boolean",
"declareImmutable",
"(",
"String",
"label",
",",
"BtrpOperand",
"t",
")",
"{",
"if",
"(",
"isDeclared",
"(",
"label",
")",
")",
"{",
"return",
"false",
";",
"}",
"level",
".",
"put",
"(",
"label",
",",
"-",
"1",
")",
";",
"type",... | Declare an immutable variable. The variable must not
has been already declared.
@param label the identifier of the variable
@param t the operand associated to the identifier
@return {@code true} if the variable as been declared. {@code false} otherwise | [
"Declare",
"an",
"immutable",
"variable",
".",
"The",
"variable",
"must",
"not",
"has",
"been",
"already",
"declared",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java#L73-L80 | train |
btrplace/scheduler | btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java | SymbolsTable.remove | public boolean remove(String label) {
if (!isDeclared(label)) {
return false;
}
level.remove(label);
type.remove(label);
return true;
} | java | public boolean remove(String label) {
if (!isDeclared(label)) {
return false;
}
level.remove(label);
type.remove(label);
return true;
} | [
"public",
"boolean",
"remove",
"(",
"String",
"label",
")",
"{",
"if",
"(",
"!",
"isDeclared",
"(",
"label",
")",
")",
"{",
"return",
"false",
";",
"}",
"level",
".",
"remove",
"(",
"label",
")",
";",
"type",
".",
"remove",
"(",
"label",
")",
";",
... | Remove a symbol from the table.
@param label the symbol to remove
@return {@code true} if the symbol was present then removed. {@code false} otherwise | [
"Remove",
"a",
"symbol",
"from",
"the",
"table",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java#L88-L95 | train |
btrplace/scheduler | btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java | SymbolsTable.declare | public final boolean declare(String label, BtrpOperand t) {
if (isDeclared(label) && level.get(label) < 0) { //Disallow immutable value
return false;
}
if (!isDeclared(label)) {
level.put(label, currentLevel);
}
type.put(label, t);
return true;
} | java | public final boolean declare(String label, BtrpOperand t) {
if (isDeclared(label) && level.get(label) < 0) { //Disallow immutable value
return false;
}
if (!isDeclared(label)) {
level.put(label, currentLevel);
}
type.put(label, t);
return true;
} | [
"public",
"final",
"boolean",
"declare",
"(",
"String",
"label",
",",
"BtrpOperand",
"t",
")",
"{",
"if",
"(",
"isDeclared",
"(",
"label",
")",
"&&",
"level",
".",
"get",
"(",
"label",
")",
"<",
"0",
")",
"{",
"//Disallow immutable value",
"return",
"fal... | Declare a new variable.
The variable is inserted into the current script.
@param label the label of the variable
@param t the content of the variable
@return {@code true} if the declaration succeeds, {@code false} otherwise | [
"Declare",
"a",
"new",
"variable",
".",
"The",
"variable",
"is",
"inserted",
"into",
"the",
"current",
"script",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/btrpsl/src/main/java/org/btrplace/btrpsl/SymbolsTable.java#L115-L124 | train |
OpenNTF/JavascriptAggregator | jaggr-core/src/main/java/com/ibm/jaggr/core/impl/modulebuilder/javascript/JavaScriptModuleBuilder.java | JavaScriptModuleBuilder.getJSSource | protected List<JSSourceFile> getJSSource(String mid, IResource resource, HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws IOException {
List<JSSourceFile> result = new ArrayList<JSSourceFile>(1);
InputStream in = resource.getInputStream();
JSSourceFile sf = JSSourceFile.fromInputStream(mid, in);
sf.setOriginalPath(resource.getURI().toString());
in.close();
result.add(sf);
return result;
} | java | protected List<JSSourceFile> getJSSource(String mid, IResource resource, HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws IOException {
List<JSSourceFile> result = new ArrayList<JSSourceFile>(1);
InputStream in = resource.getInputStream();
JSSourceFile sf = JSSourceFile.fromInputStream(mid, in);
sf.setOriginalPath(resource.getURI().toString());
in.close();
result.add(sf);
return result;
} | [
"protected",
"List",
"<",
"JSSourceFile",
">",
"getJSSource",
"(",
"String",
"mid",
",",
"IResource",
"resource",
",",
"HttpServletRequest",
"request",
",",
"List",
"<",
"ICacheKeyGenerator",
">",
"keyGens",
")",
"throws",
"IOException",
"{",
"List",
"<",
"JSSou... | Overrideable method for getting the source modules to compile
@param mid
the module id
@param resource
the resource
@param request
the request object
@param keyGens
the list of cache key generators
@return the list of source files
@throws IOException | [
"Overrideable",
"method",
"for",
"getting",
"the",
"source",
"modules",
"to",
"compile"
] | 9f47a96d778251638b1df9a368462176216d5b29 | https://github.com/OpenNTF/JavascriptAggregator/blob/9f47a96d778251638b1df9a368462176216d5b29/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/modulebuilder/javascript/JavaScriptModuleBuilder.java#L555-L564 | train |
OpenNTF/JavascriptAggregator | jaggr-core/src/main/java/com/ibm/jaggr/core/impl/modulebuilder/javascript/JavaScriptModuleBuilder.java | JavaScriptModuleBuilder.moduleNameIdEncodingBeginLayer | protected String moduleNameIdEncodingBeginLayer(HttpServletRequest request) {
StringBuffer sb = new StringBuffer();
if (request.getParameter(AbstractHttpTransport.SCRIPTS_REQPARAM) != null) {
// This is a request for a bootstrap layer with non-AMD script modules.
// Define the deps variable in global scope in case it's needed by
// the script modules.
sb.append("var " + EXPDEPS_VARNAME + ";"); //$NON-NLS-1$//$NON-NLS-2$
}
return sb.toString();
} | java | protected String moduleNameIdEncodingBeginLayer(HttpServletRequest request) {
StringBuffer sb = new StringBuffer();
if (request.getParameter(AbstractHttpTransport.SCRIPTS_REQPARAM) != null) {
// This is a request for a bootstrap layer with non-AMD script modules.
// Define the deps variable in global scope in case it's needed by
// the script modules.
sb.append("var " + EXPDEPS_VARNAME + ";"); //$NON-NLS-1$//$NON-NLS-2$
}
return sb.toString();
} | [
"protected",
"String",
"moduleNameIdEncodingBeginLayer",
"(",
"HttpServletRequest",
"request",
")",
"{",
"StringBuffer",
"sb",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"if",
"(",
"request",
".",
"getParameter",
"(",
"AbstractHttpTransport",
".",
"SCRIPTS_REQPARAM",
... | Returns the text to be included at the beginning of the layer if module name id
encoding is enabled.
@param request
the http request object
@return the string to include at the beginning of the layer | [
"Returns",
"the",
"text",
"to",
"be",
"included",
"at",
"the",
"beginning",
"of",
"the",
"layer",
"if",
"module",
"name",
"id",
"encoding",
"is",
"enabled",
"."
] | 9f47a96d778251638b1df9a368462176216d5b29 | https://github.com/OpenNTF/JavascriptAggregator/blob/9f47a96d778251638b1df9a368462176216d5b29/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/modulebuilder/javascript/JavaScriptModuleBuilder.java#L591-L600 | train |
m-m-m/util | scanner/src/main/java/net/sf/mmm/util/scanner/base/CharSequenceScanner.java | CharSequenceScanner.getTail | protected String getTail() {
String tail = "";
if (this.offset < this.limit) {
tail = new String(this.buffer, this.offset, this.limit - this.offset + 1);
}
return tail;
} | java | protected String getTail() {
String tail = "";
if (this.offset < this.limit) {
tail = new String(this.buffer, this.offset, this.limit - this.offset + 1);
}
return tail;
} | [
"protected",
"String",
"getTail",
"(",
")",
"{",
"String",
"tail",
"=",
"\"\"",
";",
"if",
"(",
"this",
".",
"offset",
"<",
"this",
".",
"limit",
")",
"{",
"tail",
"=",
"new",
"String",
"(",
"this",
".",
"buffer",
",",
"this",
".",
"offset",
",",
... | This method gets the tail of this scanner without changing the state.
@return the tail of this scanner. | [
"This",
"method",
"gets",
"the",
"tail",
"of",
"this",
"scanner",
"without",
"changing",
"the",
"state",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/scanner/src/main/java/net/sf/mmm/util/scanner/base/CharSequenceScanner.java#L335-L342 | train |
m-m-m/util | scanner/src/main/java/net/sf/mmm/util/scanner/base/CharSequenceScanner.java | CharSequenceScanner.getOriginalString | public String getOriginalString() {
if (this.string != null) {
this.string = new String(this.buffer, this.initialOffset, getLength());
}
return this.string;
} | java | public String getOriginalString() {
if (this.string != null) {
this.string = new String(this.buffer, this.initialOffset, getLength());
}
return this.string;
} | [
"public",
"String",
"getOriginalString",
"(",
")",
"{",
"if",
"(",
"this",
".",
"string",
"!=",
"null",
")",
"{",
"this",
".",
"string",
"=",
"new",
"String",
"(",
"this",
".",
"buffer",
",",
"this",
".",
"initialOffset",
",",
"getLength",
"(",
")",
... | This method gets the original string to parse.
@see CharSequenceScanner#CharSequenceScanner(String)
@return the original string. | [
"This",
"method",
"gets",
"the",
"original",
"string",
"to",
"parse",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/scanner/src/main/java/net/sf/mmm/util/scanner/base/CharSequenceScanner.java#L391-L397 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/plan/event/SuspendVM.java | SuspendVM.applyAction | @Override
public boolean applyAction(Model m) {
Mapping map = m.getMapping();
return map.isRunning(vm) &&
map.getVMLocation(vm).equals(src) &&
map.addSleepingVM(vm, dst);
} | java | @Override
public boolean applyAction(Model m) {
Mapping map = m.getMapping();
return map.isRunning(vm) &&
map.getVMLocation(vm).equals(src) &&
map.addSleepingVM(vm, dst);
} | [
"@",
"Override",
"public",
"boolean",
"applyAction",
"(",
"Model",
"m",
")",
"{",
"Mapping",
"map",
"=",
"m",
".",
"getMapping",
"(",
")",
";",
"return",
"map",
".",
"isRunning",
"(",
"vm",
")",
"&&",
"map",
".",
"getVMLocation",
"(",
"vm",
")",
".",... | Apply the action by putting the VM
into the sleeping state on its destination node in a given model
@param m the model to alter
@return {@code true} iff the VM is now sleeping on the destination node | [
"Apply",
"the",
"action",
"by",
"putting",
"the",
"VM",
"into",
"the",
"sleeping",
"state",
"on",
"its",
"destination",
"node",
"in",
"a",
"given",
"model"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/plan/event/SuspendVM.java#L67-L73 | train |
btrplace/scheduler | json/src/main/java/org/btrplace/json/model/view/network/StaticRoutingConverter.java | StaticRoutingConverter.nodesMapFromJSON | public StaticRouting.NodesMap nodesMapFromJSON(Model mo, JSONObject o) throws JSONConverterException {
return new StaticRouting.NodesMap(requiredNode(mo, o, "src"), requiredNode(mo, o, "dst"));
} | java | public StaticRouting.NodesMap nodesMapFromJSON(Model mo, JSONObject o) throws JSONConverterException {
return new StaticRouting.NodesMap(requiredNode(mo, o, "src"), requiredNode(mo, o, "dst"));
} | [
"public",
"StaticRouting",
".",
"NodesMap",
"nodesMapFromJSON",
"(",
"Model",
"mo",
",",
"JSONObject",
"o",
")",
"throws",
"JSONConverterException",
"{",
"return",
"new",
"StaticRouting",
".",
"NodesMap",
"(",
"requiredNode",
"(",
"mo",
",",
"o",
",",
"\"src\"",... | Convert a JSON nodes map object into a Java NodesMap object
@param o the JSON object to convert
@return the nodes map | [
"Convert",
"a",
"JSON",
"nodes",
"map",
"object",
"into",
"a",
"Java",
"NodesMap",
"object"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/json/src/main/java/org/btrplace/json/model/view/network/StaticRoutingConverter.java#L90-L92 | train |
btrplace/scheduler | split/src/main/java/org/btrplace/scheduler/runner/disjoint/splitter/ConstraintSplitterMapper.java | ConstraintSplitterMapper.newBundle | public static ConstraintSplitterMapper newBundle() {
ConstraintSplitterMapper mapper = new ConstraintSplitterMapper();
mapper.register(new AmongSplitter());
mapper.register(new BanSplitter());
mapper.register(new FenceSplitter());
mapper.register(new GatherSplitter());
mapper.register(new KilledSplitter());
mapper.register(new LonelySplitter());
mapper.register(new OfflineSplitter());
mapper.register(new OnlineSplitter());
mapper.register(new OverbookSplitter());
mapper.register(new PreserveSplitter());
mapper.register(new QuarantineSplitter());
mapper.register(new ReadySplitter());
mapper.register(new RootSplitter());
mapper.register(new RunningSplitter());
mapper.register(new SeqSplitter());
mapper.register(new SleepingSplitter());
mapper.register(new SplitSplitter());
mapper.register(new SpreadSplitter());
return mapper;
} | java | public static ConstraintSplitterMapper newBundle() {
ConstraintSplitterMapper mapper = new ConstraintSplitterMapper();
mapper.register(new AmongSplitter());
mapper.register(new BanSplitter());
mapper.register(new FenceSplitter());
mapper.register(new GatherSplitter());
mapper.register(new KilledSplitter());
mapper.register(new LonelySplitter());
mapper.register(new OfflineSplitter());
mapper.register(new OnlineSplitter());
mapper.register(new OverbookSplitter());
mapper.register(new PreserveSplitter());
mapper.register(new QuarantineSplitter());
mapper.register(new ReadySplitter());
mapper.register(new RootSplitter());
mapper.register(new RunningSplitter());
mapper.register(new SeqSplitter());
mapper.register(new SleepingSplitter());
mapper.register(new SplitSplitter());
mapper.register(new SpreadSplitter());
return mapper;
} | [
"public",
"static",
"ConstraintSplitterMapper",
"newBundle",
"(",
")",
"{",
"ConstraintSplitterMapper",
"mapper",
"=",
"new",
"ConstraintSplitterMapper",
"(",
")",
";",
"mapper",
".",
"register",
"(",
"new",
"AmongSplitter",
"(",
")",
")",
";",
"mapper",
".",
"r... | Make a new bridge and register
every splitters supported by default.
@return the fulfilled bridge. | [
"Make",
"a",
"new",
"bridge",
"and",
"register",
"every",
"splitters",
"supported",
"by",
"default",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/split/src/main/java/org/btrplace/scheduler/runner/disjoint/splitter/ConstraintSplitterMapper.java#L52-L75 | train |
btrplace/scheduler | split/src/main/java/org/btrplace/scheduler/runner/disjoint/splitter/ConstraintSplitterMapper.java | ConstraintSplitterMapper.register | public boolean register(ConstraintSplitter<? extends Constraint> ccb) {
return builders.put(ccb.getKey(), ccb) == null;
} | java | public boolean register(ConstraintSplitter<? extends Constraint> ccb) {
return builders.put(ccb.getKey(), ccb) == null;
} | [
"public",
"boolean",
"register",
"(",
"ConstraintSplitter",
"<",
"?",
"extends",
"Constraint",
">",
"ccb",
")",
"{",
"return",
"builders",
".",
"put",
"(",
"ccb",
".",
"getKey",
"(",
")",
",",
"ccb",
")",
"==",
"null",
";",
"}"
] | Register a splitter.
@param ccb the splitter to register
@return {@code true} if no splitter previously registered for the given constraint was deleted | [
"Register",
"a",
"splitter",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/split/src/main/java/org/btrplace/scheduler/runner/disjoint/splitter/ConstraintSplitterMapper.java#L83-L85 | train |
m-m-m/util | gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java | AbstractIncrementalGenerator.generateDefaultConstructor | protected void generateDefaultConstructor(SourceWriter sourceWriter, String simpleName) {
generateSourcePublicConstructorDeclaration(sourceWriter, simpleName);
sourceWriter.println("super();");
generateSourceCloseBlock(sourceWriter);
} | java | protected void generateDefaultConstructor(SourceWriter sourceWriter, String simpleName) {
generateSourcePublicConstructorDeclaration(sourceWriter, simpleName);
sourceWriter.println("super();");
generateSourceCloseBlock(sourceWriter);
} | [
"protected",
"void",
"generateDefaultConstructor",
"(",
"SourceWriter",
"sourceWriter",
",",
"String",
"simpleName",
")",
"{",
"generateSourcePublicConstructorDeclaration",
"(",
"sourceWriter",
",",
"simpleName",
")",
";",
"sourceWriter",
".",
"println",
"(",
"\"super();\... | Generates the the default constructor.
@param sourceWriter is the {@link SourceWriter}.
@param simpleName is the {@link Class#getSimpleName() simple name}. | [
"Generates",
"the",
"the",
"default",
"constructor",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java#L167-L172 | train |
m-m-m/util | gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java | AbstractIncrementalGenerator.generateSourcePublicMethodDeclaration | protected final void generateSourcePublicMethodDeclaration(SourceWriter sourceWriter, JMethod method) {
StringBuilder arguments = new StringBuilder();
for (JParameter parameter : method.getParameters()) {
if (arguments.length() > 0) {
arguments.append(", ");
}
arguments.append(parameter.getType().getQualifiedSourceName());
arguments.append(" ");
arguments.append(parameter.getName());
}
generateSourcePublicMethodDeclaration(sourceWriter, method.getReturnType().getQualifiedSourceName(),
method.getName(), arguments.toString(), false);
} | java | protected final void generateSourcePublicMethodDeclaration(SourceWriter sourceWriter, JMethod method) {
StringBuilder arguments = new StringBuilder();
for (JParameter parameter : method.getParameters()) {
if (arguments.length() > 0) {
arguments.append(", ");
}
arguments.append(parameter.getType().getQualifiedSourceName());
arguments.append(" ");
arguments.append(parameter.getName());
}
generateSourcePublicMethodDeclaration(sourceWriter, method.getReturnType().getQualifiedSourceName(),
method.getName(), arguments.toString(), false);
} | [
"protected",
"final",
"void",
"generateSourcePublicMethodDeclaration",
"(",
"SourceWriter",
"sourceWriter",
",",
"JMethod",
"method",
")",
"{",
"StringBuilder",
"arguments",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"JParameter",
"parameter",
":",
"met... | This method generates the source code for a public method declaration including the opening brace and indentation.
@param sourceWriter is the {@link SourceWriter}.
@param method is the {@link JMethod} to implement. | [
"This",
"method",
"generates",
"the",
"source",
"code",
"for",
"a",
"public",
"method",
"declaration",
"including",
"the",
"opening",
"brace",
"and",
"indentation",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java#L193-L206 | train |
m-m-m/util | gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java | AbstractIncrementalGenerator.generateSourcePublicMethodDeclaration | protected final void generateSourcePublicMethodDeclaration(SourceWriter sourceWriter, String returnType,
String methodName, String arguments, boolean override) {
if (override) {
sourceWriter.println("@Override");
}
sourceWriter.print("public ");
if (returnType != null) {
sourceWriter.print(returnType);
sourceWriter.print(" ");
}
sourceWriter.print(methodName);
sourceWriter.print("(");
sourceWriter.print(arguments);
sourceWriter.println(") {");
sourceWriter.indent();
} | java | protected final void generateSourcePublicMethodDeclaration(SourceWriter sourceWriter, String returnType,
String methodName, String arguments, boolean override) {
if (override) {
sourceWriter.println("@Override");
}
sourceWriter.print("public ");
if (returnType != null) {
sourceWriter.print(returnType);
sourceWriter.print(" ");
}
sourceWriter.print(methodName);
sourceWriter.print("(");
sourceWriter.print(arguments);
sourceWriter.println(") {");
sourceWriter.indent();
} | [
"protected",
"final",
"void",
"generateSourcePublicMethodDeclaration",
"(",
"SourceWriter",
"sourceWriter",
",",
"String",
"returnType",
",",
"String",
"methodName",
",",
"String",
"arguments",
",",
"boolean",
"override",
")",
"{",
"if",
"(",
"override",
")",
"{",
... | This method generates the source code for a public method or constructor including the opening brace and
indentation.
@param sourceWriter is the {@link SourceWriter}.
@param returnType is the return type of the method.
@param methodName is the name of the method (or the {@link Class#getSimpleName() simple class name} for a
constructor}.
@param arguments is the source line with the arguments to the method or constructor.
@param override - {@code true} if an {@link Override} annotation shall be added. | [
"This",
"method",
"generates",
"the",
"source",
"code",
"for",
"a",
"public",
"method",
"or",
"constructor",
"including",
"the",
"opening",
"brace",
"and",
"indentation",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/gwt/src/main/java/net/sf/mmm/util/gwt/base/rebind/AbstractIncrementalGenerator.java#L219-L235 | train |
OpenNTF/JavascriptAggregator | jaggr-core/src/main/java/com/ibm/jaggr/core/impl/cache/CacheManagerImpl.java | CacheManagerImpl.notifyInit | protected void notifyInit () {
final String sourceMethod = "notifyInit"; //$NON-NLS-1$
IServiceReference[] refs = null;
try {
if(_aggregator != null && _aggregator.getPlatformServices() != null){
refs = _aggregator.getPlatformServices().getServiceReferences(ICacheManagerListener.class.getName(),"(name=" + _aggregator.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
if (refs != null) {
for (IServiceReference ref : refs) {
ICacheManagerListener listener = (ICacheManagerListener)_aggregator.getPlatformServices().getService(ref);
if (listener != null) {
try {
listener.initialized(this);
} catch (Throwable t) {
if (log.isLoggable(Level.WARNING)) {
log.logp(Level.WARNING, CacheManagerImpl.class.getName(), sourceMethod, t.getMessage(), t);
}
} finally {
_aggregator.getPlatformServices().ungetService(ref);
}
}
}
}
}
} catch (PlatformServicesException e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
} | java | protected void notifyInit () {
final String sourceMethod = "notifyInit"; //$NON-NLS-1$
IServiceReference[] refs = null;
try {
if(_aggregator != null && _aggregator.getPlatformServices() != null){
refs = _aggregator.getPlatformServices().getServiceReferences(ICacheManagerListener.class.getName(),"(name=" + _aggregator.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
if (refs != null) {
for (IServiceReference ref : refs) {
ICacheManagerListener listener = (ICacheManagerListener)_aggregator.getPlatformServices().getService(ref);
if (listener != null) {
try {
listener.initialized(this);
} catch (Throwable t) {
if (log.isLoggable(Level.WARNING)) {
log.logp(Level.WARNING, CacheManagerImpl.class.getName(), sourceMethod, t.getMessage(), t);
}
} finally {
_aggregator.getPlatformServices().ungetService(ref);
}
}
}
}
}
} catch (PlatformServicesException e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
} | [
"protected",
"void",
"notifyInit",
"(",
")",
"{",
"final",
"String",
"sourceMethod",
"=",
"\"notifyInit\"",
";",
"//$NON-NLS-1$\r",
"IServiceReference",
"[",
"]",
"refs",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"_aggregator",
"!=",
"null",
"&&",
"_aggregator"... | Notify listeners that the cache manager is initialized. | [
"Notify",
"listeners",
"that",
"the",
"cache",
"manager",
"is",
"initialized",
"."
] | 9f47a96d778251638b1df9a368462176216d5b29 | https://github.com/OpenNTF/JavascriptAggregator/blob/9f47a96d778251638b1df9a368462176216d5b29/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/cache/CacheManagerImpl.java#L594-L622 | train |
OpenNTF/JavascriptAggregator | jaggr-core/src/main/java/com/ibm/jaggr/core/impl/ForcedErrorResponse.java | ForcedErrorResponse.getStatus | public int getStatus() {
int result = status;
if (status > 0) {
if (skip.getAndDecrement() <= 0) {
if (count.getAndDecrement() <= 0) {
result = status = -1;
}
} else {
result = 0;
}
}
return result;
} | java | public int getStatus() {
int result = status;
if (status > 0) {
if (skip.getAndDecrement() <= 0) {
if (count.getAndDecrement() <= 0) {
result = status = -1;
}
} else {
result = 0;
}
}
return result;
} | [
"public",
"int",
"getStatus",
"(",
")",
"{",
"int",
"result",
"=",
"status",
";",
"if",
"(",
"status",
">",
"0",
")",
"{",
"if",
"(",
"skip",
".",
"getAndDecrement",
"(",
")",
"<=",
"0",
")",
"{",
"if",
"(",
"count",
".",
"getAndDecrement",
"(",
... | Returns the error response status that should be returned for the current
response. If the value is zero, then the normal response should be returned
and this method should be called again for the next response. If the value
is less than 0, then this error response status object is spent and may be
discarded.
@return the error response status | [
"Returns",
"the",
"error",
"response",
"status",
"that",
"should",
"be",
"returned",
"for",
"the",
"current",
"response",
".",
"If",
"the",
"value",
"is",
"zero",
"then",
"the",
"normal",
"response",
"should",
"be",
"returned",
"and",
"this",
"method",
"shou... | 9f47a96d778251638b1df9a368462176216d5b29 | https://github.com/OpenNTF/JavascriptAggregator/blob/9f47a96d778251638b1df9a368462176216d5b29/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/ForcedErrorResponse.java#L86-L98 | train |
InsightLab/graphast | core/src/main/java/br/ufc/insightlab/graphast/serialization/SerializationUtils.java | SerializationUtils.deleteMMapGraph | public static boolean deleteMMapGraph(String path) {
String directory = ensureDirectory(path);
File f = new File(directory);
boolean ok = true;
if (f.exists()) {
ok = new File(directory + "nodes.mmap").delete();
ok = new File(directory + "edges.mmap").delete() && ok;
ok = new File(directory + "treeMap.mmap").delete() && ok;
ok = f.delete() && ok;
}
return ok;
} | java | public static boolean deleteMMapGraph(String path) {
String directory = ensureDirectory(path);
File f = new File(directory);
boolean ok = true;
if (f.exists()) {
ok = new File(directory + "nodes.mmap").delete();
ok = new File(directory + "edges.mmap").delete() && ok;
ok = new File(directory + "treeMap.mmap").delete() && ok;
ok = f.delete() && ok;
}
return ok;
} | [
"public",
"static",
"boolean",
"deleteMMapGraph",
"(",
"String",
"path",
")",
"{",
"String",
"directory",
"=",
"ensureDirectory",
"(",
"path",
")",
";",
"File",
"f",
"=",
"new",
"File",
"(",
"directory",
")",
";",
"boolean",
"ok",
"=",
"true",
";",
"if",... | Delete a graph from the given path.
@param path to search the file that contains the graph that will be deleted.
@return true if the MMap Graph was deleted without problems, false otherwise. | [
"Delete",
"a",
"graph",
"from",
"the",
"given",
"path",
"."
] | b81d10c1ea8378e1fb9fcb545dd75d5e6308fd24 | https://github.com/InsightLab/graphast/blob/b81d10c1ea8378e1fb9fcb545dd75d5e6308fd24/core/src/main/java/br/ufc/insightlab/graphast/serialization/SerializationUtils.java#L49-L63 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/ChocoMapper.java | ChocoMapper.mapConstraint | public void mapConstraint(Class<? extends Constraint> c, Class<? extends ChocoConstraint> cc) {
constraints.put(c, cc);
} | java | public void mapConstraint(Class<? extends Constraint> c, Class<? extends ChocoConstraint> cc) {
constraints.put(c, cc);
} | [
"public",
"void",
"mapConstraint",
"(",
"Class",
"<",
"?",
"extends",
"Constraint",
">",
"c",
",",
"Class",
"<",
"?",
"extends",
"ChocoConstraint",
">",
"cc",
")",
"{",
"constraints",
".",
"put",
"(",
"c",
",",
"cc",
")",
";",
"}"
] | Register a mapping between an api-side constraint and its choco implementation.
It is expected from the implementation to exhibit a constructor that takes the api-side constraint as argument.
@param c the api-side constraint
@param cc the choco implementation
@throws IllegalArgumentException if there is no suitable constructor for the choco implementation | [
"Register",
"a",
"mapping",
"between",
"an",
"api",
"-",
"side",
"constraint",
"and",
"its",
"choco",
"implementation",
".",
"It",
"is",
"expected",
"from",
"the",
"implementation",
"to",
"exhibit",
"a",
"constructor",
"that",
"takes",
"the",
"api",
"-",
"si... | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/ChocoMapper.java#L140-L142 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/ChocoMapper.java | ChocoMapper.mapView | public void mapView(Class<? extends ModelView> c, Class<? extends ChocoView> cc) {
views.put(c, cc);
} | java | public void mapView(Class<? extends ModelView> c, Class<? extends ChocoView> cc) {
views.put(c, cc);
} | [
"public",
"void",
"mapView",
"(",
"Class",
"<",
"?",
"extends",
"ModelView",
">",
"c",
",",
"Class",
"<",
"?",
"extends",
"ChocoView",
">",
"cc",
")",
"{",
"views",
".",
"put",
"(",
"c",
",",
"cc",
")",
";",
"}"
] | Register a mapping between an api-side view and its choco implementation.
It is expected from the implementation to exhibit a constructor that takes the api-side constraint as argument.
@param c the api-side view
@param cc the choco implementation
@throws IllegalArgumentException if there is no suitable constructor for the choco implementation | [
"Register",
"a",
"mapping",
"between",
"an",
"api",
"-",
"side",
"view",
"and",
"its",
"choco",
"implementation",
".",
"It",
"is",
"expected",
"from",
"the",
"implementation",
"to",
"exhibit",
"a",
"constructor",
"that",
"takes",
"the",
"api",
"-",
"side",
... | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/ChocoMapper.java#L152-L154 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/StaticRouting.java | StaticRouting.getStaticRoute | public List<Link> getStaticRoute(NodesMap nm) {
Map<Link, Boolean> route = routes.get(nm);
if (route == null) {
return null;
}
return new ArrayList<>(route.keySet());
} | java | public List<Link> getStaticRoute(NodesMap nm) {
Map<Link, Boolean> route = routes.get(nm);
if (route == null) {
return null;
}
return new ArrayList<>(route.keySet());
} | [
"public",
"List",
"<",
"Link",
">",
"getStaticRoute",
"(",
"NodesMap",
"nm",
")",
"{",
"Map",
"<",
"Link",
",",
"Boolean",
">",
"route",
"=",
"routes",
".",
"get",
"(",
"nm",
")",
";",
"if",
"(",
"route",
"==",
"null",
")",
"{",
"return",
"null",
... | Get the static route between two given nodes.
@param nm the nodes map
@return the static route. {@code null} if not found | [
"Get",
"the",
"static",
"route",
"between",
"two",
"given",
"nodes",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/StaticRouting.java#L52-L61 | train |
btrplace/scheduler | api/src/main/java/org/btrplace/model/view/network/StaticRouting.java | StaticRouting.setStaticRoute | public void setStaticRoute(NodesMap nm, Map<Link, Boolean> links) {
routes.put(nm, links); // Only one route between two nodes (replace the old route)
} | java | public void setStaticRoute(NodesMap nm, Map<Link, Boolean> links) {
routes.put(nm, links); // Only one route between two nodes (replace the old route)
} | [
"public",
"void",
"setStaticRoute",
"(",
"NodesMap",
"nm",
",",
"Map",
"<",
"Link",
",",
"Boolean",
">",
"links",
")",
"{",
"routes",
".",
"put",
"(",
"nm",
",",
"links",
")",
";",
"// Only one route between two nodes (replace the old route)",
"}"
] | Manually add a static route between two nodes.
@param nm a node mapping containing two nodes: the source and the destination node.
@param links an insert-ordered map of link<->direction representing the path between the two nodes. | [
"Manually",
"add",
"a",
"static",
"route",
"between",
"two",
"nodes",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/api/src/main/java/org/btrplace/model/view/network/StaticRouting.java#L78-L80 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java | OnStableNodeFirst.getMovingVM | private IntVar getMovingVM() {
//VMs that are moving
for (int i = move.nextSetBit(0); i >= 0; i = move.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated() && oldPos[i] != hosts[i].getValue()) {
return starts[i];
}
}
return null;
} | java | private IntVar getMovingVM() {
//VMs that are moving
for (int i = move.nextSetBit(0); i >= 0; i = move.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated() && oldPos[i] != hosts[i].getValue()) {
return starts[i];
}
}
return null;
} | [
"private",
"IntVar",
"getMovingVM",
"(",
")",
"{",
"//VMs that are moving",
"for",
"(",
"int",
"i",
"=",
"move",
".",
"nextSetBit",
"(",
"0",
")",
";",
"i",
">=",
"0",
";",
"i",
"=",
"move",
".",
"nextSetBit",
"(",
"i",
"+",
"1",
")",
")",
"{",
"... | Get the start moment for a VM that moves
@return a start moment, or {@code null} if all the moments are already instantiated | [
"Get",
"the",
"start",
"moment",
"for",
"a",
"VM",
"that",
"moves"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java#L184-L192 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java | OnStableNodeFirst.getEarlyVar | private IntVar getEarlyVar() {
IntVar earlyVar = null;
for (int i = stays.nextSetBit(0); i >= 0; i = stays.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated()) {
if (earlyVar == null) {
earlyVar = starts[i];
} else {
if (earlyVar.getLB() > starts[i].getLB()) {
earlyVar = starts[i];
}
}
}
}
return earlyVar;
} | java | private IntVar getEarlyVar() {
IntVar earlyVar = null;
for (int i = stays.nextSetBit(0); i >= 0; i = stays.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated()) {
if (earlyVar == null) {
earlyVar = starts[i];
} else {
if (earlyVar.getLB() > starts[i].getLB()) {
earlyVar = starts[i];
}
}
}
}
return earlyVar;
} | [
"private",
"IntVar",
"getEarlyVar",
"(",
")",
"{",
"IntVar",
"earlyVar",
"=",
"null",
";",
"for",
"(",
"int",
"i",
"=",
"stays",
".",
"nextSetBit",
"(",
"0",
")",
";",
"i",
">=",
"0",
";",
"i",
"=",
"stays",
".",
"nextSetBit",
"(",
"i",
"+",
"1",... | Get the earliest un-instantiated start moment
@return the variable, or {@code null} if all the start moments are already instantiated | [
"Get",
"the",
"earliest",
"un",
"-",
"instantiated",
"start",
"moment"
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java#L222-L236 | train |
btrplace/scheduler | choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java | OnStableNodeFirst.getVMtoLeafNode | private IntVar getVMtoLeafNode() {
for (int x = 0; x < outs.length; x++) {
if (outs[x].cardinality() == 0) {
//no outgoing VMs, can be launched directly.
BitSet in = ins[x];
for (int i = in.nextSetBit(0); i >= 0; i = in.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated()) {
return starts[i];
}
}
}
}
return null;
} | java | private IntVar getVMtoLeafNode() {
for (int x = 0; x < outs.length; x++) {
if (outs[x].cardinality() == 0) {
//no outgoing VMs, can be launched directly.
BitSet in = ins[x];
for (int i = in.nextSetBit(0); i >= 0; i = in.nextSetBit(i + 1)) {
if (starts[i] != null && !starts[i].isInstantiated()) {
return starts[i];
}
}
}
}
return null;
} | [
"private",
"IntVar",
"getVMtoLeafNode",
"(",
")",
"{",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"outs",
".",
"length",
";",
"x",
"++",
")",
"{",
"if",
"(",
"outs",
"[",
"x",
"]",
".",
"cardinality",
"(",
")",
"==",
"0",
")",
"{",
"//n... | Get the start moment for a VM that move to
a node where no VM will leave this node.
This way, we are pretty sure the action can be scheduled at 0.
@return a start moment, or {@code null} if there is no more un-schedule actions to leaf nodes | [
"Get",
"the",
"start",
"moment",
"for",
"a",
"VM",
"that",
"move",
"to",
"a",
"node",
"where",
"no",
"VM",
"will",
"leave",
"this",
"node",
".",
"This",
"way",
"we",
"are",
"pretty",
"sure",
"the",
"action",
"can",
"be",
"scheduled",
"at",
"0",
"."
] | 611063aad0b47a016e57ebf36fa4dfdf24de09e8 | https://github.com/btrplace/scheduler/blob/611063aad0b47a016e57ebf36fa4dfdf24de09e8/choco/src/main/java/org/btrplace/scheduler/choco/constraint/mttr/OnStableNodeFirst.java#L245-L258 | train |
m-m-m/util | contenttype/src/main/java/net/sf/mmm/util/contenttype/base/format/SegmentConstant.java | SegmentConstant.initBytes | protected void initBytes(StringBuilder source) {
if (this.bytes == null) {
if (this.string != null) {
String encodingValue = getEncoding();
try {
this.bytes = this.string.getBytes(encodingValue);
} catch (UnsupportedEncodingException e) {
source.append(".encoding");
throw new NlsIllegalArgumentException(encodingValue, source.toString(), e);
}
} else if (this.hex != null) {
this.bytes = parseBytes(this.hex, "hex");
} else {
throw new XmlInvalidException(
new NlsParseException(XML_TAG, XML_ATTRIBUTE_HEX + "|" + XML_ATTRIBUTE_STRING, source.toString()));
}
}
} | java | protected void initBytes(StringBuilder source) {
if (this.bytes == null) {
if (this.string != null) {
String encodingValue = getEncoding();
try {
this.bytes = this.string.getBytes(encodingValue);
} catch (UnsupportedEncodingException e) {
source.append(".encoding");
throw new NlsIllegalArgumentException(encodingValue, source.toString(), e);
}
} else if (this.hex != null) {
this.bytes = parseBytes(this.hex, "hex");
} else {
throw new XmlInvalidException(
new NlsParseException(XML_TAG, XML_ATTRIBUTE_HEX + "|" + XML_ATTRIBUTE_STRING, source.toString()));
}
}
} | [
"protected",
"void",
"initBytes",
"(",
"StringBuilder",
"source",
")",
"{",
"if",
"(",
"this",
".",
"bytes",
"==",
"null",
")",
"{",
"if",
"(",
"this",
".",
"string",
"!=",
"null",
")",
"{",
"String",
"encodingValue",
"=",
"getEncoding",
"(",
")",
";",... | This method initializes the internal byte array.
@param source describes the source. | [
"This",
"method",
"initializes",
"the",
"internal",
"byte",
"array",
"."
] | f0e4e084448f8dfc83ca682a9e1618034a094ce6 | https://github.com/m-m-m/util/blob/f0e4e084448f8dfc83ca682a9e1618034a094ce6/contenttype/src/main/java/net/sf/mmm/util/contenttype/base/format/SegmentConstant.java#L116-L134 | train |
wuman/orientdb-android | core/src/main/java/com/orientechnologies/orient/core/db/record/ORecordLazyMap.java | ORecordLazyMap.convertLink2Record | private void convertLink2Record(final Object iKey) {
if (status == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS)
return;
final Object value;
if (iKey instanceof ORID)
value = iKey;
else
value = super.get(iKey);
if (value != null && value instanceof ORID) {
final ORID rid = (ORID) value;
marshalling = true;
try {
try {
// OVERWRITE IT
super.put(iKey, rid.getRecord());
} catch (ORecordNotFoundException e) {
// IGNORE THIS
}
} finally {
marshalling = false;
}
}
} | java | private void convertLink2Record(final Object iKey) {
if (status == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS)
return;
final Object value;
if (iKey instanceof ORID)
value = iKey;
else
value = super.get(iKey);
if (value != null && value instanceof ORID) {
final ORID rid = (ORID) value;
marshalling = true;
try {
try {
// OVERWRITE IT
super.put(iKey, rid.getRecord());
} catch (ORecordNotFoundException e) {
// IGNORE THIS
}
} finally {
marshalling = false;
}
}
} | [
"private",
"void",
"convertLink2Record",
"(",
"final",
"Object",
"iKey",
")",
"{",
"if",
"(",
"status",
"==",
"MULTIVALUE_CONTENT_TYPE",
".",
"ALL_RECORDS",
")",
"return",
";",
"final",
"Object",
"value",
";",
"if",
"(",
"iKey",
"instanceof",
"ORID",
")",
"v... | Convert the item with the received key to a record.
@param iKey
Key of the item to convert | [
"Convert",
"the",
"item",
"with",
"the",
"received",
"key",
"to",
"a",
"record",
"."
] | ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0 | https://github.com/wuman/orientdb-android/blob/ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0/core/src/main/java/com/orientechnologies/orient/core/db/record/ORecordLazyMap.java#L187-L212 | train |
wuman/orientdb-android | core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java | ODatabaseFactory.register | public synchronized ODatabaseComplex<?> register(final ODatabaseComplex<?> db) {
instances.put(db, Thread.currentThread());
return db;
} | java | public synchronized ODatabaseComplex<?> register(final ODatabaseComplex<?> db) {
instances.put(db, Thread.currentThread());
return db;
} | [
"public",
"synchronized",
"ODatabaseComplex",
"<",
"?",
">",
"register",
"(",
"final",
"ODatabaseComplex",
"<",
"?",
">",
"db",
")",
"{",
"instances",
".",
"put",
"(",
"db",
",",
"Thread",
".",
"currentThread",
"(",
")",
")",
";",
"return",
"db",
";",
... | Registers a database.
@param db
@return | [
"Registers",
"a",
"database",
"."
] | ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0 | https://github.com/wuman/orientdb-android/blob/ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0/core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java#L41-L44 | train |
wuman/orientdb-android | core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java | ODatabaseFactory.unregister | public synchronized void unregister(final OStorage iStorage) {
for (ODatabaseComplex<?> db : new HashSet<ODatabaseComplex<?>>(instances.keySet())) {
if (db != null && db.getStorage() == iStorage) {
db.close();
instances.remove(db);
}
}
} | java | public synchronized void unregister(final OStorage iStorage) {
for (ODatabaseComplex<?> db : new HashSet<ODatabaseComplex<?>>(instances.keySet())) {
if (db != null && db.getStorage() == iStorage) {
db.close();
instances.remove(db);
}
}
} | [
"public",
"synchronized",
"void",
"unregister",
"(",
"final",
"OStorage",
"iStorage",
")",
"{",
"for",
"(",
"ODatabaseComplex",
"<",
"?",
">",
"db",
":",
"new",
"HashSet",
"<",
"ODatabaseComplex",
"<",
"?",
">",
">",
"(",
"instances",
".",
"keySet",
"(",
... | Unregisters all the database instances that share the storage received as argument.
@param iStorage | [
"Unregisters",
"all",
"the",
"database",
"instances",
"that",
"share",
"the",
"storage",
"received",
"as",
"argument",
"."
] | ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0 | https://github.com/wuman/orientdb-android/blob/ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0/core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java#L60-L67 | train |
wuman/orientdb-android | core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java | ODatabaseFactory.shutdown | public synchronized void shutdown() {
if (instances.size() > 0) {
OLogManager.instance().debug(null,
"Found %d databases opened during OrientDB shutdown. Assure to always close database instances after usage",
instances.size());
for (ODatabaseComplex<?> db : new HashSet<ODatabaseComplex<?>>(instances.keySet())) {
if (db != null && !db.isClosed()) {
db.close();
}
}
}
} | java | public synchronized void shutdown() {
if (instances.size() > 0) {
OLogManager.instance().debug(null,
"Found %d databases opened during OrientDB shutdown. Assure to always close database instances after usage",
instances.size());
for (ODatabaseComplex<?> db : new HashSet<ODatabaseComplex<?>>(instances.keySet())) {
if (db != null && !db.isClosed()) {
db.close();
}
}
}
} | [
"public",
"synchronized",
"void",
"shutdown",
"(",
")",
"{",
"if",
"(",
"instances",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"OLogManager",
".",
"instance",
"(",
")",
".",
"debug",
"(",
"null",
",",
"\"Found %d databases opened during OrientDB shutdown. Ass... | Closes all open databases. | [
"Closes",
"all",
"open",
"databases",
"."
] | ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0 | https://github.com/wuman/orientdb-android/blob/ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0/core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseFactory.java#L72-L84 | train |
wuman/orientdb-android | core/src/main/java/com/orientechnologies/orient/core/security/OSecurityManager.java | OSecurityManager.digest2String | public String digest2String(final String iInput, final boolean iIncludeAlgorithm) {
final StringBuilder buffer = new StringBuilder();
if (iIncludeAlgorithm)
buffer.append(ALGORITHM_PREFIX);
buffer.append(OSecurityManager.instance().digest2String(iInput));
return buffer.toString();
} | java | public String digest2String(final String iInput, final boolean iIncludeAlgorithm) {
final StringBuilder buffer = new StringBuilder();
if (iIncludeAlgorithm)
buffer.append(ALGORITHM_PREFIX);
buffer.append(OSecurityManager.instance().digest2String(iInput));
return buffer.toString();
} | [
"public",
"String",
"digest2String",
"(",
"final",
"String",
"iInput",
",",
"final",
"boolean",
"iIncludeAlgorithm",
")",
"{",
"final",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"iIncludeAlgorithm",
")",
"buffer",
".",
"... | Hashes the input string.
@param iInput
String to hash
@param iIncludeAlgorithm
Include the algorithm used or not
@return | [
"Hashes",
"the",
"input",
"string",
"."
] | ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0 | https://github.com/wuman/orientdb-android/blob/ff9b17e4349f26168b2d0c4facb1a18cbfbe8cf0/core/src/main/java/com/orientechnologies/orient/core/security/OSecurityManager.java#L77-L85 | train |
lightblue-platform/lightblue-migrator | migrator/src/main/java/com/redhat/lightblue/migrator/ThreadMonitor.java | ThreadMonitor.getThreads | private static Thread[] getThreads(ThreadGroup g) {
int mul = 1;
do {
Thread[] arr = new Thread[g.activeCount() * mul + 1];
if (g.enumerate(arr) < arr.length) {
return arr;
}
mul++;
} while (true);
} | java | private static Thread[] getThreads(ThreadGroup g) {
int mul = 1;
do {
Thread[] arr = new Thread[g.activeCount() * mul + 1];
if (g.enumerate(arr) < arr.length) {
return arr;
}
mul++;
} while (true);
} | [
"private",
"static",
"Thread",
"[",
"]",
"getThreads",
"(",
"ThreadGroup",
"g",
")",
"{",
"int",
"mul",
"=",
"1",
";",
"do",
"{",
"Thread",
"[",
"]",
"arr",
"=",
"new",
"Thread",
"[",
"g",
".",
"activeCount",
"(",
")",
"*",
"mul",
"+",
"1",
"]",
... | Returns threads in an array. Some elements may be null. | [
"Returns",
"threads",
"in",
"an",
"array",
".",
"Some",
"elements",
"may",
"be",
"null",
"."
] | ec20748557b40d1f7851e1816d1b76dae48d2027 | https://github.com/lightblue-platform/lightblue-migrator/blob/ec20748557b40d1f7851e1816d1b76dae48d2027/migrator/src/main/java/com/redhat/lightblue/migrator/ThreadMonitor.java#L185-L194 | train |
lightblue-platform/lightblue-migrator | migrator/src/main/java/com/redhat/lightblue/migrator/ThreadMonitor.java | ThreadMonitor.getThreadCount | public int getThreadCount(ThreadGroup group, Status... s) {
Thread[] threads = getThreads(group);
int count = 0;
for (Thread t : threads) {
if (t instanceof MonitoredThread) {
Status status = getStatus((MonitoredThread) t);
if (status != null) {
for (Status x : s) {
if (x == status) {
count++;
}
}
}
}
}
return count;
} | java | public int getThreadCount(ThreadGroup group, Status... s) {
Thread[] threads = getThreads(group);
int count = 0;
for (Thread t : threads) {
if (t instanceof MonitoredThread) {
Status status = getStatus((MonitoredThread) t);
if (status != null) {
for (Status x : s) {
if (x == status) {
count++;
}
}
}
}
}
return count;
} | [
"public",
"int",
"getThreadCount",
"(",
"ThreadGroup",
"group",
",",
"Status",
"...",
"s",
")",
"{",
"Thread",
"[",
"]",
"threads",
"=",
"getThreads",
"(",
"group",
")",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"Thread",
"t",
":",
"threads",
"... | Return the count of threads that are in any of the statuses | [
"Return",
"the",
"count",
"of",
"threads",
"that",
"are",
"in",
"any",
"of",
"the",
"statuses"
] | ec20748557b40d1f7851e1816d1b76dae48d2027 | https://github.com/lightblue-platform/lightblue-migrator/blob/ec20748557b40d1f7851e1816d1b76dae48d2027/migrator/src/main/java/com/redhat/lightblue/migrator/ThreadMonitor.java#L199-L215 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.