_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q14800
Vector2d.convert
train
public static Vector2d convert(Tuple2D<?> tuple) { if (tuple instanceof Vector2d) { return (Vector2d) tuple; } return new Vector2d(tuple.getX(), tuple.getY()); }
java
{ "resource": "" }
q14801
BusNetwork.addBusLine
train
public boolean addBusLine(BusLine busLine) { if (busLine == null) { return false; } if (this.busLines.indexOf(busLine) != -1) { return false; } if (!this.busLines.add(busLine)) { return false; } final boolean isValidLine = busLine.isValidPrimitive(); busLine.setEventFirable(isEventFirable()); busLine.setContainer(this); if (isEventFirable()) { fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.LINE_ADDED, busLine, this.busLines.size() - 1, "shape", //$NON-NLS-1$ null, null)); if (!isValidLine) { revalidate(); } else { checkPrimitiveValidity(); } } return true; }
java
{ "resource": "" }
q14802
BusNetwork.removeAllBusLines
train
public void removeAllBusLines() { for (final BusLine busline : this.busLines) { busline.setContainer(null); busline.setEventFirable(true); } this.busLines.clear(); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ALL_LINES_REMOVED, null, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); }
java
{ "resource": "" }
q14803
BusNetwork.removeBusLine
train
public boolean removeBusLine(BusLine busLine) { final int index = this.busLines.indexOf(busLine); if (index >= 0) { return removeBusLine(index); } return false; }
java
{ "resource": "" }
q14804
BusNetwork.removeBusLine
train
public boolean removeBusLine(String name) { final Iterator<BusLine> iterator = this.busLines.iterator(); BusLine busLine; int i = 0; while (iterator.hasNext()) { busLine = iterator.next(); if (name.equals(busLine.getName())) { iterator.remove(); busLine.setContainer(null); busLine.setEventFirable(true); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.LINE_REMOVED, busLine, i, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } ++i; } return false; }
java
{ "resource": "" }
q14805
BusNetwork.removeBusLine
train
public boolean removeBusLine(int index) { try { final BusLine busLine = this.busLines.remove(index); busLine.setContainer(null); busLine.setEventFirable(true); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.LINE_REMOVED, busLine, index, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } catch (Throwable exception) { // } return false; }
java
{ "resource": "" }
q14806
BusNetwork.getBusLine
train
@Pure public BusLine getBusLine(UUID uuid) { if (uuid == null) { return null; } for (final BusLine busLine : this.busLines) { if (uuid.equals(busLine.getUUID())) { return busLine; } } return null; }
java
{ "resource": "" }
q14807
BusNetwork.getBusLine
train
@Pure public BusLine getBusLine(String name, Comparator<String> nameComparator) { if (name == null) { return null; } final Comparator<String> cmp = nameComparator == null ? BusNetworkUtilities.NAME_COMPARATOR : nameComparator; for (final BusLine busLine : this.busLines) { if (cmp.compare(name, busLine.getName()) == 0) { return busLine; } } return null; }
java
{ "resource": "" }
q14808
BusNetwork.addBusStop
train
public boolean addBusStop(BusStop busStop) { if (busStop == null) { return false; } if (this.validBusStops.contains(busStop)) { return false; } if (ListUtil.contains(this.invalidBusStops, INVALID_STOP_COMPARATOR, busStop)) { return false; } final boolean isValidPrimitive = busStop.isValidPrimitive(); if (isValidPrimitive) { if (!this.validBusStops.add(busStop)) { return false; } } else if (ListUtil.addIfAbsent(this.invalidBusStops, INVALID_STOP_COMPARATOR, busStop) < 0) { return false; } busStop.setEventFirable(isEventFirable()); busStop.setContainer(this); if (isEventFirable()) { fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.STOP_ADDED, busStop, -1, "shape", //$NON-NLS-1$ null, null)); busStop.checkPrimitiveValidity(); checkPrimitiveValidity(); } return true; }
java
{ "resource": "" }
q14809
BusNetwork.removeAllBusStops
train
public void removeAllBusStops() { for (final BusStop busStop : this.validBusStops) { busStop.setContainer(null); busStop.setEventFirable(true); } for (final BusStop busStop : this.invalidBusStops) { busStop.setContainer(null); busStop.setEventFirable(true); } this.validBusStops.clear(); this.invalidBusStops.clear(); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ALL_STOPS_REMOVED, null, -1, "shape", //$NON-NLS-1$ null, null)); revalidate(); }
java
{ "resource": "" }
q14810
BusNetwork.removeBusStop
train
public boolean removeBusStop(BusStop busStop) { if (this.validBusStops.remove(busStop)) { busStop.setContainer(null); busStop.setEventFirable(true); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.STOP_REMOVED, busStop, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } final int idx = ListUtil.remove(this.invalidBusStops, INVALID_STOP_COMPARATOR, busStop); if (idx >= 0) { busStop.setContainer(null); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.STOP_REMOVED, busStop, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } return false; }
java
{ "resource": "" }
q14811
BusNetwork.removeBusStop
train
public boolean removeBusStop(String name) { Iterator<BusStop> iterator; BusStop busStop; iterator = this.validBusStops.iterator(); while (iterator.hasNext()) { busStop = iterator.next(); if (name.equals(busStop.getName())) { iterator.remove(); busStop.setContainer(null); busStop.setEventFirable(true); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.STOP_REMOVED, busStop, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } } iterator = this.invalidBusStops.iterator(); while (iterator.hasNext()) { busStop = iterator.next(); if (name.equals(busStop.getName())) { iterator.remove(); busStop.setContainer(null); fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.STOP_REMOVED, busStop, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); return true; } } return false; }
java
{ "resource": "" }
q14812
BusNetwork.getBusStop
train
@Pure public BusStop getBusStop(UUID id) { if (id == null) { return null; } for (final BusStop busStop : this.validBusStops) { final UUID busid = busStop.getUUID(); if (id.equals(busid)) { return busStop; } } for (final BusStop busStop : this.invalidBusStops) { final UUID busid = busStop.getUUID(); if (id.equals(busid)) { return busStop; } } return null; }
java
{ "resource": "" }
q14813
BusNetwork.getBusStop
train
@Pure public BusStop getBusStop(String name, Comparator<String> nameComparator) { if (name == null) { return null; } final Comparator<String> cmp = nameComparator == null ? BusNetworkUtilities.NAME_COMPARATOR : nameComparator; for (final BusStop busStop : this.validBusStops) { if (cmp.compare(name, busStop.getName()) == 0) { return busStop; } } for (final BusStop busStop : this.invalidBusStops) { if (cmp.compare(name, busStop.getName()) == 0) { return busStop; } } return null; }
java
{ "resource": "" }
q14814
BusNetwork.getBusStopsIn
train
@Pure public Iterator<BusStop> getBusStopsIn(Rectangle2afp<?, ?, ?, ?, ?, ?> clipBounds) { return Iterators.unmodifiableIterator( this.validBusStops.iterator(clipBounds)); }
java
{ "resource": "" }
q14815
BusNetwork.getNearestBusStop
train
@Pure public BusStop getNearestBusStop(double x, double y) { double distance = Double.POSITIVE_INFINITY; BusStop bestStop = null; double dist; for (final BusStop stop : this.validBusStops) { dist = stop.distance(x, y); if (dist < distance) { distance = dist; bestStop = stop; } } return bestStop; }
java
{ "resource": "" }
q14816
BusNetwork.addBusHub
train
private boolean addBusHub(BusHub hub) { if (hub == null) { return false; } if (this.validBusHubs.contains(hub)) { return false; } if (ListUtil.contains(this.invalidBusHubs, INVALID_HUB_COMPARATOR, hub)) { return false; } final boolean isValidPrimitive = hub.isValidPrimitive(); if (isValidPrimitive) { if (!this.validBusHubs.add(hub)) { return false; } } else if (ListUtil.addIfAbsent(this.invalidBusHubs, INVALID_HUB_COMPARATOR, hub) < 0) { return false; } hub.setEventFirable(isEventFirable()); hub.setContainer(this); if (isEventFirable()) { firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.HUB_ADDED, hub, -1, null, null, null)); hub.checkPrimitiveValidity(); checkPrimitiveValidity(); } return true; }
java
{ "resource": "" }
q14817
BusNetwork.removeAllBusHubs
train
public void removeAllBusHubs() { for (final BusHub busHub : this.validBusHubs) { busHub.setContainer(null); busHub.setEventFirable(true); } for (final BusHub busHub : this.invalidBusHubs) { busHub.setContainer(null); busHub.setEventFirable(true); } this.validBusHubs.clear(); this.invalidBusHubs.clear(); firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.ALL_HUBS_REMOVED, null, -1, null, null, null)); revalidate(); }
java
{ "resource": "" }
q14818
BusNetwork.removeBusHub
train
public boolean removeBusHub(BusHub busHub) { if (this.validBusHubs.remove(busHub)) { busHub.setContainer(null); busHub.setEventFirable(true); firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.HUB_REMOVED, busHub, -1, null, null, null)); checkPrimitiveValidity(); return true; } final int idx = ListUtil.remove(this.invalidBusHubs, INVALID_HUB_COMPARATOR, busHub); if (idx >= 0) { busHub.setContainer(null); busHub.setEventFirable(true); firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.HUB_REMOVED, busHub, -1, null, null, null)); checkPrimitiveValidity(); return true; } return false; }
java
{ "resource": "" }
q14819
BusNetwork.removeBusHub
train
public boolean removeBusHub(String name) { Iterator<BusHub> iterator; BusHub busHub; iterator = this.validBusHubs.iterator(); while (iterator.hasNext()) { busHub = iterator.next(); if (name.equals(busHub.getName())) { iterator.remove(); busHub.setContainer(null); busHub.setEventFirable(true); firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.HUB_REMOVED, busHub, -1, null, null, null)); checkPrimitiveValidity(); return true; } } iterator = this.invalidBusHubs.iterator(); while (iterator.hasNext()) { busHub = iterator.next(); if (name.equals(busHub.getName())) { iterator.remove(); busHub.setContainer(null); firePrimitiveChanged(new BusChangeEvent(this, BusChangeEventType.HUB_REMOVED, busHub, -1, null, null, null)); checkPrimitiveValidity(); return true; } } return false; }
java
{ "resource": "" }
q14820
BusNetwork.getBusHub
train
@Pure public BusHub getBusHub(UUID uuid) { if (uuid == null) { return null; } for (final BusHub busHub : this.validBusHubs) { if (uuid.equals(busHub.getUUID())) { return busHub; } } for (final BusHub busHub : this.invalidBusHubs) { if (uuid.equals(busHub.getUUID())) { return busHub; } } return null; }
java
{ "resource": "" }
q14821
BusNetwork.getBusHub
train
@Pure public BusHub getBusHub(String name, Comparator<String> nameComparator) { if (name == null) { return null; } final Comparator<String> cmp = nameComparator == null ? BusNetworkUtilities.NAME_COMPARATOR : nameComparator; for (final BusHub busHub : this.validBusHubs) { if (cmp.compare(name, busHub.getName()) == 0) { return busHub; } } for (final BusHub busHub : this.invalidBusHubs) { if (cmp.compare(name, busHub.getName()) == 0) { return busHub; } } return null; }
java
{ "resource": "" }
q14822
BusNetwork.getBusHubsIn
train
@Pure public Iterator<BusHub> getBusHubsIn(Rectangle2afp<?, ?, ?, ?, ?, ?> clipBounds) { return Iterators.unmodifiableIterator( this.validBusHubs.iterator(clipBounds)); }
java
{ "resource": "" }
q14823
Property.setValue
train
public void setValue(Object instance, Object value) { try { setMethod.invoke(instance, value); } catch (Exception e) { throw new PropertyNotFoundException(klass, getType(), fieldName); } }
java
{ "resource": "" }
q14824
Vector3dfx.convert
train
public static Vector3dfx convert(Tuple3D<?> tuple) { if (tuple instanceof Vector3dfx) { return (Vector3dfx) tuple; } return new Vector3dfx(tuple.getX(), tuple.getY(), tuple.getZ()); }
java
{ "resource": "" }
q14825
GenericShuffleTableModel.shuffleSelectedRightRowToLeftTableModel
train
public void shuffleSelectedRightRowToLeftTableModel(final int selectedRow) { if (-1 < selectedRow) { final T row = rightTableModel.removeAt(selectedRow); leftTableModel.add(row); } }
java
{ "resource": "" }
q14826
LocatedString.startReferenceOffsetsForContentOffset
train
public OffsetGroup startReferenceOffsetsForContentOffset(CharOffset contentOffset) { return characterRegions().get(regionIndexContainingContentOffset(contentOffset)) .startOffsetGroupForPosition(contentOffset); }
java
{ "resource": "" }
q14827
LocatedString.endReferenceOffsetsForContentOffset
train
public OffsetGroup endReferenceOffsetsForContentOffset(CharOffset contentOffset) { return characterRegions().get(regionIndexContainingContentOffset(contentOffset)) .endOffsetGroupForPosition(contentOffset); }
java
{ "resource": "" }
q14828
LocatedString.referenceSubstringByContentOffsets
train
public final Optional<UnicodeFriendlyString> referenceSubstringByContentOffsets( final OffsetRange<CharOffset> contentOffsets) { if (referenceString().isPresent()) { return Optional.of(referenceString().get().substringByCodePoints( OffsetGroupRange.from( startReferenceOffsetsForContentOffset(contentOffsets.startInclusive()), endReferenceOffsetsForContentOffset(contentOffsets.endInclusive())) .asCharOffsetRange())); } else { return Optional.absent(); } }
java
{ "resource": "" }
q14829
GeodesicPosition.getLatitudeMinute
train
@SuppressWarnings("checkstyle:localvariablename") @Pure public int getLatitudeMinute() { double p = Math.abs(this.phi); p = p - (int) p; return (int) (p * 60.); }
java
{ "resource": "" }
q14830
GeodesicPosition.getLatitudeSecond
train
@SuppressWarnings("checkstyle:localvariablename") @Pure public double getLatitudeSecond() { double p = Math.abs(this.phi); p = (p - (int) p) * 60.; p = p - (int) p; return p * 60.; }
java
{ "resource": "" }
q14831
GeodesicPosition.getLongitudeMinute
train
@SuppressWarnings("checkstyle:localvariablename") @Pure public int getLongitudeMinute() { double l = Math.abs(this.lambda); l = l - (int) l; return (int) (l * 60.); }
java
{ "resource": "" }
q14832
GeodesicPosition.getLongitudeSecond
train
@SuppressWarnings("checkstyle:localvariablename") @Pure public double getLongitudeSecond() { double p = Math.abs(this.lambda); p = (p - (int) p) * 60.; p = p - (int) p; return p * 60.; }
java
{ "resource": "" }
q14833
GeodesicPosition.setPreferredStringRepresentation
train
public static void setPreferredStringRepresentation(GeodesicPositionStringRepresentation representation, boolean useSymbolicDirection) { final Preferences prefs = Preferences.userNodeForPackage(GeodesicPosition.class); if (prefs != null) { if (representation == null) { prefs.remove("STRING_REPRESENTATION"); //$NON-NLS-1$ prefs.remove("SYMBOL_IN_STRING_REPRESENTATION"); //$NON-NLS-1$ } else { prefs.put("STRING_REPRESENTATION", representation.toString()); //$NON-NLS-1$ prefs.putBoolean("SYMBOL_IN_STRING_REPRESENTATION", useSymbolicDirection); //$NON-NLS-1$ } } }
java
{ "resource": "" }
q14834
GeodesicPosition.getPreferredStringRepresentation
train
@Pure public static GeodesicPositionStringRepresentation getPreferredStringRepresentation(boolean allowNullValue) { final Preferences prefs = Preferences.userNodeForPackage(GeodesicPosition.class); if (prefs != null) { final String v = prefs.get("STRING_REPRESENTATION", null); //$NON-NLS-1$ if (v != null && !"".equals(v)) { //$NON-NLS-1$ try { GeodesicPositionStringRepresentation rep; try { rep = GeodesicPositionStringRepresentation.valueOf(v.toUpperCase()); } catch (Throwable exception) { rep = null; } if (rep != null) { return rep; } } catch (AssertionError e) { throw e; } catch (Throwable exception) { // } } } if (allowNullValue) { return null; } return DEFAULT_STRING_REPRESENTATION; }
java
{ "resource": "" }
q14835
GeodesicPosition.getDirectionSymbolInPreferredStringRepresentation
train
@Pure public static boolean getDirectionSymbolInPreferredStringRepresentation() { final Preferences prefs = Preferences.userNodeForPackage(GeodesicPosition.class); if (prefs != null) { return prefs.getBoolean("SYMBOL_IN_STRING_REPRESENTATION", DEFAULT_SYMBOL_IN_STRING_REPRESENTATION); //$NON-NLS-1$ } return DEFAULT_SYMBOL_IN_STRING_REPRESENTATION; }
java
{ "resource": "" }
q14836
AbstractForest.addForestListener
train
public synchronized void addForestListener(ForestListener listener) { if (this.listeners == null) { this.listeners = new ArrayList<>(); } this.listeners.add(listener); }
java
{ "resource": "" }
q14837
AbstractForest.removeForestListener
train
public synchronized void removeForestListener(ForestListener listener) { if (this.listeners != null) { this.listeners.remove(listener); if (this.listeners.isEmpty()) { this.listeners = null; } } }
java
{ "resource": "" }
q14838
Log4jIntegrationModule.getLog4jIntegrationConfig
train
@SuppressWarnings("static-method") @Provides @Singleton public Log4jIntegrationConfig getLog4jIntegrationConfig(ConfigurationFactory configFactory, Injector injector) { final Log4jIntegrationConfig config = Log4jIntegrationConfig.getConfiguration(configFactory); injector.injectMembers(config); return config; }
java
{ "resource": "" }
q14839
Log4jIntegrationModule.provideRootLogger
train
@SuppressWarnings("static-method") @Singleton @Provides public Logger provideRootLogger(ConfigurationFactory configFactory, Provider<Log4jIntegrationConfig> config) { final Logger root = Logger.getRootLogger(); // Reroute JUL SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); final Log4jIntegrationConfig cfg = config.get(); if (!cfg.getUseLog4jConfig()) { cfg.configureLogger(root); } return root; }
java
{ "resource": "" }
q14840
NetworkSettingsPanel.onInitializeComponents
train
@Override protected void onInitializeComponents() { lpNoProxy = new JLayeredPane(); lpNoProxy.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null)); lpHostOrIpaddress = new JLayeredPane(); lpHostOrIpaddress.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null)); rdbtnManualProxyConfiguration = new JRadioButton("Manual proxy configuration"); rdbtnManualProxyConfiguration.setBounds(6, 7, 313, 23); lpHostOrIpaddress.add(rdbtnManualProxyConfiguration); lblHostOrIpaddress = new JLabel("Host or IP-address:"); lblHostOrIpaddress.setBounds(26, 37, 109, 14); lpHostOrIpaddress.add(lblHostOrIpaddress); txtHostOrIpaddress = new JTextField(); txtHostOrIpaddress.setBounds(145, 37, 213, 20); lpHostOrIpaddress.add(txtHostOrIpaddress); txtHostOrIpaddress.setColumns(10); lblPort = new JLabel("Port:"); lblPort.setBounds(368, 40, 46, 14); lpHostOrIpaddress.add(lblPort); txtPort = new JTextField(); txtPort.setBounds(408, 37, 67, 20); lpHostOrIpaddress.add(txtPort); txtPort.setColumns(10); rdbtnNoProxy = new JRadioButton("Direct connection to internet (no proxy)"); rdbtnNoProxy.setBounds(6, 7, 305, 23); lpNoProxy.add(rdbtnNoProxy); lpUseSystemSettings = new JLayeredPane(); lpUseSystemSettings.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null)); rdbtnUseSystemSettings = new JRadioButton("Use proxy settings from system"); rdbtnUseSystemSettings.setBounds(6, 7, 305, 23); lpUseSystemSettings.add(rdbtnUseSystemSettings); // Group the radio buttons. btngrpProxySettings = new ButtonGroup(); btngrpProxySettings.add(rdbtnNoProxy); btngrpProxySettings.add(rdbtnManualProxyConfiguration); chckbxSocksProxy = new JCheckBox("SOCKS-Proxy?"); chckbxSocksProxy.setToolTipText("Is it a SOCKS-Proxy?"); chckbxSocksProxy.setBounds(26, 63, 97, 23); lpHostOrIpaddress.add(chckbxSocksProxy); btngrpProxySettings.add(rdbtnUseSystemSettings); }
java
{ "resource": "" }
q14841
BusNetworkUtilities.getBusHalts
train
@Pure public static Iterator<BusItineraryHalt> getBusHalts(BusLine busLine) { assert busLine != null; return new LineHaltIterator(busLine); }
java
{ "resource": "" }
q14842
BusNetworkUtilities.getBusHalts
train
@Pure public static Iterator<BusItineraryHalt> getBusHalts(BusNetwork busNetwork) { assert busNetwork != null; return new NetworkHaltIterator(busNetwork); }
java
{ "resource": "" }
q14843
JSR303ValidationInterceptor.getActionMethod
train
protected Method getActionMethod(Class actionClass, String methodName) throws NoSuchMethodException { Method method; try { method = actionClass.getMethod(methodName, new Class[0]); } catch (NoSuchMethodException e) { // hmm -- OK, try doXxx instead try { String altMethodName = "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1); method = actionClass.getMethod(altMethodName, new Class[0]); } catch (NoSuchMethodException e1) { // throw the original one throw e; } } return method; }
java
{ "resource": "" }
q14844
DssatAFileOutput.cutYear
train
private String cutYear(String str) { if (str.length() > 3) { return str.substring(str.length() - 3, str.length()); } else { return str; } }
java
{ "resource": "" }
q14845
Plane4d.getPivot
train
@Override public Point3d getPivot() { Point3d pivot = this.cachedPivot == null ? null : this.cachedPivot.get(); if (pivot==null) { pivot = getProjection(0., 0., 0.); this.cachedPivot = new WeakReference<>(pivot); } return pivot; }
java
{ "resource": "" }
q14846
FileSystem.decodeHTMLEntities
train
private static String decodeHTMLEntities(String string) { if (string == null) { return null; } try { return URLDecoder.decode(string, Charset.defaultCharset().displayName()); } catch (UnsupportedEncodingException exception) { return string; } }
java
{ "resource": "" }
q14847
FileSystem.encodeHTMLEntities
train
private static String encodeHTMLEntities(String string) { if (string == null) { return null; } try { return URLEncoder.encode(string, Charset.defaultCharset().displayName()); } catch (UnsupportedEncodingException exception) { return string; } }
java
{ "resource": "" }
q14848
FileSystem.isJarURL
train
@Pure @Inline(value = "URISchemeType.JAR.isURL($1)", imported = {URISchemeType.class}) public static boolean isJarURL(URL url) { return URISchemeType.JAR.isURL(url); }
java
{ "resource": "" }
q14849
FileSystem.getJarURL
train
@Pure public static URL getJarURL(URL url) { if (!isJarURL(url)) { return null; } String path = url.getPath(); final int idx = path.lastIndexOf(JAR_URL_FILE_ROOT); if (idx >= 0) { path = path.substring(0, idx); } try { return new URL(path); } catch (MalformedURLException exception) { return null; } }
java
{ "resource": "" }
q14850
FileSystem.getJarFile
train
@Pure public static File getJarFile(URL url) { if (isJarURL(url)) { final String path = url.getPath(); final int idx = path.lastIndexOf(JAR_URL_FILE_ROOT); if (idx >= 0) { return new File(decodeHTMLEntities(path.substring(idx + 1))); } } return null; }
java
{ "resource": "" }
q14851
FileSystem.isCaseSensitiveFilenameSystem
train
@Pure public static boolean isCaseSensitiveFilenameSystem() { switch (OperatingSystem.getCurrentOS()) { case AIX: case ANDROID: case BSD: case FREEBSD: case NETBSD: case OPENBSD: case LINUX: case SOLARIS: case HPUX: return true; //$CASES-OMITTED$ default: return false; } }
java
{ "resource": "" }
q14852
FileSystem.extension
train
@Pure public static String extension(File filename) { if (filename == null) { return null; } final String largeBasename = largeBasename(filename); final int idx = largeBasename.lastIndexOf(getFileExtensionCharacter()); if (idx <= 0) { return ""; //$NON-NLS-1$ } return largeBasename.substring(idx); }
java
{ "resource": "" }
q14853
FileSystem.hasExtension
train
@Pure public static boolean hasExtension(File filename, String extension) { if (filename == null) { return false; } assert extension != null; String extent = extension; if (!"".equals(extent) && !extent.startsWith(EXTENSION_SEPARATOR)) { //$NON-NLS-1$ extent = EXTENSION_SEPARATOR + extent; } final String ext = extension(filename); if (ext == null) { return false; } if (isCaseSensitiveFilenameSystem()) { return ext.equals(extent); } return ext.equalsIgnoreCase(extent); }
java
{ "resource": "" }
q14854
FileSystem.getSystemConfigurationDirectoryFor
train
@Pure public static File getSystemConfigurationDirectoryFor(String software) { if (software == null || "".equals(software)) { //$NON-NLS-1$ throw new IllegalArgumentException(); } final OperatingSystem os = OperatingSystem.getCurrentOS(); if (os == OperatingSystem.ANDROID) { return join(File.listRoots()[0], Android.CONFIGURATION_DIRECTORY, Android.makeAndroidApplicationName(software)); } else if (os.isUnixCompliant()) { final File[] roots = File.listRoots(); return join(roots[0], "etc", software); //$NON-NLS-1$ } else if (os == OperatingSystem.WIN) { File pfDirectory; for (final File root : File.listRoots()) { pfDirectory = new File(root, "Program Files"); //$NON-NLS-1$ if (pfDirectory.isDirectory()) { return new File(root, software); } } } return null; }
java
{ "resource": "" }
q14855
FileSystem.getSystemSharedLibraryDirectoryNameFor
train
@Pure public static String getSystemSharedLibraryDirectoryNameFor(String software) { final File f = getSystemSharedLibraryDirectoryFor(software); if (f == null) { return null; } return f.getAbsolutePath(); }
java
{ "resource": "" }
q14856
FileSystem.convertStringToFile
train
@Pure public static File convertStringToFile(String filename) { if (filename == null || "".equals(filename)) { //$NON-NLS-1$ return null; } if (isWindowsNativeFilename(filename)) { return normalizeWindowsNativeFilename(filename); } // Test for malformed filenames. return new File(extractLocalPath(filename).replaceAll( Pattern.quote(UNIX_SEPARATOR_STRING), Matcher.quoteReplacement(File.separator))); }
java
{ "resource": "" }
q14857
FileSystem.convertURLToFile
train
@Pure @SuppressWarnings("checkstyle:npathcomplexity") public static File convertURLToFile(URL url) { URL theUrl = url; if (theUrl == null) { return null; } if (URISchemeType.RESOURCE.isURL(theUrl)) { theUrl = Resources.getResource(decodeHTMLEntities(theUrl.getFile())); if (theUrl == null) { theUrl = url; } } URI uri; try { // this is the step that can fail, and so // it should be this step that should be fixed uri = theUrl.toURI(); } catch (URISyntaxException e) { // OK if we are here, then obviously the URL did // not comply with RFC 2396. This can only // happen if we have illegal unescaped characters. // If we have one unescaped character, then // the only automated fix we can apply, is to assume // all characters are unescaped. // If we want to construct a URI from unescaped // characters, then we have to use the component // constructors: try { uri = new URI(theUrl.getProtocol(), theUrl.getUserInfo(), theUrl.getHost(), theUrl.getPort(), decodeHTMLEntities(theUrl.getPath()), decodeHTMLEntities(theUrl.getQuery()), theUrl.getRef()); } catch (URISyntaxException e1) { // The URL is broken beyond automatic repair throw new IllegalArgumentException(Locale.getString("E1", theUrl)); //$NON-NLS-1$ } } if (uri != null && URISchemeType.FILE.isURI(uri)) { final String auth = uri.getAuthority(); String path = uri.getPath(); if (path == null) { path = uri.getRawPath(); } if (path == null) { path = uri.getSchemeSpecificPart(); } if (path == null) { path = uri.getRawSchemeSpecificPart(); } if (path != null) { if (auth == null || "".equals(auth)) { //$NON-NLS-1$ // absolute filename in URI path = decodeHTMLEntities(path); } else { // relative filename in URI, extract it directly path = decodeHTMLEntities(auth + path); } if (Pattern.matches("^" + Pattern.quote(URL_PATH_SEPARATOR) //$NON-NLS-1$ + "[a-zA-Z][:|].*$", path)) { //$NON-NLS-1$ path = path.substring(URL_PATH_SEPARATOR.length()); } return new File(path); } } throw new IllegalArgumentException(Locale.getString("E2", theUrl)); //$NON-NLS-1$ }
java
{ "resource": "" }
q14858
FileSystem.getParentURL
train
@Pure @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) public static URL getParentURL(URL url) throws MalformedURLException { if (url == null) { return url; } String path = url.getPath(); final String prefix; final String parentStr; switch (URISchemeType.getSchemeType(url)) { case JAR: final int index = path.indexOf(JAR_URL_FILE_ROOT); assert index > 0; prefix = path.substring(0, index + 1); path = path.substring(index + 1); parentStr = URL_PATH_SEPARATOR; break; case FILE: prefix = null; parentStr = ".." + URL_PATH_SEPARATOR; //$NON-NLS-1$ break; //$CASES-OMITTED$ default: prefix = null; parentStr = URL_PATH_SEPARATOR; } if (path == null || "".equals(path)) { //$NON-NLS-1$ path = parentStr; } int index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR); if (index == -1) { path = parentStr; } else if (index == path.length() - 1) { index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR, index - 1); if (index == -1) { path = parentStr; } else { path = path.substring(0, index + 1); } } else { path = path.substring(0, index + 1); } if (prefix != null) { path = prefix + path; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path); }
java
{ "resource": "" }
q14859
FileSystem.extractLocalPath
train
@Pure @SuppressWarnings("checkstyle:magicnumber") private static String extractLocalPath(String filename) { if (filename == null) { return null; } final int max = Math.min(FILE_PREFIX.length, filename.length()); final int inner = max - 2; if (inner <= 0) { return filename; } boolean foundInner = false; boolean foundFull = false; for (int i = 0; i < max; ++i) { final char c = Character.toLowerCase(filename.charAt(i)); if (FILE_PREFIX[i] != c) { foundFull = false; foundInner = i >= inner; break; } foundFull = true; } String fn; if (foundFull) { fn = filename.substring(FILE_PREFIX.length); } else if (foundInner) { fn = filename.substring(inner); } else { fn = filename; } if (Pattern.matches("^(" + Pattern.quote(URL_PATH_SEPARATOR) + "|" //$NON-NLS-1$ //$NON-NLS-2$ + Pattern.quote(WINDOWS_SEPARATOR_STRING) + ")[a-zA-Z][:|].*$", fn)) { //$NON-NLS-1$ fn = fn.substring(1); } return fn; }
java
{ "resource": "" }
q14860
FileSystem.isWindowsNativeFilename
train
@Pure public static boolean isWindowsNativeFilename(String filename) { final String fn = extractLocalPath(filename); if (fn == null || fn.length() == 0) { return false; } final Pattern pattern = Pattern.compile(WINDOW_NATIVE_FILENAME_PATTERN); final Matcher matcher = pattern.matcher(fn); return matcher.matches(); }
java
{ "resource": "" }
q14861
FileSystem.normalizeWindowsNativeFilename
train
@Pure public static File normalizeWindowsNativeFilename(String filename) { final String fn = extractLocalPath(filename); if (fn != null && fn.length() > 0) { final Pattern pattern = Pattern.compile(WINDOW_NATIVE_FILENAME_PATTERN); final Matcher matcher = pattern.matcher(fn); if (matcher.find()) { return new File(fn.replace(WINDOWS_SEPARATOR_CHAR, File.separatorChar)); } } return null; }
java
{ "resource": "" }
q14862
FileSystem.makeCanonicalURL
train
@Pure public static URL makeCanonicalURL(URL url) { if (url != null) { final String[] pathComponents = url.getPath().split(Pattern.quote(URL_PATH_SEPARATOR)); final List<String> canonicalPath = new LinkedList<>(); for (final String component : pathComponents) { if (!CURRENT_DIRECTORY.equals(component)) { if (PARENT_DIRECTORY.equals(component)) { if (!canonicalPath.isEmpty()) { canonicalPath.remove(canonicalPath.size() - 1); } else { canonicalPath.add(component); } } else { canonicalPath.add(component); } } } final StringBuilder newPathBuffer = new StringBuilder(); boolean isFirst = true; for (final String component : canonicalPath) { if (!isFirst) { newPathBuffer.append(URL_PATH_SEPARATOR_CHAR); } else { isFirst = false; } newPathBuffer.append(component); } try { return new URI( url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), newPathBuffer.toString(), url.getQuery(), url.getRef()).toURL(); } catch (MalformedURLException | URISyntaxException exception) { // } try { return new URL( url.getProtocol(), url.getHost(), newPathBuffer.toString()); } catch (Throwable exception) { // } } return url; }
java
{ "resource": "" }
q14863
FileSystem.zipFile
train
public static void zipFile(File input, File output) throws IOException { try (FileOutputStream fos = new FileOutputStream(output)) { zipFile(input, fos); } }
java
{ "resource": "" }
q14864
FileSystem.zipFile
train
@SuppressWarnings("checkstyle:npathcomplexity") public static void zipFile(File input, OutputStream output) throws IOException { try (ZipOutputStream zos = new ZipOutputStream(output)) { if (input == null) { return; } final LinkedList<File> candidates = new LinkedList<>(); candidates.add(input); final byte[] buffer = new byte[BUFFER_SIZE]; int len; File file; File relativeFile; String zipFilename; final File rootDirectory = (input.isDirectory()) ? input : input.getParentFile(); while (!candidates.isEmpty()) { file = candidates.removeFirst(); assert file != null; if (file.getAbsoluteFile().equals(rootDirectory.getAbsoluteFile())) { relativeFile = null; } else { relativeFile = makeRelative(file, rootDirectory, false); } if (file.isDirectory()) { if (relativeFile != null) { zipFilename = fromFileStandardToURLStandard(relativeFile) + URL_PATH_SEPARATOR; final ZipEntry zipEntry = new ZipEntry(zipFilename); zos.putNextEntry(zipEntry); zos.closeEntry(); } candidates.addAll(Arrays.asList(file.listFiles())); } else if (relativeFile != null) { try (FileInputStream fis = new FileInputStream(file)) { zipFilename = fromFileStandardToURLStandard(relativeFile); final ZipEntry zipEntry = new ZipEntry(zipFilename); zos.putNextEntry(zipEntry); while ((len = fis.read(buffer)) > 0) { zos.write(buffer, 0, len); } zos.closeEntry(); } } } } }
java
{ "resource": "" }
q14865
FileSystem.unzipFile
train
public static void unzipFile(InputStream input, File output) throws IOException { if (output == null) { return; } output.mkdirs(); if (!output.isDirectory()) { throw new IOException(Locale.getString("E3", output)); //$NON-NLS-1$ } try (ZipInputStream zis = new ZipInputStream(input)) { final byte[] buffer = new byte[BUFFER_SIZE]; int len; ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { final String name = zipEntry.getName(); final File outFile = new File(output, name).getCanonicalFile(); if (zipEntry.isDirectory()) { outFile.mkdirs(); } else { outFile.getParentFile().mkdirs(); try (FileOutputStream fos = new FileOutputStream(outFile)) { while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } } } zipEntry = zis.getNextEntry(); } } }
java
{ "resource": "" }
q14866
FileSystem.unzipFile
train
public static void unzipFile(File input, File output) throws IOException { try (FileInputStream fis = new FileInputStream(input)) { unzipFile(fis, output); } }
java
{ "resource": "" }
q14867
KeyValueSinks.forPalDB
train
@Nonnull public static KeyValueSink<Symbol, byte[]> forPalDB(final File dbFile, final boolean compressValues) throws IOException { return PalDBKeyValueSink.forFile(dbFile, compressValues); }
java
{ "resource": "" }
q14868
RandomUtils.sampleHashingSetWithoutReplacement
train
public static <T> Set<T> sampleHashingSetWithoutReplacement(final Set<T> sourceSet, final int numSamples, final Random rng) { checkArgument(numSamples <= sourceSet.size()); // first we find the indices of the selected elements final List<Integer> selectedItems = distinctRandomIntsInRange(rng, 0, sourceSet.size(), numSamples); final Set<T> ret = Sets.newHashSet(); final Iterator<Integer> selectedItemsIterator = selectedItems.iterator(); if (numSamples > 0) { // now we walk through sourceSet in order to find the items at // the indices we selected. It doens't matter that the iteration // order over the set isn't guaranteed because the indices are // random anyway int nextSelectedIdx = selectedItemsIterator.next(); int idx = 0; for (final T item : sourceSet) { if (idx == nextSelectedIdx) { ret.add(item); if (selectedItemsIterator.hasNext()) { nextSelectedIdx = selectedItemsIterator.next(); } else { // we may (and probably will) run out of selected indices // before we run out of items in the set, unless the // last index is selected. break; } } ++idx; } } return ret; }
java
{ "resource": "" }
q14869
Transform1D.getPath
train
@Pure public List<S> getPath() { if (this.path == null) { return Collections.emptyList(); } return Collections.unmodifiableList(this.path); }
java
{ "resource": "" }
q14870
Transform1D.setPath
train
public void setPath(List<? extends S> path, Direction1D direction) { this.path = path == null || path.isEmpty() ? null : new ArrayList<>(path); this.firstSegmentDirection = detectFirstSegmentDirection(direction); }
java
{ "resource": "" }
q14871
Transform1D.setIdentity
train
public void setIdentity() { this.path = null; this.firstSegmentDirection = detectFirstSegmentDirection(null); this.curvilineTranslation = 0.; this.shiftTranslation = 0.; this.isIdentity = Boolean.TRUE; }
java
{ "resource": "" }
q14872
Transform1D.isIdentity
train
@Pure public boolean isIdentity() { if (this.isIdentity == null) { this.isIdentity = MathUtil.isEpsilonZero(this.curvilineTranslation) && MathUtil.isEpsilonZero(this.curvilineTranslation); } return this.isIdentity.booleanValue(); }
java
{ "resource": "" }
q14873
Transform1D.setTranslation
train
public void setTranslation(Tuple2D<?> position) { assert position != null : AssertMessages.notNullParameter(); this.curvilineTranslation = position.getX(); this.shiftTranslation = position.getY(); this.isIdentity = null; }
java
{ "resource": "" }
q14874
Transform1D.translate
train
public void translate(Tuple2D<?> move) { assert move != null : AssertMessages.notNullParameter(); this.curvilineTranslation += move.getX(); this.shiftTranslation += move.getY(); this.isIdentity = null; }
java
{ "resource": "" }
q14875
SGraphPoint.add
train
void add(Iterable<SGraphSegment> segments) { for (final SGraphSegment segment : segments) { this.segments.add(segment); } }
java
{ "resource": "" }
q14876
Configs.extractConfigs
train
public static List<ConfigMetadataNode> extractConfigs(ModulesMetadata modulesMetadata) { final List<ModuleMetadata> modules = modulesMetadata .getModules() .stream() .collect(Collectors.toList()); return modules.stream() .map(ModuleMetadata::getConfigs) .flatMap(Collection::stream) .sorted(Comparator.comparing(MetadataNode::getName)) .collect(Collectors.toList()); }
java
{ "resource": "" }
q14877
Configs.defineConfig
train
@SuppressWarnings("checkstyle:npathcomplexity") public static void defineConfig(Map<String, Object> content, ConfigMetadataNode config, Injector injector) { assert content != null; assert config != null; final Class<?> type = (Class<?>) config.getType(); final String sectionName = config.getName(); final Pattern setPattern = Pattern.compile("^set([A-Z])([a-zA-Z0-9]+)$"); //$NON-NLS-1$ Object theConfig = null; for (final Method setterMethod : type.getMethods()) { final Matcher matcher = setPattern.matcher(setterMethod.getName()); if (matcher.matches()) { final String firstLetter = matcher.group(1); final String rest = matcher.group(2); final String getterName = "get" + firstLetter + rest; //$NON-NLS-1$ Method getterMethod = null; try { getterMethod = type.getMethod(getterName); } catch (Throwable exception) { // } if (getterMethod != null && Modifier.isPublic(getterMethod.getModifiers()) && !Modifier.isAbstract(getterMethod.getModifiers()) && !Modifier.isStatic(getterMethod.getModifiers())) { try { if (theConfig == null) { theConfig = injector.getInstance(type); } if (theConfig != null) { final Object value = filterValue(getterMethod.getReturnType(), getterMethod.invoke(theConfig)); final String id = sectionName + "." + firstLetter.toLowerCase() + rest; //$NON-NLS-1$ defineScalar(content, id, value); } } catch (Throwable exception) { // } } } } }
java
{ "resource": "" }
q14878
Configs.defineScalar
train
public static void defineScalar(Map<String, Object> content, String bootiqueVariable, Object value) throws Exception { final String[] elements = bootiqueVariable.split("\\."); //$NON-NLS-1$ final Map<String, Object> entry = getScalarParent(content, elements); entry.put(elements[elements.length - 1], value); }
java
{ "resource": "" }
q14879
Permutation.createForNElements
train
public static Permutation createForNElements(final int numElements, final Random rng) { final int[] permutation = IntUtils.arange(numElements); IntUtils.shuffle(permutation, checkNotNull(rng)); return new Permutation(permutation); }
java
{ "resource": "" }
q14880
Permutation.permute
train
public void permute(final int[] arr) { checkArgument(arr.length == sources.length); final int[] tmp = new int[arr.length]; for (int i = 0; i < tmp.length; ++i) { tmp[i] = arr[sources[i]]; } System.arraycopy(tmp, 0, arr, 0, arr.length); }
java
{ "resource": "" }
q14881
PentaTreeNode.setChild1
train
private boolean setChild1(N newChild) { if (this.child1 == newChild) { return false; } if (this.child1 != null) { this.child1.setParentNodeReference(null, true); --this.notNullChildCount; firePropertyChildRemoved(0, this.child1); } if (newChild != null) { final N oldParent = newChild.getParentNode(); if (oldParent != this) { newChild.removeFromParent(); } } this.child1 = newChild; if (newChild != null) { newChild.setParentNodeReference(toN(), true); ++this.notNullChildCount; firePropertyChildAdded(0, newChild); } return true; }
java
{ "resource": "" }
q14882
PentaTreeNode.setChild2
train
private boolean setChild2(N newChild) { if (this.child2 == newChild) { return false; } if (this.child2 != null) { this.child2.setParentNodeReference(null, true); --this.notNullChildCount; firePropertyChildRemoved(1, this.child2); } if (newChild != null) { final N oldParent = newChild.getParentNode(); if (oldParent != this) { newChild.removeFromParent(); } } this.child2 = newChild; if (newChild != null) { newChild.setParentNodeReference(toN(), true); ++this.notNullChildCount; firePropertyChildAdded(1, newChild); } return true; }
java
{ "resource": "" }
q14883
PentaTreeNode.setChild3
train
private boolean setChild3(N newChild) { if (this.child3 == newChild) { return false; } if (this.child3 != null) { this.child3.setParentNodeReference(null, true); --this.notNullChildCount; firePropertyChildRemoved(2, this.child3); } if (newChild != null) { final N oldParent = newChild.getParentNode(); if (oldParent != this) { newChild.removeFromParent(); } } this.child3 = newChild; if (newChild != null) { newChild.setParentNodeReference(toN(), true); ++this.notNullChildCount; firePropertyChildAdded(2, newChild); } return true; }
java
{ "resource": "" }
q14884
PentaTreeNode.setChild4
train
private boolean setChild4(N newChild) { if (this.child4 == newChild) { return false; } if (this.child4 != null) { this.child4.setParentNodeReference(null, true); --this.notNullChildCount; firePropertyChildRemoved(3, this.child4); } if (newChild != null) { final N oldParent = newChild.getParentNode(); if (oldParent != this) { newChild.removeFromParent(); } } this.child4 = newChild; if (newChild != null) { newChild.setParentNodeReference(toN(), true); ++this.notNullChildCount; firePropertyChildAdded(3, newChild); } return true; }
java
{ "resource": "" }
q14885
Vector2i.convert
train
public static Vector2i convert(Tuple2D<?> tuple) { if (tuple instanceof Vector2i) { return (Vector2i) tuple; } return new Vector2i(tuple.getX(), tuple.getY()); }
java
{ "resource": "" }
q14886
ParameterAccessListener.constructLogMsg
train
String constructLogMsg() { final StringBuilder msg = new StringBuilder(); for (final Map.Entry<String, List<StackTraceElement>> e : paramToStackTrace.build().entries()) { msg.append("Parameter ").append(e.getKey()).append(" accessed at \n"); msg.append(FluentIterable.from(e.getValue()) // but exclude code in Parameters itself .filter(not(IS_THIS_CLASS)) .filter(not(IS_PARAMETERS_ITSELF)) .filter(not(IS_THREAD_CLASS)) .join(StringUtils.unixNewlineJoiner())); msg.append("\n\n"); } return msg.toString(); }
java
{ "resource": "" }
q14887
GraphicsDeviceExtensions.getAvailableScreens
train
public static GraphicsDevice[] getAvailableScreens() { final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment .getLocalGraphicsEnvironment(); final GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices(); return graphicsDevices; }
java
{ "resource": "" }
q14888
GraphicsDeviceExtensions.isScreenAvailableToShow
train
public static boolean isScreenAvailableToShow(final int screen) { final GraphicsDevice[] graphicsDevices = getAvailableScreens(); boolean screenAvailableToShow = false; if ((screen > -1 && screen < graphicsDevices.length) || (graphicsDevices.length > 0)) { screenAvailableToShow = true; } return screenAvailableToShow; }
java
{ "resource": "" }
q14889
ModuleUtils.classNameToModule
train
@Nonnull // it's reflection, can't avoid unchecked cast @SuppressWarnings("unchecked") public static Module classNameToModule(final Parameters parameters, final Class<?> clazz, Optional<? extends Class<? extends Annotation>> annotation) throws IllegalAccessException, InvocationTargetException, InstantiationException { if (Module.class.isAssignableFrom(clazz)) { return instantiateModule((Class<? extends Module>) clazz, parameters, annotation); } else { // to abbreviate the names of modules in param files, if a class name is provided which // is not a Module, we check if there is an inner-class named Module which is a Module for (final String fallbackInnerClassName : FALLBACK_INNER_CLASS_NAMES) { final String fullyQualifiedName = clazz.getName() + "$" + fallbackInnerClassName; final Class<? extends Module> innerModuleClazz; try { innerModuleClazz = (Class<? extends Module>) Class.forName(fullyQualifiedName); } catch (ClassNotFoundException cnfe) { // it's okay, we just try the next one continue; } if (Module.class.isAssignableFrom(innerModuleClazz)) { return instantiateModule(innerModuleClazz, parameters, annotation); } else { throw new RuntimeException(clazz.getName() + " is not a module; " + fullyQualifiedName + " exists but is not a module"); } } // if we got here, we didn't find any module throw new RuntimeException("Could not find inner class of " + clazz.getName() + " matching any of " + FALLBACK_INNER_CLASS_NAMES); } }
java
{ "resource": "" }
q14890
ModuleUtils.instantiateWithPrivateConstructor
train
private static Optional<Module> instantiateWithPrivateConstructor(Class<?> clazz, Class<?>[] parameters, Object... paramVals) throws InvocationTargetException, IllegalAccessException, InstantiationException { final Constructor<?> constructor; try { constructor = clazz.getDeclaredConstructor(parameters); } catch (NoSuchMethodException e) { return Optional.absent(); } final boolean oldAccessible = constructor.isAccessible(); constructor.setAccessible(true); try { return Optional.of((Module) constructor.newInstance(paramVals)); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw e; } finally { constructor.setAccessible(oldAccessible); } }
java
{ "resource": "" }
q14891
MapUtils.zipValues
train
public static <K, V> PairedMapValues<V> zipValues(final Map<K, V> left, final Map<K, V> right) { checkNotNull(left); checkNotNull(right); final ImmutableList.Builder<ZipPair<V, V>> pairedValues = ImmutableList.builder(); final ImmutableList.Builder<V> leftOnly = ImmutableList.builder(); final ImmutableList.Builder<V> rightOnly = ImmutableList.builder(); for (final Map.Entry<K, V> leftEntry : left.entrySet()) { final K key = leftEntry.getKey(); if (right.containsKey(key)) { pairedValues.add(ZipPair.from(leftEntry.getValue(), right.get(key))); } else { leftOnly.add(leftEntry.getValue()); } } for (final Map.Entry<K, V> rightEntry : right.entrySet()) { if (!left.containsKey(rightEntry.getKey())) { rightOnly.add(rightEntry.getValue()); } } return new PairedMapValues<V>(pairedValues.build(), leftOnly.build(), rightOnly.build()); }
java
{ "resource": "" }
q14892
MapUtils.indexMap
train
public static <T> ImmutableMap<T, Integer> indexMap(Iterable<? extends T> items) { final ImmutableMap.Builder<T, Integer> ret = ImmutableMap.builder(); int idx = 0; for (final T item : items) { ret.put(item, idx++); } return ret.build(); }
java
{ "resource": "" }
q14893
MapUtils.longestKeyLength
train
public static <V> int longestKeyLength(Map<String, V> map) { if (map.isEmpty()) { return 0; } return Ordering.natural().max( FluentIterable.from(map.keySet()) .transform(StringUtils.lengthFunction())); }
java
{ "resource": "" }
q14894
MapElementConstants.getPreferredRadius
train
@Pure public static double getPreferredRadius() { final Preferences prefs = Preferences.userNodeForPackage(MapElementConstants.class); if (prefs != null) { return prefs.getDouble("RADIUS", DEFAULT_RADIUS); //$NON-NLS-1$ } return DEFAULT_RADIUS; }
java
{ "resource": "" }
q14895
MapElementConstants.setPreferredRadius
train
public static void setPreferredRadius(double radius) { assert !Double.isNaN(radius); final Preferences prefs = Preferences.userNodeForPackage(MapElementConstants.class); if (prefs != null) { prefs.putDouble("RADIUS", radius); //$NON-NLS-1$ try { prefs.flush(); } catch (BackingStoreException exception) { // } } }
java
{ "resource": "" }
q14896
MapElementConstants.getPreferredColor
train
@Pure public static int getPreferredColor() { final Preferences prefs = Preferences.userNodeForPackage(MapElementConstants.class); if (prefs != null) { return prefs.getInt("COLOR", DEFAULT_COLOR); //$NON-NLS-1$ } return DEFAULT_COLOR; }
java
{ "resource": "" }
q14897
MapElementConstants.setPreferredColor
train
public static void setPreferredColor(int color) { final Preferences prefs = Preferences.userNodeForPackage(MapElementConstants.class); if (prefs != null) { prefs.putInt("COLOR", color); //$NON-NLS-1$ try { prefs.flush(); } catch (BackingStoreException exception) { // } } }
java
{ "resource": "" }
q14898
PhysicsUtil.setPhysicsEngine
train
public static PhysicsEngine setPhysicsEngine(PhysicsEngine newEngine) { final PhysicsEngine oldEngine = engine; if (newEngine == null) { engine = new JavaPhysicsEngine(); } else { engine = newEngine; } return oldEngine; }
java
{ "resource": "" }
q14899
PhysicsUtil.speed
train
@Pure @Inline(value = "PhysicsUtil.getPhysicsEngine().speed(($1), ($2))", imported = {PhysicsUtil.class}) public static double speed(double movement, double dt) { return engine.speed(movement, dt); }
java
{ "resource": "" }