_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q15300 | StandardRoadNetwork.getLegalTrafficSide | train | @Pure
public LegalTrafficSide getLegalTrafficSide() {
final String side;
try {
side = getAttributeAsString("LEGAL_TRAFFIC_SIDE"); //$NON-NLS-1$
LegalTrafficSide sd;
try {
sd = LegalTrafficSide.valueOf(side);
} catch (Throwable exception) {
sd = null;
}
if (sd != null) {
return sd;
}
} catch (Throwable exception) {
//
}
return RoadNetworkConstants.getPreferredLegalTrafficSide();
} | java | {
"resource": ""
} |
q15301 | StandardRoadNetwork.fireSegmentChanged | train | protected void fireSegmentChanged(RoadSegment segment) {
if (this.listeners != null && isEventFirable()) {
for (final RoadNetworkListener listener : this.listeners) {
listener.onRoadSegmentChanged(this, segment);
}
}
} | java | {
"resource": ""
} |
q15302 | IntegerList.toSegmentIterable | train | @Pure
public Iterable<IntegerSegment> toSegmentIterable() {
return new Iterable<IntegerSegment>() {
@Override
public Iterator<IntegerSegment> iterator() {
return new SegmentIterator();
}
};
} | java | {
"resource": ""
} |
q15303 | IntegerList.set | train | public void set(SortedSet<? extends Number> collection) {
this.values = null;
this.size = 0;
for (final Number number : collection) {
final int e = number.intValue();
if ((this.values != null) && (e == this.values[this.values.length - 1] + 1)) {
// Same group
++this.values[this.values.length - 1];
++this.size;
}
if ((this.values != null) && (e > this.values[this.values.length - 1] + 1)) {
// Create a new group
final int[] newTab = new int[this.values.length + 2];
System.arraycopy(this.values, 0, newTab, 0, this.values.length);
newTab[newTab.length - 2] = e;
newTab[newTab.length - 1] = newTab[newTab.length - 2];
this.values = newTab;
++this.size;
} else if (this.values == null) {
// Add the first group
this.values = new int[] {e, e};
this.size = 1;
}
}
} | java | {
"resource": ""
} |
q15304 | IntegerList.toSortedSet | train | @Pure
public SortedSet<Integer> toSortedSet() {
final SortedSet<Integer> theset = new TreeSet<>();
if (this.values != null) {
for (int idxStart = 0; idxStart < this.values.length - 1; idxStart += 2) {
for (int n = this.values[idxStart]; n <= this.values[idxStart + 1]; ++n) {
theset.add(n);
}
}
}
return theset;
} | java | {
"resource": ""
} |
q15305 | DssatCommonOutput.formatDateStr2 | train | protected String formatDateStr2(String str) {
// Initial Calendar object
Calendar cal = Calendar.getInstance();
str = str.replaceAll("/", "");
try {
// Set date with input value
cal.set(Integer.parseInt(str.substring(0, 4)), Integer.parseInt(str.substring(4, 6)) - 1, Integer.parseInt(str.substring(6)));
// translatet to yyddd format
return String.format("%1$02d%2$03d", cal.get(Calendar.YEAR) % 100, cal.get(Calendar.DAY_OF_YEAR));
} catch (Exception e) {
// if tranlate failed, then use default value for date
//sbError.append("! Waring: There is a invalid date [").append(str).append("]\r\n");
return formatDateStr2(defValD);
}
} | java | {
"resource": ""
} |
q15306 | DssatCommonOutput.formatDateStr | train | protected static String formatDateStr(String startDate, String strDays) {
// Initial Calendar object
Calendar cal = Calendar.getInstance();
int days;
startDate = startDate.replaceAll("/", "");
try {
days = Double.valueOf(strDays).intValue();
// Set date with input value
cal.set(Integer.parseInt(startDate.substring(0, 4)), Integer.parseInt(startDate.substring(4, 6)) - 1, Integer.parseInt(startDate.substring(6)));
cal.add(Calendar.DATE, days);
// translatet to yyddd format
return String.format("%1$02d%2$03d", cal.get(Calendar.YEAR) % 100, cal.get(Calendar.DAY_OF_YEAR));
} catch (Exception e) {
// if tranlate failed, then use default value for date
// sbError.append("! Waring: There is a invalid date [").append(startDate).append("]\r\n");
return "-99"; //formatDateStr(defValD);
}
} | java | {
"resource": ""
} |
q15307 | DssatCommonOutput.getExName | train | protected String getExName(Map result) {
String ret = getValueOr(result, "exname", "");
if (ret.matches("\\w+\\.\\w{2}[Xx]")) {
ret = ret.substring(0, ret.length() - 1).replace(".", "");
}
// TODO need to be updated with a translate rule for other models' exname
if (ret.matches(".+(_+\\d+)+$")) {
ret = ret.replaceAll("(_+\\d+)+$", "");
}
return ret;
} | java | {
"resource": ""
} |
q15308 | DssatCommonOutput.getCrid | train | protected String getCrid(Map result) {
HashMap mgnData = getObjectOr(result, "management", new HashMap());
ArrayList<HashMap> events = getObjectOr(mgnData, "events", new ArrayList());
String crid = null;
boolean isPlEventExist = false;
for (HashMap event : events) {
if ("planting".equals(event.get("event"))) {
isPlEventExist = true;
if (crid == null) {
crid = (String) event.get("crid");
} else if (!crid.equals(event.get("crid"))) {
return "SQ";
}
}
}
if (crid == null) {
crid = getValueOr(result, "crid", "XX");
}
if (!isPlEventExist && "XX".equals(crid)) {
return "FA";
} else {
// DssatCRIDHelper crids = new DssatCRIDHelper();
return DssatCRIDHelper.get2BitCrid(crid);
}
} | java | {
"resource": ""
} |
q15309 | DssatCommonOutput.getFileName | train | protected synchronized String getFileName(Map result, String fileType) {
String exname = getExName(result);
String crid;
if (getValueOr(result, "seasonal_dome_applied", "N").equals("Y")) {
crid = "SN";
} else {
crid = getCrid(result);
}
if (exname.length() == 10) {
if (crid.equals("XX") || crid.equals("FA")) {
crid = exname.substring(exname.length() - 2, exname.length());
}
}
String ret;
if (exToFileMap.containsKey(exname + "_" + crid)) {
return exToFileMap.get(exname + "_" + crid) + fileType;
} else {
ret = exname;
if (ret.equals("")) {
ret = "TEMP0001";
} else {
try {
if (ret.endsWith(crid)) {
ret = ret.substring(0, ret.length() - crid.length());
}
// If the exname is too long
if (ret.length() > 8) {
ret = ret.substring(0, 8);
}
// If the exname do not follow the Dssat rule
if (!ret.matches("[\\w ]{1,6}\\d{2}$")) {
if (ret.length() > 6) {
ret = ret.substring(0, 6);
}
ret += "01";
}
} catch (Exception e) {
ret = "TEMP0001";
}
}
// Special handling for batch
if (exname.matches(".+_\\d+_b\\S+(__\\d+)?$")) {
int idx = exname.lastIndexOf("_b") + 2;
ret += "B" + exname.substring(idx).replaceAll("__\\d+$", "");
}
// Find a non-repeated file name
int count;
while (fileNameSet.contains(ret + "." + crid)) {
try {
count = Integer.parseInt(ret.substring(ret.length() - 2, ret.length()));
count++;
} catch (Exception e) {
count = 1;
}
ret = ret.replaceAll("\\w{2}$", String.format("%02d", count));
}
}
exToFileMap.put(exname + "_" + crid, ret + "." + crid);
fileNameSet.add(ret + "." + crid);
return ret + "." + crid + fileType;
} | java | {
"resource": ""
} |
q15310 | DssatCommonOutput.decompressData | train | protected void decompressData(HashMap m) {
for (Object key : m.keySet()) {
if (m.get(key) instanceof ArrayList) {
// iterate sub array nodes
decompressData((ArrayList) m.get(key));
} else if (m.get(key) instanceof HashMap) {
// iterate sub data nodes
decompressData((HashMap) m.get(key));
} else {
// ignore other type nodes
}
}
} | java | {
"resource": ""
} |
q15311 | DssatCommonOutput.decompressData | train | protected void decompressData(ArrayList arr) {
HashMap fstData = null; // The first data record (Map type)
HashMap cprData; // The following data record which will be compressed
for (Object sub : arr) {
if (sub instanceof ArrayList) {
// iterate sub array nodes
decompressData((ArrayList) sub);
} else if (sub instanceof HashMap) {
// iterate sub data nodes
decompressData((HashMap) sub);
// Compress data for current array
if (fstData == null) {
// Get first data node
fstData = (HashMap) sub;
} else {
cprData = (HashMap) sub;
// The omitted data will be recovered to the following map; Only data item (String type) will be processed
for (Object key : fstData.keySet()) {
if (!cprData.containsKey(key)) {
cprData.put(key, fstData.get(key));
}
}
}
} else {
}
}
} | java | {
"resource": ""
} |
q15312 | DssatCommonOutput.getPdate | train | protected String getPdate(Map result) {
HashMap management = getObjectOr(result, "management", new HashMap());
ArrayList<HashMap> events = getObjectOr(management, "events", new ArrayList<HashMap>());
for (HashMap event : events) {
if (getValueOr(event, "event", "").equals("planting")) {
return getValueOr(event, "date", "");
}
}
return "";
} | java | {
"resource": ""
} |
q15313 | ZipArchiveMagicNumber.isContentTypeIn | train | private boolean isContentTypeIn(ZipInputStream stream) throws IOException {
boolean isContentType = false;
if (this.innerFile != null) {
final String strInner = this.innerFile.toString();
InputStream dataStream = null;
ZipEntry zipEntry = stream.getNextEntry();
while (zipEntry != null && dataStream == null) {
if (strInner.equals(zipEntry.getName())) {
dataStream = stream;
} else {
zipEntry = stream.getNextEntry();
}
}
if (dataStream != null) {
isContentType = isContentType(stream, zipEntry, dataStream);
}
} else {
isContentType = isContentType(stream, null, null);
}
return isContentType;
} | java | {
"resource": ""
} |
q15314 | DBaseFileAttributePool.close | train | public void close() throws IOException {
this.accessors.clear();
if (this.reader != null) {
this.reader.close();
this.reader = null;
}
} | java | {
"resource": ""
} |
q15315 | DBaseFileAttributePool.getReader | train | @Pure
protected DBaseFileReader getReader() throws IOException {
if (this.reader == null) {
this.reader = new DBaseFileReader(this.url.openStream());
this.reader.readDBFHeader();
this.reader.readDBFFields();
}
return this.reader;
} | java | {
"resource": ""
} |
q15316 | DBaseFileAttributePool.getAllAttributeNames | train | @SuppressWarnings("resource")
@Pure
public Collection<String> getAllAttributeNames(int recordNumber) {
try {
final DBaseFileReader dbReader = getReader();
synchronized (dbReader) {
final List<DBaseFileField> fields = dbReader.getDBFFields();
if (fields == null) {
return Collections.emptyList();
}
final ArrayList<String> titles = new ArrayList<>(fields.size());
for (int i = 0; i < fields.size(); ++i) {
titles.add(fields.get(i).getName());
}
return titles;
}
} catch (IOException exception) {
return Collections.emptyList();
}
} | java | {
"resource": ""
} |
q15317 | DBaseFileAttributePool.getAttributeCount | train | @SuppressWarnings("resource")
@Pure
public int getAttributeCount() {
try {
final DBaseFileReader dbReader = getReader();
synchronized (dbReader) {
return dbReader.getDBFFieldCount();
}
} catch (IOException exception) {
return 0;
}
} | java | {
"resource": ""
} |
q15318 | DBaseFileAttributePool.getRawValue | train | @SuppressWarnings("resource")
@Pure
public Object getRawValue(int recordNumber, String name, OutputParameter<AttributeType> type) throws AttributeException {
try {
final DBaseFileReader dbReader = getReader();
synchronized (dbReader) {
dbReader.seek(recordNumber);
final DBaseFileRecord record = dbReader.readNextDBFRecord();
if (record != null) {
final int column = dbReader.getDBFFieldIndex(name);
if (column >= 0) {
final Object value = record.getFieldValue(column);
final DBaseFieldType dbfType = dbReader.getDBFFieldType(column);
type.set(dbfType.toAttributeType());
return value;
}
}
throw new NoAttributeFoundException(name);
}
} catch (IOException e) {
throw new AttributeException(e);
}
} | java | {
"resource": ""
} |
q15319 | EndianNumbers.toLEInt | train | @Pure
public static int toLEInt(int b1, int b2, int b3, int b4) {
return ((b4 & 0xFF) << 24) + ((b3 & 0xFF) << 16) + ((b2 & 0xFF) << 8) + (b1 & 0xFF);
} | java | {
"resource": ""
} |
q15320 | EndianNumbers.toBEInt | train | @Pure
public static int toBEInt(int b1, int b2, int b3, int b4) {
return ((b1 & 0xFF) << 24) + ((b2 & 0xFF) << 16) + ((b3 & 0xFF) << 8) + (b4 & 0xFF);
} | java | {
"resource": ""
} |
q15321 | EndianNumbers.toLELong | train | @Pure
public static long toLELong(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) {
return ((b8 & 0xFF) << 56) + ((b7 & 0xFF) << 48) + ((b6 & 0xFF) << 40) + ((b5 & 0xFF) << 32)
+ ((b4 & 0xFF) << 24) + ((b3 & 0xFF) << 16) + ((b2 & 0xFF) << 8) + (b1 & 0xFF);
} | java | {
"resource": ""
} |
q15322 | EndianNumbers.toLEDouble | train | @Pure
@Inline(value = "Double.longBitsToDouble(EndianNumbers.toLELong($1, $2, $3, $4, $5, $6, $7, $8))",
imported = {EndianNumbers.class})
public static double toLEDouble(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) {
return Double.longBitsToDouble(toLELong(b1, b2, b3, b4, b5, b6, b7, b8));
} | java | {
"resource": ""
} |
q15323 | EndianNumbers.toBEDouble | train | @Pure
@Inline(value = "Double.longBitsToDouble(EndianNumbers.toBELong($1, $2, $3, $4, $5, $6, $7, $8))",
imported = {EndianNumbers.class})
public static double toBEDouble(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) {
return Double.longBitsToDouble(toBELong(b1, b2, b3, b4, b5, b6, b7, b8));
} | java | {
"resource": ""
} |
q15324 | EndianNumbers.toLEFloat | train | @Pure
@Inline(value = "Float.intBitsToFloat(EndianNumbers.toLEInt($1, $2, $3, $4))",
imported = {EndianNumbers.class})
public static float toLEFloat(int b1, int b2, int b3, int b4) {
return Float.intBitsToFloat(toLEInt(b1, b2, b3, b4));
} | java | {
"resource": ""
} |
q15325 | EndianNumbers.toBEFloat | train | @Pure
@Inline(value = "Float.intBitsToFloat(EndianNumbers.toBEInt($1, $2, $3, $4))",
imported = {EndianNumbers.class})
public static float toBEFloat(int b1, int b2, int b3, int b4) {
return Float.intBitsToFloat(toBEInt(b1, b2, b3, b4));
} | java | {
"resource": ""
} |
q15326 | EndianNumbers.parseLEFloat | train | @Pure
@Inline(value = "EndianNumbers.parseLEInt(Float.floatToIntBits($1))",
imported = {EndianNumbers.class})
public static byte[] parseLEFloat(float value) {
return parseLEInt(Float.floatToIntBits(value));
} | java | {
"resource": ""
} |
q15327 | EndianNumbers.parseLELong | train | @Pure
public static byte[] parseLELong(long value) {
return new byte[] {
(byte) (value & 0xFF),
(byte) ((value >> 8) & 0xFF),
(byte) ((value >> 16) & 0xFF),
(byte) ((value >> 24) & 0xFF),
(byte) ((value >> 32) & 0xFF),
(byte) ((value >> 40) & 0xFF),
(byte) ((value >> 48) & 0xFF),
(byte) ((value >> 56) & 0xFF),
};
} | java | {
"resource": ""
} |
q15328 | EndianNumbers.parseLEDouble | train | @Pure
@Inline(value = "EndianNumbers.parseLELong(Double.doubleToLongBits($1))",
imported = {EndianNumbers.class})
public static byte[] parseLEDouble(double value) {
return parseLELong(Double.doubleToLongBits(value));
} | java | {
"resource": ""
} |
q15329 | EndianNumbers.parseBEFloat | train | @Pure
@Inline(value = "EndianNumbers.parseBEInt(Float.floatToIntBits($1))",
imported = {EndianNumbers.class})
public static byte[] parseBEFloat(float value) {
return parseBEInt(Float.floatToIntBits(value));
} | java | {
"resource": ""
} |
q15330 | EndianNumbers.parseBELong | train | @Pure
public static byte[] parseBELong(long value) {
return new byte[] {
(byte) ((value >> 56) & 0xFF),
(byte) ((value >> 48) & 0xFF),
(byte) ((value >> 40) & 0xFF),
(byte) ((value >> 32) & 0xFF),
(byte) ((value >> 24) & 0xFF),
(byte) ((value >> 16) & 0xFF),
(byte) ((value >> 8) & 0xFF),
(byte) (value & 0xFF),
};
} | java | {
"resource": ""
} |
q15331 | EndianNumbers.parseBEDouble | train | @Pure
@Inline(value = "EndianNumbers.parseBELong(Double.doubleToLongBits($1))",
imported = {EndianNumbers.class})
public static byte[] parseBEDouble(double value) {
return parseBELong(Double.doubleToLongBits(value));
} | java | {
"resource": ""
} |
q15332 | SubRoadNetwork.unwrap | train | @SuppressWarnings({ "unchecked", "static-method" })
@Pure
final <O> O unwrap(O obj) {
O unwrapped = obj;
if (obj instanceof TerminalConnection) {
unwrapped = (O) ((TerminalConnection) obj).getWrappedRoadConnection();
} else if (obj instanceof WrapSegment) {
unwrapped = (O) ((WrapSegment) obj).getWrappedSegment();
}
assert unwrapped != null;
return unwrapped;
} | java | {
"resource": ""
} |
q15333 | OrientedRectangle2dfx.firstAxisProperty | train | @Pure
public UnitVectorProperty firstAxisProperty() {
if (this.raxis == null) {
this.raxis = new UnitVectorProperty(this, MathFXAttributeNames.FIRST_AXIS, getGeomFactory());
}
return this.raxis;
} | java | {
"resource": ""
} |
q15334 | OrientedRectangle2dfx.secondAxisProperty | train | @Pure
public ReadOnlyUnitVectorProperty secondAxisProperty() {
if (this.saxis == null) {
this.saxis = new ReadOnlyUnitVectorWrapper(this, MathFXAttributeNames.SECOND_AXIS, getGeomFactory());
this.saxis.bind(Bindings.createObjectBinding(() -> {
final Vector2dfx firstAxis = firstAxisProperty().get();
return firstAxis.toOrthogonalVector();
},
firstAxisProperty()));
}
return this.saxis.getReadOnlyProperty();
} | java | {
"resource": ""
} |
q15335 | InfomationDialog.showInfoDialog | train | public static String showInfoDialog(final Frame owner, final String message)
{
InfomationDialog mdialog;
String ok = "OK";
mdialog = new InfomationDialog(owner, "Information message", message, ok);
@SuppressWarnings("unlikely-arg-type")
final int index = mdialog.getVButtons().indexOf(ok);
final Button button = mdialog.getVButtons().get(index);
button.addActionListener(mdialog);
mdialog.setVisible(true);
return mdialog.getResult();
} | java | {
"resource": ""
} |
q15336 | DssatCulFileInput.readFile | train | @Override
protected HashMap readFile(HashMap brMap) throws IOException {
HashMap ret = new HashMap();
HashMap metaData = new HashMap();
ArrayList<HashMap> culArr = readCultivarData(brMap, metaData);
// compressData(sites);
ArrayList<HashMap> expArr = new ArrayList();
HashMap tmp = new HashMap();
HashMap tmp2 = new HashMap();
tmp.put(jsonKey, tmp2);
tmp2.put(dataKey, culArr);
expArr.add(tmp);
ret.put("experiments", expArr);
return ret;
} | java | {
"resource": ""
} |
q15337 | TypeConfusionInspector.createOutputtingTo | train | public static <LeftRightT> TypeConfusionInspector<LeftRightT> createOutputtingTo(
final String name,
final Function<? super LeftRightT, String> confusionLabeler,
final Equivalence<LeftRightT> confusionEquivalence,
final File outputDir) {
return new TypeConfusionInspector<LeftRightT>(name, confusionLabeler, confusionEquivalence, outputDir);
} | java | {
"resource": ""
} |
q15338 | MapPolyline.distanceToEnd | train | @Pure
public double distanceToEnd(Point2D<?, ?> point, double width) {
final Point2d firstPoint = getPointAt(0);
final Point2d lastPoint = getPointAt(-1);
double d1 = firstPoint.getDistance(point);
double d2 = lastPoint.getDistance(point);
d1 -= width;
if (d1 < 0) {
d1 = 0;
}
d2 -= width;
if (d2 < 0) {
d2 = 0;
}
return d1 < d2 ? d1 : d2;
} | java | {
"resource": ""
} |
q15339 | MapPolyline.getNearestEndIndex | train | @Pure
public final int getNearestEndIndex(double x, double y, OutputParameter<Double> distance) {
final int count = getPointCount();
final Point2d firstPoint = getPointAt(0);
final Point2d lastPoint = getPointAt(count - 1);
final double d1 = Point2D.getDistancePointPoint(firstPoint.getX(), firstPoint.getY(), x, y);
final double d2 = Point2D.getDistancePointPoint(lastPoint.getX(), lastPoint.getY(), x, y);
if (d1 <= d2) {
if (distance != null) {
distance.set(d1);
}
return 0;
}
if (distance != null) {
distance.set(d2);
}
return count - 1;
} | java | {
"resource": ""
} |
q15340 | MapPolyline.getNearestPosition | train | @Pure
public Point1d getNearestPosition(Point2D<?, ?> pos) {
Point2d pp = null;
final Vector2d v = new Vector2d();
double currentPosition = 0.;
double bestPosition = Double.NaN;
double bestDistance = Double.POSITIVE_INFINITY;
for (final Point2d p : points()) {
if (pp != null) {
double position = Segment2afp.findsProjectedPointPointLine(
pos.getX(), pos.getY(),
pp.getX(), pp.getY(),
p.getX(), p.getY());
if (position < 0.) {
position = 0.;
}
if (position > 1.) {
position = 1.;
}
v.sub(p, pp);
final double t = v.getLength();
v.scale(position);
final double dist = Point2D.getDistanceSquaredPointPoint(
pos.getX(),
pos.getY(),
pp.getX() + v.getX(),
pp.getY() + v.getY());
if (dist < bestDistance) {
bestDistance = dist;
bestPosition = currentPosition + v.getLength();
}
currentPosition += t;
}
pp = p;
}
if (Double.isNaN(bestPosition)) {
return null;
}
return new Point1d(toSegment1D(), bestPosition, 0.);
} | java | {
"resource": ""
} |
q15341 | MapPolyline.getLength | train | @Pure
public double getLength() {
if (this.length < 0) {
double segmentLength = 0;
for (final PointGroup group : groups()) {
Point2d previousPts = null;
for (final Point2d pts : group.points()) {
if (previousPts != null) {
segmentLength += previousPts.getDistance(pts);
}
previousPts = pts;
}
}
this.length = segmentLength;
}
return this.length;
} | java | {
"resource": ""
} |
q15342 | MapPolyline.getSubSegmentForDistance | train | @Pure
public Segment1D<?, ?> getSubSegmentForDistance(double distance) {
final double rd = distance < 0. ? 0. : distance;
double onGoingDistance = 0.;
for (final PointGroup group : groups()) {
Point2d previousPts = null;
for (final Point2d pts : group.points()) {
if (previousPts != null) {
onGoingDistance += previousPts.getDistance(pts);
if (rd <= onGoingDistance) {
// The desired distance is on the current point pair
return new DefaultSegment1d(previousPts, pts);
}
}
previousPts = pts;
}
}
throw new IllegalArgumentException("distance must be lower or equal than getLength(); distance=" //$NON-NLS-1$
+ Double.toString(distance)
+ "; length=" //$NON-NLS-1$
+ Double.toString(getLength()));
} | java | {
"resource": ""
} |
q15343 | MapPolyline.toPath2D | train | @Pure
public final void toPath2D(Path2d path) {
// loop on parts and build the path to draw
boolean firstPoint;
for (final PointGroup grp : groups()) {
firstPoint = true;
for (final Point2d pts : grp) {
final double x = pts.getX();
final double y = pts.getY();
if (firstPoint) {
path.moveTo(x, y);
firstPoint = false;
} else {
path.lineTo(x, y);
}
}
}
} | java | {
"resource": ""
} |
q15344 | RoadPath.addPathToPath | train | public static boolean addPathToPath(RoadPath inside, RoadPath elements) {
RoadConnection first = elements.getFirstPoint();
RoadConnection last = elements.getLastPoint();
assert first != null;
assert last != null;
first = first.getWrappedRoadConnection();
last = last.getWrappedRoadConnection();
assert first != null;
assert last != null;
if (last.equals(inside.getLastPoint()) || last.equals(inside.getFirstPoint())) {
for (int i = elements.size() - 1; i >= 0; --i) {
if (!inside.add(elements.get(i))) {
return false;
}
}
} else {
for (final RoadSegment segment : elements) {
if (!inside.add(segment)) {
return false;
}
}
}
return true;
} | java | {
"resource": ""
} |
q15345 | RoadPath.isConnectableTo | train | @Pure
public boolean isConnectableTo(RoadPath path) {
assert path != null;
if (path.isEmpty()) {
return false;
}
RoadConnection first1 = getFirstPoint();
RoadConnection last1 = getLastPoint();
first1 = first1.getWrappedRoadConnection();
last1 = last1.getWrappedRoadConnection();
RoadConnection first2 = path.getFirstPoint();
RoadConnection last2 = path.getLastPoint();
first2 = first2.getWrappedRoadConnection();
last2 = last2.getWrappedRoadConnection();
return first1.equals(first2) || first1.equals(last2)
|| last1.equals(first2) || last1.equals(last2);
} | java | {
"resource": ""
} |
q15346 | RoadPath.getFirstCrossRoad | train | @Pure
public RoadConnection getFirstCrossRoad() {
for (final RoadConnection pt : points()) {
if (pt.getConnectedSegmentCount() > 2) {
return pt;
}
}
return null;
} | java | {
"resource": ""
} |
q15347 | RoadPath.getFirstJunctionPoint | train | @Pure
public CrossRoad getFirstJunctionPoint() {
RoadConnection point = getFirstPoint();
double distance = 0;
RoadSegment beforeSegment = null;
RoadSegment afterSegment = null;
int beforeSegmentIndex = -1;
int afterSegmentIndex = -1;
boolean found = false;
if (point != null) {
int index = 0;
for (final RoadSegment sgmt : this) {
if (found) {
afterSegment = sgmt;
afterSegmentIndex = index;
//stop now
break;
}
point = sgmt.getOtherSidePoint(point);
beforeSegment = sgmt;
beforeSegmentIndex = index;
distance += sgmt.getLength();
final int count = point.getConnectedSegmentCount();
if (count != 2) {
found = true;
}
++index;
}
}
if (found) {
return new CrossRoad(point, beforeSegment, beforeSegmentIndex,
afterSegment, afterSegmentIndex, distance, distance);
}
return null;
} | java | {
"resource": ""
} |
q15348 | BusLine.getFirstFreeBusLineName | train | public static String getFirstFreeBusLineName(BusNetwork network) {
if (network == null) {
return null;
}
int nb = network.getBusLineCount();
String name;
do {
++nb;
name = Locale.getString("NAME_TEMPLATE", Integer.toString(nb)); //$NON-NLS-1$
}
while (network.getBusLine(name) != null);
return name;
} | java | {
"resource": ""
} |
q15349 | BusLine.addBusItinerary | train | public boolean addBusItinerary(BusItinerary busItinerary) {
if (busItinerary == null) {
return false;
}
if (this.itineraries.indexOf(busItinerary) != -1) {
return false;
}
if (!this.itineraries.add(busItinerary)) {
return false;
}
final boolean isValidItinerary = busItinerary.isValidPrimitive();
busItinerary.setEventFirable(isEventFirable());
busItinerary.setContainer(this);
if (isEventFirable()) {
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ITINERARY_ADDED,
busItinerary,
this.itineraries.size() - 1,
"shape", //$NON-NLS-1$
null,
null));
if (!isValidItinerary) {
revalidate();
} else {
checkPrimitiveValidity();
}
}
return true;
} | java | {
"resource": ""
} |
q15350 | BusLine.removeAllBusItineraries | train | public void removeAllBusItineraries() {
for (final BusItinerary itinerary : this.itineraries) {
itinerary.setContainer(null);
itinerary.setEventFirable(true);
}
this.itineraries.clear();
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ALL_ITINERARIES_REMOVED,
null,
-1,
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
} | java | {
"resource": ""
} |
q15351 | BusLine.removeBusItinerary | train | public boolean removeBusItinerary(BusItinerary itinerary) {
final int index = this.itineraries.indexOf(itinerary);
if (index >= 0) {
return removeBusItinerary(index);
}
return false;
} | java | {
"resource": ""
} |
q15352 | BusLine.removeBusItinerary | train | public boolean removeBusItinerary(int index) {
try {
final BusItinerary busItinerary = this.itineraries.remove(index);
busItinerary.setContainer(null);
busItinerary.setEventFirable(true);
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ITINERARY_REMOVED,
busItinerary,
index,
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
return true;
} catch (Throwable exception) {
//
}
return false;
} | java | {
"resource": ""
} |
q15353 | BusLine.getBusItinerary | train | public BusItinerary getBusItinerary(UUID uuid) {
if (uuid == null) {
return null;
}
for (final BusItinerary busItinerary : this.itineraries) {
if (uuid.equals(busItinerary.getUUID())) {
return busItinerary;
}
}
return null;
} | java | {
"resource": ""
} |
q15354 | BusLine.getBusItinerary | train | public BusItinerary getBusItinerary(String name, Comparator<String> nameComparator) {
if (name == null) {
return null;
}
final Comparator<String> cmp = nameComparator == null ? BusNetworkUtilities.NAME_COMPARATOR : nameComparator;
for (final BusItinerary itinerary : this.itineraries) {
if (cmp.compare(name, itinerary.getName()) == 0) {
return itinerary;
}
}
return null;
} | java | {
"resource": ""
} |
q15355 | SerifStyleParameterFileLoader.load | train | @Override
public final Parameters load(final File configFile) throws IOException {
final Loading loading = new Loading();
loading.topLoad(configFile);
return Parameters.fromMap(loading.ret);
} | java | {
"resource": ""
} |
q15356 | DynamicURLClassLoader.findClass | train | @Override
@Pure
protected Class<?> findClass(final String name) throws ClassNotFoundException {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
@Override
public Class<?> run() throws ClassNotFoundException {
final String path = name.replace('.', '/').concat(".class"); //$NON-NLS-1$
final sun.misc.Resource res = DynamicURLClassLoader.this.ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
}
throw new ClassNotFoundException(name);
}
}, this.acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
} | java | {
"resource": ""
} |
q15357 | DynamicURLClassLoader.defineClass | train | protected Class<?> defineClass(String name, sun.misc.Resource res) throws IOException {
final int i = name.lastIndexOf('.');
final URL url = res.getCodeSourceURL();
if (i != -1) {
final String pkgname = name.substring(0, i);
// Check if package already loaded.
final Package pkg = getPackage(pkgname);
final Manifest man = res.getManifest();
if (pkg != null) {
// Package found, so check package sealing.
if (pkg.isSealed()) {
// Verify that code source URL is the same.
if (!pkg.isSealed(url)) {
throw new SecurityException(Locale.getString("E1", pkgname)); //$NON-NLS-1$
}
} else {
// Make sure we are not attempting to seal the package
// at this code source URL.
if ((man != null) && isSealed(pkgname, man)) {
throw new SecurityException(Locale.getString("E2", pkgname)); //$NON-NLS-1$
}
}
} else {
if (man != null) {
definePackage(pkgname, man, url);
} else {
definePackage(pkgname, null, null, null, null, null, null, null);
}
}
}
// Now read the class bytes and define the class
final java.nio.ByteBuffer bb = res.getByteBuffer();
if (bb != null) {
// Use (direct) ByteBuffer:
final CodeSigner[] signers = res.getCodeSigners();
final CodeSource cs = new CodeSource(url, signers);
return defineClass(name, bb, cs);
}
final byte[] b = res.getBytes();
// must read certificates AFTER reading bytes.
final CodeSigner[] signers = res.getCodeSigners();
final CodeSource cs = new CodeSource(url, signers);
return defineClass(name, b, 0, b.length, cs);
} | java | {
"resource": ""
} |
q15358 | DynamicURLClassLoader.definePackage | train | @SuppressWarnings("checkstyle:npathcomplexity")
protected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException {
final String path = name.replace('.', '/').concat("/"); //$NON-NLS-1$
String specTitle = null;
String specVersion = null;
String specVendor = null;
String implTitle = null;
String implVersion = null;
String implVendor = null;
String sealed = null;
URL sealBase = null;
Attributes attr = man.getAttributes(path);
if (attr != null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
sealed = attr.getValue(Name.SEALED);
}
attr = man.getMainAttributes();
if (attr != null) {
if (specTitle == null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
}
if (specVersion == null) {
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
}
if (specVendor == null) {
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
}
if (implTitle == null) {
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
}
if (implVersion == null) {
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
}
if (implVendor == null) {
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
}
if (sealed == null) {
sealed = attr.getValue(Name.SEALED);
}
}
if ("true".equalsIgnoreCase(sealed)) { //$NON-NLS-1$
sealBase = url;
}
return definePackage(name, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor, sealBase);
} | java | {
"resource": ""
} |
q15359 | DynamicURLClassLoader.findResource | train | @Override
@Pure
public URL findResource(final String name) {
/*
* The same restriction to finding classes applies to resources
*/
final URL url = AccessController.doPrivileged(new PrivilegedAction<URL>() {
@Override
public URL run() {
return DynamicURLClassLoader.this.ucp.findResource(name, true);
}
}, this.acc);
return url != null ? this.ucp.checkURL(url) : null;
} | java | {
"resource": ""
} |
q15360 | DynamicURLClassLoader.findResources | train | @Override
@Pure
public Enumeration<URL> findResources(final String name) throws IOException {
final Enumeration<?> e = this.ucp.findResources(name, true);
return new Enumeration<URL>() {
private URL url;
private boolean next() {
if (this.url != null) {
return true;
}
do {
final URL u = AccessController.doPrivileged(new PrivilegedAction<URL>() {
@Override
public URL run() {
if (!e.hasMoreElements()) {
return null;
}
return (URL) e.nextElement();
}
}, DynamicURLClassLoader.this.acc);
if (u == null) {
break;
}
this.url = DynamicURLClassLoader.this.ucp.checkURL(u);
}
while (this.url == null);
return this.url != null;
}
@Override
public URL nextElement() {
if (!next()) {
throw new NoSuchElementException();
}
final URL u = this.url;
this.url = null;
return u;
}
@Override
public boolean hasMoreElements() {
return next();
}
};
} | java | {
"resource": ""
} |
q15361 | DynamicURLClassLoader.getPermissions | train | @Override
protected PermissionCollection getPermissions(CodeSource codesource) {
final PermissionCollection perms = super.getPermissions(codesource);
final URL url = codesource.getLocation();
Permission permission;
URLConnection urlConnection;
try {
urlConnection = url.openConnection();
permission = urlConnection.getPermission();
} catch (IOException ioe) {
permission = null;
urlConnection = null;
}
if ((permission != null) && (permission instanceof FilePermission)) {
// if the permission has a separator char on the end,
// it means the codebase is a directory, and we need
// to add an additional permission to read recursively
String path = permission.getName();
if (path.endsWith(File.separator)) {
path += "-"; //$NON-NLS-1$
permission = new FilePermission(path, sun.security.util.SecurityConstants.FILE_READ_ACTION);
}
} else if ((permission == null) && (URISchemeType.FILE.isURL(url))) {
String path = url.getFile().replace('/', File.separatorChar);
path = sun.net.www.ParseUtil.decode(path);
if (path.endsWith(File.separator)) {
path += "-"; //$NON-NLS-1$
}
permission = new FilePermission(path, sun.security.util.SecurityConstants.FILE_READ_ACTION);
} else {
URL locUrl = url;
if (urlConnection instanceof JarURLConnection) {
locUrl = ((JarURLConnection) urlConnection).getJarFileURL();
}
String host = locUrl.getHost();
if (host == null) {
host = "localhost"; //$NON-NLS-1$
}
permission = new SocketPermission(host,
sun.security.util.SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION);
}
// make sure the person that created this class loader
// would have this permission
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final Permission fp = permission;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() throws SecurityException {
sm.checkPermission(fp);
return null;
}
}, this.acc);
}
perms.add(permission);
return perms;
} | java | {
"resource": ""
} |
q15362 | DynamicURLClassLoader.mergeClassPath | train | private static URL[] mergeClassPath(URL... urls) {
final String path = System.getProperty("java.class.path"); //$NON-NLS-1$
final String separator = System.getProperty("path.separator"); //$NON-NLS-1$
final String[] parts = path.split(Pattern.quote(separator));
final URL[] u = new URL[parts.length + urls.length];
for (int i = 0; i < parts.length; ++i) {
try {
u[i] = new File(parts[i]).toURI().toURL();
} catch (MalformedURLException exception) {
// ignore exception
}
}
System.arraycopy(urls, 0, u, parts.length, urls.length);
return u;
} | java | {
"resource": ""
} |
q15363 | ListUtil.remove | train | public static <E> int remove(List<E> list, Comparator<? super E> comparator, E data) {
assert list != null;
assert comparator != null;
assert data != null;
int first = 0;
int last = list.size() - 1;
while (last >= first) {
final int center = (first + last) / 2;
final E dt = list.get(center);
final int cmpR = comparator.compare(data, dt);
if (cmpR == 0) {
list.remove(center);
return center;
} else if (cmpR < 0) {
last = center - 1;
} else {
first = center + 1;
}
}
return -1;
} | java | {
"resource": ""
} |
q15364 | ListUtil.addIfAbsent | train | @Inline(value = "add($1, $2, $3, false, false)")
public static <E> int addIfAbsent(List<E> list, Comparator<? super E> comparator, E data) {
return add(list, comparator, data, false, false);
} | java | {
"resource": ""
} |
q15365 | ListUtil.add | train | public static <E> int add(List<E> list, Comparator<? super E> comparator, E data,
boolean allowMultipleOccurencesOfSameValue, boolean allowReplacement) {
assert list != null;
assert comparator != null;
assert data != null;
int first = 0;
int last = list.size() - 1;
while (last >= first) {
final int center = (first + last) / 2;
final E dt = list.get(center);
final int cmpR = comparator.compare(data, dt);
if (cmpR == 0 && !allowMultipleOccurencesOfSameValue) {
if (allowReplacement) {
list.set(center, data);
return center;
}
return -1;
}
if (cmpR < 0) {
last = center - 1;
} else {
first = center + 1;
}
}
list.add(first, data);
return first;
} | java | {
"resource": ""
} |
q15366 | ListUtil.contains | train | @Pure
public static <E> boolean contains(List<E> list, Comparator<? super E> comparator, E data) {
assert list != null;
assert comparator != null;
assert data != null;
int first = 0;
int last = list.size() - 1;
while (last >= first) {
final int center = (first + last) / 2;
final E dt = list.get(center);
final int cmpR = comparator.compare(data, dt);
if (cmpR == 0) {
return true;
} else if (cmpR < 0) {
last = center - 1;
} else {
first = center + 1;
}
}
return false;
} | java | {
"resource": ""
} |
q15367 | ListUtil.reverseIterator | train | public static <T> Iterator<T> reverseIterator(final List<T> list) {
return new Iterator<T>() {
private int next = list.size() - 1;
@Override
@Pure
public boolean hasNext() {
return this.next >= 0;
}
@Override
public T next() {
final int n = this.next;
--this.next;
try {
return list.get(n);
} catch (IndexOutOfBoundsException exception) {
throw new NoSuchElementException();
}
}
};
} | java | {
"resource": ""
} |
q15368 | XMLUtil.getAttributeClassWithDefault | train | @Pure
public static Class<?> getAttributeClassWithDefault(Node document, boolean caseSensitive,
Class<?> defaultValue, String... path) {
assert document != null : AssertMessages.notNullParameter(0);
final String v = getAttributeValue(document, caseSensitive, 0, path);
if (v != null && !v.isEmpty()) {
try {
final ClassLoader loader = ClassLoaderFinder.findClassLoader();
return loader.loadClass(v);
} catch (Throwable e) {
//
}
}
return defaultValue;
} | java | {
"resource": ""
} |
q15369 | XMLUtil.getChild | train | @Pure
public static <T extends Node> T getChild(Node parent, Class<T> type) {
assert parent != null : AssertMessages.notNullParameter(0);
assert type != null : AssertMessages.notNullParameter(1);
final NodeList children = parent.getChildNodes();
final int len = children.getLength();
for (int i = 0; i < len; ++i) {
final Node child = children.item(i);
if (type.isInstance(child)) {
return type.cast(child);
}
}
return null;
} | java | {
"resource": ""
} |
q15370 | XMLUtil.getDocumentFor | train | @Pure
public static Document getDocumentFor(Node node) {
Node localnode = node;
while (localnode != null) {
if (localnode instanceof Document) {
return (Document) localnode;
}
localnode = localnode.getParentNode();
}
return null;
} | java | {
"resource": ""
} |
q15371 | XMLUtil.getText | train | @Pure
public static String getText(Node document, String... path) {
assert document != null : AssertMessages.notNullParameter(0);
Node parentNode = getNodeFromPath(document, path);
if (parentNode == null) {
parentNode = document;
}
final StringBuilder text = new StringBuilder();
final NodeList children = parentNode.getChildNodes();
final int len = children.getLength();
for (int i = 0; i < len; ++i) {
final Node child = children.item(i);
if (child instanceof Text) {
text.append(((Text) child).getWholeText());
}
}
if (text.length() > 0) {
return text.toString();
}
return null;
} | java | {
"resource": ""
} |
q15372 | XMLUtil.iterate | train | @Pure
public static Iterator<Node> iterate(Node parent, String nodeName) {
assert parent != null : AssertMessages.notNullParameter(0);
assert nodeName != null && !nodeName.isEmpty() : AssertMessages.notNullParameter(0);
return new NameBasedIterator(parent, nodeName);
} | java | {
"resource": ""
} |
q15373 | XMLUtil.parseObject | train | @Pure
public static Object parseObject(String xmlSerializedObject) throws IOException, ClassNotFoundException {
assert xmlSerializedObject != null : AssertMessages.notNullParameter(0);
try (ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(xmlSerializedObject))) {
final ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
}
} | java | {
"resource": ""
} |
q15374 | XMLUtil.parseString | train | @Pure
public static byte[] parseString(String text) {
return Base64.getDecoder().decode(Strings.nullToEmpty(text).trim());
} | java | {
"resource": ""
} |
q15375 | XMLUtil.parseXML | train | @Pure
public static Document parseXML(String xmlString) {
assert xmlString != null : AssertMessages.notNullParameter(0);
try {
return readXML(new StringReader(xmlString));
} catch (Exception e) {
//
}
return null;
} | java | {
"resource": ""
} |
q15376 | XMLUtil.writeResources | train | public static void writeResources(Element node, XMLResources resources, XMLBuilder builder) {
if (resources != null) {
final Element resourcesNode = builder.createElement(NODE_RESOURCES);
for (final java.util.Map.Entry<Long, Entry> pair : resources.getPairs().entrySet()) {
final Entry e = pair.getValue();
if (e.isURL()) {
final Element resourceNode = builder.createElement(NODE_RESOURCE);
resourceNode.setAttribute(ATTR_ID, XMLResources.getStringIdentifier(pair.getKey()));
resourceNode.setAttribute(ATTR_URL, e.getURL().toExternalForm());
resourceNode.setAttribute(ATTR_MIMETYPE, e.getMimeType());
resourcesNode.appendChild(resourceNode);
} else if (e.isFile()) {
final Element resourceNode = builder.createElement(NODE_RESOURCE);
resourceNode.setAttribute(ATTR_ID, XMLResources.getStringIdentifier(pair.getKey()));
final File file = e.getFile();
final StringBuilder url = new StringBuilder();
url.append("file:"); //$NON-NLS-1$
boolean addSlash = false;
for (final String elt : FileSystem.split(file)) {
try {
if (addSlash) {
url.append("/"); //$NON-NLS-1$
}
url.append(URLEncoder.encode(elt, Charset.defaultCharset().name()));
} catch (UnsupportedEncodingException e1) {
throw new Error(e1);
}
addSlash = true;
}
resourceNode.setAttribute(ATTR_FILE, url.toString());
resourceNode.setAttribute(ATTR_MIMETYPE, e.getMimeType());
resourcesNode.appendChild(resourceNode);
} else if (e.isEmbeddedData()) {
final Element resourceNode = builder.createElement(NODE_RESOURCE);
resourceNode.setAttribute(ATTR_ID, XMLResources.getStringIdentifier(pair.getKey()));
resourceNode.setAttribute(ATTR_MIMETYPE, e.getMimeType());
final byte[] data = e.getEmbeddedData();
final CDATASection cdata = builder.createCDATASection(toString(data));
resourceNode.appendChild(cdata);
resourcesNode.appendChild(resourceNode);
}
}
if (resourcesNode.getChildNodes().getLength() > 0) {
node.appendChild(resourcesNode);
}
}
} | java | {
"resource": ""
} |
q15377 | XMLUtil.readResourceURL | train | @Pure
public static URL readResourceURL(Element node, XMLResources resources, String... path) {
final String stringValue = getAttributeValue(node, path);
if (XMLResources.isStringIdentifier(stringValue)) {
try {
final long id = XMLResources.getNumericalIdentifier(stringValue);
return resources.getResourceURL(id);
} catch (Throwable exception) {
//
}
}
return null;
} | java | {
"resource": ""
} |
q15378 | StackTraceCaller.getTraceElementAt | train | protected static StackTraceElement getTraceElementAt(int level) {
if (level < 0) {
return null;
}
try {
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
int j = -1;
boolean found = false;
Class<?> type;
for (int i = 0; i < stackTrace.length; ++i) {
if (found) {
if ((i - j) == level) {
return stackTrace[i];
}
} else {
type = loadClass(stackTrace[i].getClassName());
if (type != null && Caller.class.isAssignableFrom(type)) {
j = i + 1;
} else if (j >= 0) {
// First ocurrence of a class in the stack, after the
// inner invocation of StackTraceCaller
found = true;
if ((i - j) == level) {
return stackTrace[i];
}
}
}
}
} catch (AssertionError e) {
throw e;
} catch (Throwable exception) {
//
}
return null;
} | java | {
"resource": ""
} |
q15379 | NaryTreeNode.moveTo | train | public boolean moveTo(N newParent) {
if (newParent == null) {
return false;
}
return moveTo(newParent, newParent.getChildCount());
} | java | {
"resource": ""
} |
q15380 | NaryTreeNode.addChild | train | public final boolean addChild(int index, N newChild) {
if (newChild == null) {
return false;
}
final int count = (this.children == null) ? 0 : this.children.size();
final N oldParent = newChild.getParentNode();
if (oldParent != this && oldParent != null) {
newChild.removeFromParent();
}
final int insertionIndex;
if (this.children == null) {
this.children = newInternalList(index + 1);
}
if (index < count) {
// set the element
insertionIndex = Math.max(index, 0);
this.children.add(insertionIndex, newChild);
} else {
// Resize the array
insertionIndex = this.children.size();
this.children.add(newChild);
}
++this.notNullChildCount;
newChild.setParentNodeReference(toN(), true);
firePropertyChildAdded(insertionIndex, newChild);
return true;
} | java | {
"resource": ""
} |
q15381 | Scoreds.ByScoreThenByItem | train | public static final <T extends Comparable<T>> Ordering<Scored<T>> ByScoreThenByItem(
Ordering<T> itemOrdering) {
final Ordering<Scored<T>> byItem = itemOrdering.onResultOf(Scoreds.<T>itemsOnly());
final Ordering<Scored<T>> byScore = Scoreds.<T>ByScoreOnly();
return Ordering.compound(ImmutableList.of(byScore, byItem));
} | java | {
"resource": ""
} |
q15382 | Scoreds.ByScoreThenByItem | train | public static final <T extends Comparable<T>> Ordering<Scored<T>> ByScoreThenByItem() {
final Ordering<Scored<T>> byItem = Scoreds.<T>ByItemOnly();
final Ordering<Scored<T>> byScore = Scoreds.<T>ByScoreOnly();
return Ordering.compound(ImmutableList.of(byScore, byItem));
} | java | {
"resource": ""
} |
q15383 | OpenFileAction.onFileChoose | train | protected void onFileChoose(JFileChooser fileChooser, ActionEvent actionEvent)
{
final int returnVal = fileChooser.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
final File file = fileChooser.getSelectedFile();
onApproveOption(file, actionEvent);
}
else
{
onCancel(actionEvent);
}
} | java | {
"resource": ""
} |
q15384 | LayoutProcessor.applyLayout | train | LayoutProcessorOutput applyLayout(FileResource resource, Locale locale, Map<String, Object> model) {
Optional<Path> layout = findLayout(resource);
return layout.map(Path::toString)//
.map(Files::getFileExtension)//
.map(layoutEngines::get)
//
.orElse(lParam -> new LayoutProcessorOutput(lParam.model.get("content").toString(), "none", lParam.layoutTemplate, lParam.locale))
.apply(new LayoutParameters(layout, resource.getPath(), locale, model));
} | java | {
"resource": ""
} |
q15385 | Timex2Time.modifiedCopy | train | @Deprecated
public Timex2Time modifiedCopy(final Modifier modifier) {
return new Timex2Time(val, modifier, set, granularity, periodicity, anchorVal, anchorDir,
nonSpecific);
} | java | {
"resource": ""
} |
q15386 | MACNumber.parse | train | @Pure
public static MACNumber[] parse(String addresses) {
if ((addresses == null) || ("".equals(addresses))) { //$NON-NLS-1$
return new MACNumber[0];
}
final String[] adrs = addresses.split(Pattern.quote(Character.toString(MACNUMBER_SEPARATOR)));
final List<MACNumber> list = new ArrayList<>();
for (final String adr : adrs) {
list.add(new MACNumber(adr));
}
final MACNumber[] tab = new MACNumber[list.size()];
list.toArray(tab);
list.clear();
return tab;
} | java | {
"resource": ""
} |
q15387 | MACNumber.join | train | @Pure
public static String join(MACNumber... addresses) {
if ((addresses == null) || (addresses.length == 0)) {
return null;
}
final StringBuilder buf = new StringBuilder();
for (final MACNumber number : addresses) {
if (buf.length() > 0) {
buf.append(MACNUMBER_SEPARATOR);
}
buf.append(number);
}
return buf.toString();
} | java | {
"resource": ""
} |
q15388 | MACNumber.getAllAdapters | train | @Pure
public static Collection<MACNumber> getAllAdapters() {
final List<MACNumber> av = new ArrayList<>();
final Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException exception) {
return av;
}
if (interfaces != null) {
NetworkInterface inter;
while (interfaces.hasMoreElements()) {
inter = interfaces.nextElement();
try {
final byte[] addr = inter.getHardwareAddress();
if (addr != null) {
av.add(new MACNumber(addr));
}
} catch (SocketException exception) {
// Continue to the next loop.
}
}
}
return av;
} | java | {
"resource": ""
} |
q15389 | MACNumber.getAllMappings | train | @Pure
public static Map<InetAddress, MACNumber> getAllMappings() {
final Map<InetAddress, MACNumber> av = new HashMap<>();
final Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException exception) {
return av;
}
if (interfaces != null) {
NetworkInterface inter;
MACNumber mac;
InetAddress inet;
while (interfaces.hasMoreElements()) {
inter = interfaces.nextElement();
try {
final byte[] addr = inter.getHardwareAddress();
if (addr != null) {
mac = new MACNumber(addr);
final Enumeration<InetAddress> inets = inter.getInetAddresses();
while (inets.hasMoreElements()) {
inet = inets.nextElement();
av.put(inet, mac);
}
}
} catch (SocketException exception) {
// Continue to the next loop.
}
}
}
return av;
} | java | {
"resource": ""
} |
q15390 | MACNumber.getPrimaryAdapter | train | @Pure
public static MACNumber getPrimaryAdapter() {
final Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException exception) {
return null;
}
if (interfaces != null) {
NetworkInterface inter;
while (interfaces.hasMoreElements()) {
inter = interfaces.nextElement();
try {
final byte[] addr = inter.getHardwareAddress();
if (addr != null) {
return new MACNumber(addr);
}
} catch (SocketException exception) {
// Continue to the next loop.
}
}
}
return null;
} | java | {
"resource": ""
} |
q15391 | MACNumber.getPrimaryAdapterAddresses | train | @Pure
public static Collection<InetAddress> getPrimaryAdapterAddresses() {
final Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException exception) {
return Collections.emptyList();
}
if (interfaces != null) {
NetworkInterface inter;
while (interfaces.hasMoreElements()) {
inter = interfaces.nextElement();
try {
final byte[] addr = inter.getHardwareAddress();
if (addr != null) {
final Collection<InetAddress> inetList = new ArrayList<>();
final Enumeration<InetAddress> inets = inter.getInetAddresses();
while (inets.hasMoreElements()) {
inetList.add(inets.nextElement());
}
return inetList;
}
} catch (SocketException exception) {
// Continue to the next loop.
}
}
}
return Collections.emptyList();
} | java | {
"resource": ""
} |
q15392 | MACNumber.isNull | train | @Pure
public boolean isNull() {
for (int i = 0; i < this.bytes.length; ++i) {
if (this.bytes[i] != 0) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q15393 | AnnotatedNYTDocument.getSourcePath | train | public Optional<Path> getSourcePath() {
File f = this.nytdoc.getSourceFile();
return f == null ? Optional.empty() : Optional.of(f.toPath());
} | java | {
"resource": ""
} |
q15394 | AnnotatedNYTDocument.getUrl | train | public Optional<URL> getUrl() {
URL u = this.nytdoc.getUrl();
return Optional.ofNullable(u);
} | java | {
"resource": ""
} |
q15395 | AuthorizationFile.load | train | public void load(File authorizationFile) throws AuthorizationFileException {
FileInputStream fis = null;
try {
fis = new FileInputStream(authorizationFile);
ANTLRInputStream stream = new ANTLRInputStream(fis);
SAFPLexer lexer = new SAFPLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SAFPParser parser = new SAFPParser(tokens);
parser.prog();
setAccessRules(parser.getAccessRules());
setGroups(parser.getGroups());
setAliases(parser.getAliases());
} catch (FileNotFoundException e) {
throw new AuthorizationFileException("FileNotFoundException: ", e);
} catch (IOException e) {
throw new AuthorizationFileException("IOException: ", e);
} catch (RecognitionException e) {
throw new AuthorizationFileException("Parser problem: ", e);
} finally {
try {
fis.close();
} catch (IOException e) {
throw new AuthorizationFileException("IOExcetion during close: ", e);
}
}
} | java | {
"resource": ""
} |
q15396 | KeyStoreExtensions.deleteAlias | train | public static void deleteAlias(final File keystoreFile, String alias, final String password)
throws NoSuchAlgorithmException, CertificateException, FileNotFoundException,
KeyStoreException, IOException
{
KeyStore keyStore = KeyStoreFactory.newKeyStore(KeystoreType.JKS.name(), password,
keystoreFile);
keyStore.deleteEntry(alias);
keyStore.store(new FileOutputStream(keystoreFile), password.toCharArray());
} | java | {
"resource": ""
} |
q15397 | CompressFilterSettings.setResponseCompressionEnabled | train | @Nonnull
public static EChange setResponseCompressionEnabled (final boolean bResponseCompressionEnabled)
{
return s_aRWLock.writeLocked ( () -> {
if (s_bResponseCompressionEnabled == bResponseCompressionEnabled)
return EChange.UNCHANGED;
s_bResponseCompressionEnabled = bResponseCompressionEnabled;
LOGGER.info ("CompressFilter responseCompressionEnabled=" + bResponseCompressionEnabled);
return EChange.CHANGED;
});
} | java | {
"resource": ""
} |
q15398 | CompressFilterSettings.setDebugModeEnabled | train | @Nonnull
public static EChange setDebugModeEnabled (final boolean bDebugModeEnabled)
{
return s_aRWLock.writeLocked ( () -> {
if (s_bDebugModeEnabled == bDebugModeEnabled)
return EChange.UNCHANGED;
s_bDebugModeEnabled = bDebugModeEnabled;
LOGGER.info ("CompressFilter debugMode=" + bDebugModeEnabled);
return EChange.CHANGED;
});
} | java | {
"resource": ""
} |
q15399 | GenomicsConverter.makeSAMFileHeader | train | @Override
public SAMFileHeader makeSAMFileHeader(ReadGroupSet readGroupSet,
List<Reference> references) {
return ReadUtils.makeSAMFileHeader(readGroupSet, references);
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.